This commit is contained in:
lolouk44 2020-11-23 22:37:56 +00:00
parent 6890e0a497
commit 5112eccde3
7 changed files with 66 additions and 23 deletions

32
.github/workflows/main.yml vendored Normal file
View File

@ -0,0 +1,32 @@
name: Publish Docker image
on:
release:
types: [published]
jobs:
push_to_registry:
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v2
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build image
run: |
docker buildx build --no-cache --push \
--tag lolouk44/xiaomi-mi-scale-ha-add-on:${{ github.event.release.tag_name }} \
--tag lolouk44/xiaomi-mi-scale-ha-add-on:latest \
--platform linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8 .

View File

@ -1,3 +1,14 @@
## [0.1.11] - 2020-11-23
### Changed
- Remove additional logging for Scale V1 that was used for testing
- Changed timestamp to default python format (fixes https://github.com/lolouk44/xiaomi_mi_scale/issues/29)
- Removed hard-coded 'unit_f_measurement' in the MQTT Discovery (fixes https://github.com/lolouk44/hassio-addons/issues/22)
- Fixed hard coded MQTT Discovery Prefix (fixes https://github.com/lolouk44/xiaomi_mi_scale/issues/35)
- Change measures format to be numbers instead of string where applicable (https://github.com/lolouk44/xiaomi_mi_scale/pull/36)
### Added
- Created workflow to automatically build docker images on new releases (Thanks @AiiR42 for your help)
## [0.1.10] - 2020-09-09
### Changed
- Fixed issue with detection of boolean in MQTT_DISCOVERY (https://github.com/lolouk44/hassio-addons/issues/16 and https://github.com/lolouk44/xiaomi_mi_scale/issues/31)
@ -9,7 +20,6 @@
## [0.1.8] - 2020-09-08
### Breaking Changes
- Attributes are now snake_case (fixes https://github.com/lolouk44/xiaomi_mi_scale/issues/24)
### Changed
- Fixed default MQTT Prefix in config.json typo (fixes https://github.com/lolouk44/hassio-addons/issues/6)
- Fixed MQTT Discovery value check to discover
@ -19,23 +29,25 @@
- Fixed weight in Lbs not detected on Scale V1 (XMTZCO1HM) (fixes https://github.com/lolouk44/xiaomi_mi_scale/issues/28)
- Fixed body calculations for non kg weights
- Updated README
### Added
- Added unit to attributes
## [0.1.7] - 2020-07-06
### Added
- repository.json to make it a real add-on repo (fixes https://github.com/lolouk44/hassio-addons/issues/4)
## Modified
## Changed
- Now truly handles optional config entries(fixes https://github.com/lolouk44/hassio-addons/issues/3)
- MQTT Discovery set wtih retain flag (fixes https://github.com/lolouk44/hassio-addons/issues/2)
- README updated to use Xiaomi Mi Fit App to retrieve the MAC Address (fixes https://github.com/lolouk44/xiaomi_mi_scale/pull/25)
## [0.1.6] - 2020-07-01
### Added
- Docker Image so install is quicker (no local build required).
## [0.1.5] - 2020-07-01
### Added
- MQTT Discovery Support.
## [0.1.4] - 2020-06-29
### Added
- First release (version in line with non Add-On script for ease of maintenance).

View File

@ -1,5 +1,5 @@
FROM python:3.8-slim
LABEL io.hass.version="0.1.6" io.hass.type="addon" io.hass.arch="armhf|aarch64|i386|amd64"
LABEL io.hass.version="0.1.11" io.hass.type="addon" io.hass.arch="armhf|aarch64|i386|amd64"
WORKDIR /opt/miscale
COPY src /opt/miscale

View File

@ -107,4 +107,4 @@ Thanks to @syssi (https://gist.github.com/syssi/4108a54877406dc231d95514e538bde9
Special thanks to [@ned-kelly](https://github.com/ned-kelly) for his help turning a "simple" python script into a fully fledged docker container
Thanks to [@bpaulin](https://github.com/bpaulin) for his PRs and collaboration
Thanks to [@bpaulin](https://github.com/bpaulin), [@AiiR42](https://github.com/AiiR42) for their PRs and collaboration

View File

@ -1,10 +1,10 @@
{
"name": "Xiaomi Mi Scale",
"version": "0.1.10",
"version": "0.1.11",
"slug": "xiaomi_mi_scale",
"description": "Read weight measurements from Xiamomi scale via BLE",
"url": "https://github.com/lolouk44/xiaomi_mi_scale_ha_add_on",
"image": "lolouk44/xiaomi-mi-scale",
"image": "lolouk44/xiaomi-mi-scale-ha-add-on",
"arch": ["armhf", "armv7", "aarch64", "amd64", "i386"],
"startup": "before",
"boot": "auto",

View File

@ -193,7 +193,7 @@ OLD_MEASURE = ''
def discovery():
for MQTTUser in (USER1_NAME,USER2_NAME,USER3_NAME):
message = '{"name": "' + MQTTUser + ' Weight",'
message+= '"state_topic": "miscale/' + MQTTUser + '/weight","value_template": "{{ value_json.weight }}","unit_of_measurement": "kg",'
message+= '"state_topic": "' + MQTT_PREFIX + '/' + MQTTUser + '/weight","value_template": "{{ value_json.weight }}"'
message+= '"json_attributes_topic": "miscale/' + MQTTUser + '/weight","icon": "mdi:scale-bathroom"}'
publish.single(
MQTT_DISCOVERY_PREFIX + '/sensor/' + MQTT_PREFIX + '/' + MQTTUser + '/config',
@ -222,16 +222,14 @@ class ScanProcessor():
### Xiaomi V1 Scale ###
if data.startswith('1d18') and sdid == 22:
measunit = data[4:6]
sys.stdout.write(f"{datetime.now().strftime('%Y-%m-%d %H:%M:%S')} - Measuring Unit: {measunit}\n")
measured = int((data[8:10] + data[6:8]), 16) * 0.01
sys.stdout.write(f"{datetime.now().strftime('%Y-%m-%d %H:%M:%S')} - Measured Raw Weight: {measured}\n")
unit = ''
if measunit.startswith(('03', 'a3')): unit = 'lbs'
if measunit.startswith(('12', 'b2')): unit = 'jin'
if measunit.startswith(('22', 'a2')): unit = 'kg' ; measured = measured / 2
if unit:
if OLD_MEASURE != round(measured, 2):
self._publish(round(measured, 2), unit, str(datetime.today().strftime('%Y-%m-%d-%H:%M:%S')), "", "")
self._publish(round(measured, 2), unit, str(datetime.now()), "", "")
OLD_MEASURE = round(measured, 2)
### Xiaomi V2 Scale ###
@ -250,7 +248,7 @@ class ScanProcessor():
miimpedance = str(int((data[24:26] + data[22:24]), 16))
if unit and isStabilized:
if OLD_MEASURE != round(measured, 2) + int(miimpedance):
self._publish(round(measured, 2), unit, str(datetime.today().strftime('%Y-%m-%d-%H:%M:%S')), hasImpedance, miimpedance)
self._publish(round(measured, 2), unit, str(datetime.now()), hasImpedance, miimpedance)
OLD_MEASURE = round(measured, 2) + int(miimpedance)
@ -276,23 +274,23 @@ class ScanProcessor():
lib = Xiaomi_Scale_Body_Metrics.bodyMetrics(calcweight, height, age, sex, 0)
message = '{'
message += '"weight":"' + "{:.2f}".format(weight) + '"'
message += '"weight":' + "{:.2f}".format(weight)
message += ',"weight_unit":"' + str(unit) + '"'
message += ',"bmi":"' + "{:.2f}".format(lib.getBMI()) + '"'
message += ',"basal_metabolism":"' + "{:.2f}".format(lib.getBMR()) + '"'
message += ',"visceral_fat":"' + "{:.2f}".format(lib.getVisceralFat()) + '"'
message += ',"bmi":' + "{:.2f}".format(lib.getBMI())
message += ',"basal_metabolism":' + "{:.2f}".format(lib.getBMR())
message += ',"visceral_fat":' + "{:.2f}".format(lib.getVisceralFat())
if hasImpedance:
lib = Xiaomi_Scale_Body_Metrics.bodyMetrics(calcweight, height, age, sex, int(miimpedance))
bodyscale = ['Obese', 'Overweight', 'Thick-set', 'Lack-exerscise', 'Balanced', 'Balanced-muscular', 'Skinny', 'Balanced-skinny', 'Skinny-muscular']
message += ',"lean_body_mass":"' + "{:.2f}".format(lib.getLBMCoefficient()) + '"'
message += ',"body_fat":"' + "{:.2f}".format(lib.getFatPercentage()) + '"'
message += ',"water":"' + "{:.2f}".format(lib.getWaterPercentage()) + '"'
message += ',"bone_mass":"' + "{:.2f}".format(lib.getBoneMass()) + '"'
message += ',"muscle_mass":"' + "{:.2f}".format(lib.getMuscleMass()) + '"'
message += ',"protein":"' + "{:.2f}".format(lib.getProteinPercentage()) + '"'
message += ',"lean_body_mass":' + "{:.2f}".format(lib.getLBMCoefficient())
message += ',"body_fat":' + "{:.2f}".format(lib.getFatPercentage())
message += ',"water":' + "{:.2f}".format(lib.getWaterPercentage())
message += ',"bone_mass":' + "{:.2f}".format(lib.getBoneMass())
message += ',"muscle_mass":' + "{:.2f}".format(lib.getMuscleMass())
message += ',"protein":' + "{:.2f}".format(lib.getProteinPercentage())
message += ',"body_type":"' + str(bodyscale[lib.getBodyType()]) + '"'
message += ',"metabolic_age":"' + "{:.0f}".format(lib.getMetabolicAge()) + '"'
message += ',"metabolic_age":' + "{:.0f}".format(lib.getMetabolicAge())
message += ',"timestamp":"' + mitdatetime + '"'
message += '}'

View File

@ -1,5 +1,6 @@
#!/bin/bash
sleep 60 # Give the system time after a reboot to connect to WiFi before continuing
export MISCALE_MAC=00:00:00:00:00:00 # Mac address of your scale
export MQTT_PREFIX=miScale