Skip to content

Commit

Permalink
add config flow
Browse files Browse the repository at this point in the history
  • Loading branch information
edenhaus committed Apr 9, 2022
1 parent d5c03bf commit 53ef7ae
Show file tree
Hide file tree
Showing 19 changed files with 703 additions and 425 deletions.
19 changes: 9 additions & 10 deletions .devcontainer/configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@ input_number:
max: 3000
step: 1

bodymiscale:
test:
sensors:
weight: input_number.weight
impedance: input_number.impedance
height: 180
born: "1990-01-01"
gender: "male"
model_miscale: "181B"
template:
- sensor:
- name: Weight
state: "{{ states('input_number.weight') }}"
unit_of_measurement: "kg"
- name: Impedance
state: "{{ states('input_number.impedance') }}"
unit_of_measurement: "ohm"

# If you need to debug uncomment the line below (doc: https://www.home-assistant.io/integrations/debugpy/)
debugpy:
# wait: true
# wait: true
17 changes: 11 additions & 6 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// See https://aka.ms/vscode-remote/devcontainer.json for format details.
{
"image": "ludeeus/container:integration-debian",
"name": "Bodymiscale HA development",
"name": "Bodymiscale Development",
"image": "ghcr.io/ludeeus/devcontainer/integration:stable",
"postCreateCommand": "container install && pip install --ignore-installed -r requirements.txt",
"context": "..",
"appPort": ["9123:8123"],
"postCreateCommand": "container install",
"extensions": [
"ms-python.python",
"github.vscode-pull-request-github",
Expand All @@ -14,11 +13,17 @@
"settings": {
"files.eol": "\n",
"editor.tabSize": 4,
"terminal.integrated.shell.linux": "/bin/bash",
"python.pythonPath": "/usr/bin/python3",
"terminal.integrated.profiles.linux": {
"zsh": {
"path": "/usr/bin/zsh"
}
},
"terminal.integrated.defaultProfile.linux": "zsh",
"python.pythonPath": "/usr/local/python/bin/python",
"python.analysis.autoSearchPaths": false,
"python.linting.pylintEnabled": true,
"python.linting.enabled": true,
"python.linting.pylintArgs": ["--disable", "import-error"],
"python.formatting.provider": "black",
"editor.formatOnPaste": false,
"editor.formatOnSave": true,
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,5 @@ dmypy.json

# Pyre type checker
.pyre/

.idea
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ ci:

repos:
- repo: https://github.com/asottile/pyupgrade
rev: v2.31.0
rev: v2.32.0
hooks:
- id: pyupgrade
args: [--py39-plus]
- repo: https://github.com/psf/black
rev: 22.1.0
rev: 22.3.0
hooks:
- id: black
args:
Expand All @@ -28,7 +28,7 @@ repos:
<<: &python-files
files: ^(custom_components/.+)?[^/]+\.py$
- repo: https://github.com/PyCQA/bandit
rev: 1.7.2
rev: 1.7.4
hooks:
- id: bandit
args:
Expand All @@ -41,15 +41,15 @@ repos:
hooks:
- id: isort
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
rev: v4.2.0
hooks:
- id: check-executables-have-shebangs
- id: check-merge-conflict
- id: detect-private-key
- id: no-commit-to-branch
- id: requirements-txt-fixer
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.5.1
rev: v2.6.2
hooks:
- id: prettier
- repo: https://github.com/adrienverge/yamllint.git
Expand Down
96 changes: 14 additions & 82 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,13 @@

EN :

The purpose of this custom integration is to have additional information when weighing yourself with a Xiaomi Mi Scale (or any other smart scale). The input sensors for the custom integration are `weight` and optionally `impedance` (Mi Scale V2 only). You can use [ESPHome](https://esphome.io/) or [BLE monitor](https://github.com/custom-components/ble_monitor) to collect the required data via Bluetooth. The calculations are done in the `body_metrics.py` file. The configuration is in `bodymiscale.yaml` where you define `name`, `weight`, `height`, `age`, `gender` and `impedance` (only for Mi Scale V2). The name of the component should be bodymiscale.username.
The purpose of this custom integration is to have additional information when weighing yourself with a smart scale like Xiaomi Mi Scale.
For example you can use [ESPHome](https://esphome.io/) or [BLE monitor](https://github.com/custom-components/ble_monitor) to collect the required data via Bluetooth.

Information about the unit of measurement. All calculations are made using the unit of measurement KG. If your scale is set in lbs don't worry Bodymiscale will convert for you. If you want to display your data in lbs you can use the card here [lovelace-body-miscale-card](https://github.com/dckiller51/lovelace-body-miscale-card). Just click on Convert kg to lbs.

FR :

Le but de ce composant est d'avoir des informations supplémentaires lorsque l'on se pese avec une balance connectée Miscale Xiaomi. Actuellement le poids est envoyé sur Hassio avec un [ESPHome](https://esphome.io/) ou [BLE monitor](https://github.com/custom-components/ble_monitor). Le calculateur est le fichier `body_metrics.py`. La base de données est dans le fichier `bodymiscale.yaml` on y retrouve `name`, `le poids`, `la taille`, `l'age`, `le genre` et `l'impedance` (uniquement pour la Mi Scale V2). Le nom du composant devra être bodymiscale.username.

Information concernant l'unité de mesure. Tous les calcules sont réalisés à l'aide de l'unité de mesure en KG. Si votre balance est paramétré en lbs ne vous soucié pas Bodymiscale convertira pour vous. Si vous souhaitez afficher vos données en lbs vous pouvez utiliser la card ici [lovelace-body-miscale-card](https://github.com/dckiller51/lovelace-body-miscale-card). Il vous suffit de cliquer sur Convertir les kg en lbs.

DE :

Der Zweck dieser benutzerdefinierten Integration besteht darin, beim Wiegen mit einer Xiaomi Mi-Waage (oder einer anderen intelligenten Waage) zusätzliche Informationen zu erhalten. Die Sensoren für die benutzerdefinierte Integration sind "Gewicht" und optional "Impedanz" (nur Mi Scale V2). Sie können [ESPHome](https://esphome.io/) oder [BLE monitor](https://github.com/custom-components/ble_monitor) verwenden, um die erforderlichen Daten über Bluetooth zu erhalten. Die Berechnungen erfolgen in der Datei `body_metrics.py`. Die Konfiguration befindet sich in `bodymiscale.yaml` wo Sie `name`, `weight`, `height`, `age`, `gender` und `impedance` definieren (nur für Mi Scale V2). Der Name der Komponente sollte bodymiscale.username lauten.

Informationen zur Maßeinheit. Alle Berechnungen werden mit der Maßeinheit KG durchgeführt. Wenn Ihre Waage in lbs eingestellt ist, brauchen Sie sich keine Sorgen zu machen, Bodymiscale wird das für Sie umrechnen. Wenn Sie Ihre Daten in lbs anzeigen möchten, können Sie die Karte hier [lovelace-body-miscale-card](https://github.com/dckiller51/lovelace-body-miscale-card) verwenden. Klicken Sie einfach auf kg in lbs umwandeln.

The generated data is :

## For miscale (181D)

- Model Miscale
- Weight
- Height
- Years
Expand All @@ -38,27 +24,16 @@ The generated data is :
- Visceral fat
- Ideal weight
- Bmi label
- Lean body mass \*
- Body fat \*
- Water \*
- Bone mass \*
- Muscle mass \*
- Fat mass ideal \*
- Protein \*
- Body type \*

## For miscale 2 (181B) (with to impedance)

- Model Miscale
- Weight
- Height
- Years
- Gender
- Bmi
- Basal metabolism
- Visceral fat
- Ideal weight
- Bmi label
- Lean body mass
- Body fat
- Water
- Bone mass
- Muscle mass
- Fat mass ideal
- Protein
- Body type
\*: When also the impedance sensor is configured

---

Expand All @@ -79,53 +54,10 @@ The generated data is :

## Configuration

| key | type | description |
| :----------------------- | :--------------------------- | :------------------------------------------- |
| **plateform (Required)** | string | `bodymiscale` |
| **name (Required)** | string | Custom name for the sensor. `yourname` |
| **weight (Required)** | sensors / sensor.weight\_ | Your sensor returning your weight. |
| **impedance (Optional)** | sensors / sensor.impedance\_ | Your sensor returning your impedance. |
| **height (Required)** | number | Your height in cm. |
| **born (Required)** | string | Your birthday. `"YYYY-MM-DD"` |
| **gender (Required)** | string | female or male. `"male"` |
| **Model (Optional)** | string | Define the scale model.`"181D"` or `"181B"`. |

---

## Example

**Configuration YAML** [configuration.yaml]

```yaml
bodymiscale: !include components/bodymiscale.yaml
```
Create a file in `/config/components/bodymiscale.yaml`.

**Configuration with default settings:** [bodymiscale.yaml]

```yaml
yourname:
sensors:
weight: sensor.weight_aurelien
height: 176
born: "1990-04-10"
gender: "male"
model_miscale: "181D"
```

**Configuration with impedance (miscale2) settings:** [bodymiscale.yaml]
1. [![Open your Home Assistant instance and start setting up a new integration.](https://my.home-assistant.io/badges/config_flow_start.svg)](https://my.home-assistant.io/redirect/config_flow_start/?domain=bodyscale)
Click on the button above or go to your HA Configuration (Settings) -> Devices & Services -> Add -> Bodymiscale.

```yaml
yourname:
sensors:
weight: sensor.weight_aurelien
impedance: sensor.impedance_aurelien
height: 176
born: "1990-04-10"
gender: "male"
model_miscale: "181B"
```
2. Insert the required data and select your input sensor for `weight` and optional `impedance`.

---

Expand Down
Loading

0 comments on commit 53ef7ae

Please sign in to comment.