Add support for docker containers, mqtt prefix, environment variables for config, and pip requirements
This commit is contained in:
parent
9d55f12105
commit
a54c3b133e
10 changed files with 219 additions and 44 deletions
54
README.md
54
README.md
|
@ -2,11 +2,12 @@
|
|||
|
||||
Code to read weight measurements from [Mi Body Composition Scale](https://www.mi.com/global/mi-body-composition-scale/) (aka Xiaomi Mi Scale V2)
|
||||
|
||||

|
||||

|
||||
|
||||
Note: Framework is present to also read from Xiaomi Scale V1, although I do not own one to test so code has not been maintained
|
||||
|
||||
## Setup:
|
||||
## Getting the Mac Address of your Scale:
|
||||
|
||||
1. Retrieve the scale's MAC Address (you can identify your scale by looking for `MIBCS` entries) using this command:
|
||||
```
|
||||
$ sudo hcitool lescan
|
||||
|
@ -15,39 +16,52 @@ F8:04:33:AF:AB:A2 [TV] UE48JU6580
|
|||
C4:D3:8C:12:4C:57 MIBCS
|
||||
[...]
|
||||
```
|
||||
1. Copy all files
|
||||
1. Open `Xiaomi_Scale.py`
|
||||
1. Assign Scale's MAC address to variable `MISCALE_MAC`
|
||||
1. Edit MQTT Credentials
|
||||
1. Edit user logic/data on lines 117-131
|
||||
1. Note down your `MIBCS` mac address - we will need to use this as part of your configuration...
|
||||
|
||||
## How to use?
|
||||
- Must be executed with Python 3 else body measurements are incorrect.
|
||||
- Must be executed as root, therefore best to schedule via crontab every 5 min (so as not to drain the battery):
|
||||
## Setup & Configuration:
|
||||
### Running script with Docker:
|
||||
|
||||
1. Open `docker-compose.yml` and edit the environment to suit your configuration...
|
||||
1. Stand up the container - `docker-compose up -d`
|
||||
|
||||
### Running script directly on your host system:
|
||||
|
||||
1. Install python requirements (pip3 install -r requirements.txt)
|
||||
1. Open `wrapper.sh` and configure your environment variables to suit your setup.
|
||||
1. Add a cron-tab entry to wrapper like so:
|
||||
|
||||
```sh
|
||||
*/5 * * * * bash /path/to/wrapper.sh
|
||||
```
|
||||
|
||||
**NOTE**: It's best to schedule via crontab at most, every 5 min (so as not to drain the battery on your scale):
|
||||
```
|
||||
*/5 * * * * python3 /path-to-script/Xiaomi_Scale.py
|
||||
```
|
||||
|
||||
## Home-Assistant Setup:
|
||||
Under the `sensor` block, enter as many blocks as users setup on lines 117-131 in `Xiaomi_Scale.py`.
|
||||
```
|
||||
Under the `sensor` block, enter as many blocks as users configured in your environment variables:
|
||||
|
||||
```yaml
|
||||
- platform: mqtt
|
||||
name: "Lolo Weight"
|
||||
state_topic: "lolo/weight"
|
||||
name: "Example Name Weight"
|
||||
state_topic: "miScale/USERS_NAME/weight"
|
||||
value_template: "{{ value_json['Weight'] }}"
|
||||
unit_of_measurement: "kg"
|
||||
json_attributes_topic: "lolo/weight"
|
||||
json_attributes_topic: "miScale/USERS_NAME/weight"
|
||||
icon: mdi:scale-bathroom
|
||||
|
||||
- platform: mqtt
|
||||
name: "Lolo BMI"
|
||||
state_topic: "lolo/weight"
|
||||
name: "Example Name BMI"
|
||||
state_topic: "miScale/USERS_NAME/weight"
|
||||
value_template: "{{ value_json['BMI'] }}"
|
||||
icon: mdi:human-pregnant
|
||||
|
||||
```
|
||||

|
||||

|
||||
```
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
## Acknowledgements:
|
||||
Thanks to @syssi (https://gist.github.com/syssi/4108a54877406dc231d95514e538bde9) and @prototux (https://github.com/wiecosystem/Bluetooth) for their initial code
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue