lolouk44 / hassio-addons

Xiaomi Mi Scale Add On for Home Assistant
MIT License
126 stars 42 forks source link

0.3.2 crashes with V1 scale #64

Closed jgalerap closed 1 year ago

jgalerap commented 1 year ago

Select Add-On (place a lowercase x for the relevant add-on)

Describe the bug Addon crashes with an exception.

2022-10-03 14:01:51 - Starting Xiaomi mi Scale...
2022-10-03 14:01:51 - Loading Config From Add-On Options...
2022-10-03 14:01:51 - Config Loaded...
2022-10-03 14:01:51 - Initialization Completed, Waiting for Scale...
ERROR:root:A message handler raised an exception: '0000181b-0000-1000-8000-00805f9b34fb'.
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/dbus_fast/message_bus.py", line 745, in _process_message
result = handler(msg)
File "/usr/local/lib/python3.9/site-packages/bleak/backends/bluezdbus/manager.py", line 798, in _parse_msg
self._run_advertisement_callbacks(
File "/usr/local/lib/python3.9/site-packages/bleak/backends/bluezdbus/manager.py", line 843, in _run_advertisement_callbacks
callback(device_path, device.copy())
File "/usr/local/lib/python3.9/site-packages/bleak/backends/bluezdbus/scanner.py", line 260, in _handle_advertising_data
self._callback(device, advertisement_data)
File "/opt/miscale/Xiaomi_Scale.py", line 284, in callback
data = binascii.b2a_hex(advertising_data.service_data['0000181b-0000-1000-8000-00805f9b34fb']).decode('ascii')
KeyError: '0000181b-0000-1000-8000-00805f9b34fb'
ERROR:root:A message handler raised an exception: '0000181b-0000-1000-8000-00805f9b34fb'.

To Reproduce Configuration used (passwords and mac masked):

HCI_DEV: hci0
BLUEPY_PASSIVE_SCAN: false
MISCALE_MAC: 00:00:00:00:00:00
MISCALE_VERSION: 1
MQTT_PREFIX: miScale
MQTT_HOST: 192.168.0.1
MQTT_USERNAME: ****
MQTT_PASSWORD: "****"
MQTT_PORT: 1883
MQTT_RETAIN: true
MQTT_DISCOVERY: true
MQTT_DISCOVERY_PREFIX: homeassistant
MQTT_TLS_CACERTS: Path to CA Cert File
MQTT_TLS_INSECURE: false
TIME_INTERVAL: 30
USERS:

NAME: ***
SEX: male
GT: 75
LT: 100
HEIGHT: 191
DOB: "1985-01-01"
NAME: ****
SEX: female
GT: 40
LT: 75
HEIGHT: 168
DOB: "1986-01-01"

Expected behaviour Please support V1 scales

Scale (please complete the following information):

Device running Home Assistant (please complete the following information):

Additional context Add any other context about the problem here.

lolouk44 commented 1 year ago

Thanks for this. I'll create a beta version with more logging for you. Bear with me pls.

jgalerap commented 1 year ago

Maybe this helps. I downloaded Bluetooth device diagnostics data from HA and filtered by scale mac address.

        {
          "name": "MI_SCALE",
          "address": "88:0F:10:00:00:00",
          "rssi": -66,
          "manufacturer_data": {
            "343": {
              "__type": "<class 'bytes'>",
              "repr": "b'\\x88\\x0f\\x10\\xaay\\x0e'"
            }
          },
          "service_data": {
            "0000181d-0000-1000-8000-00805f9b34fb": {
              "__type": "<class 'bytes'>",
              "repr": "b'\\xa2DC\\xe6\\x07\\x02\\x1b\\x0f\\x19('"
            }
          },
          "service_uuids": [
            "0000181d-0000-1000-8000-00805f9b34fb"
          ],
          "source": "hci0",
          "device": {
            "__type": "<class 'bleak.backends.device.BLEDevice'>",
            "repr": "88:0F:10:00:00:00: MI_SCALE"
          },
          "advertisement": {
            "__type": "<class 'bleak.backends.scanner.AdvertisementData'>",
            "repr": "AdvertisementData(local_name='MI_SCALE', manufacturer_data={343: b'\\x88\\x0f\\x10\\xaay\\x0e'}, service_data={'0000181d-0000-1000-8000-00805f9b34fb': b'\\xa2DC\\xe6\\x07\\x02\\x1b\\x0f\\x19('}, service_uuids=['0000181d-0000-1000-8000-00805f9b34fb'])"
          },
          "connectable": true,
          "time": 708603.039902744
        }
lolouk44 commented 1 year ago

That's ecactly what I needed 😄 Can you confirm the weight that we measured when you got this data?

jgalerap commented 1 year ago

86.1Kg. I think

jgalerap commented 1 year ago

86.4 Kg right now. And I extracted the data again.

{
          "name": "MI_SCALE",
          "address": "88:0F:10:00:0:00",
          "rssi": -74,
          "manufacturer_data": {
            "343": {
              "__type": "<class 'bytes'>",
              "repr": "b'\\x88\\x0f\\x10\\xaay\\x0e'"
            }
          },
          "service_data": {
            "0000181d-0000-1000-8000-00805f9b34fb": {
              "__type": "<class 'bytes'>",
              "repr": "b'\\xa2\\x80C\\xe6\\x07\\x02\\x1b\\x0f\\x1b '"
            }
          },
          "service_uuids": [
            "0000181d-0000-1000-8000-00805f9b34fb"
          ],
          "source": "hci0",
          "device": {
            "__type": "<class 'bleak.backends.device.BLEDevice'>",
            "repr": "88:0F:10:00:00:00: MI_SCALE"
          },
          "advertisement": {
            "__type": "<class 'bleak.backends.scanner.AdvertisementData'>",
            "repr": "AdvertisementData(local_name='MI_SCALE', manufacturer_data={343: b'\\x88\\x0f\\x10\\xaay\\x0e'}, service_data={'0000181d-0000-1000-8000-00805f9b34fb': b'\\xa2\\x80C\\xe6\\x07\\x02\\x1b\\x0f\\x1b '}, service_uuids=['0000181d-0000-1000-8000-00805f9b34fb'])"
          },
          "connectable": true,
          "time": 713520.549064826
        }
lolouk44 commented 1 year ago

0.3.3 published and being built. Should be ready in ~10-15 min

jgalerap commented 1 year ago

It works!

thanks @lolouk44 crack.

magiva commented 1 year ago

Maybe this helps. I downloaded Bluetooth device diagnostics data from HA and filtered by scale mac address.

        {
          "name": "MI_SCALE",
          "address": "88:0F:10:00:00:00",
          "rssi": -66,
          "manufacturer_data": {
            "343": {
              "__type": "<class 'bytes'>",
              "repr": "b'\\x88\\x0f\\x10\\xaay\\x0e'"
            }
          },
          "service_data": {
            "0000181d-0000-1000-8000-00805f9b34fb": {
              "__type": "<class 'bytes'>",
              "repr": "b'\\xa2DC\\xe6\\x07\\x02\\x1b\\x0f\\x19('"
            }
          },
          "service_uuids": [
            "0000181d-0000-1000-8000-00805f9b34fb"
          ],
          "source": "hci0",
          "device": {
            "__type": "<class 'bleak.backends.device.BLEDevice'>",
            "repr": "88:0F:10:00:00:00: MI_SCALE"
          },
          "advertisement": {
            "__type": "<class 'bleak.backends.scanner.AdvertisementData'>",
            "repr": "AdvertisementData(local_name='MI_SCALE', manufacturer_data={343: b'\\x88\\x0f\\x10\\xaay\\x0e'}, service_data={'0000181d-0000-1000-8000-00805f9b34fb': b'\\xa2DC\\xe6\\x07\\x02\\x1b\\x0f\\x19('}, service_uuids=['0000181d-0000-1000-8000-00805f9b34fb'])"
          },
          "connectable": true,
          "time": 708603.039902744
        }

@jgalerap can you show how you obtained this data as the scale addin doesnt work at all for me since the updates i would like to get this data before i log an issue

lolouk44 commented 1 year ago

@magiva 0.3.3 should fix your issues. Make sure you update.

magiva commented 1 year ago

yeah it is updated but never gets posts anything after " Initialization Completed, Waiting for Scale..." i need to debug but need to start from somewhere, currently i dont know where to start. it was working before the bluetooth switch (rpi docker)

jgalerap commented 1 year ago

In Home Assistant, go to Settings > Devices & Services > Select Bluetooth Integration device image

Then under Device Info click on "DOWNLOAD DIAGNOSTICS" image

A json file will be downloaded, open it with a Text Editor and search for the MAC address of you Mi Scale.

lolouk44 commented 1 year ago

You mention docker, did you ensure you have the dbus mounted in your docker run command or docker-compose? https://github.com/lolouk44/hassio-addons/blob/master/mi-scale/DOCS.md#important

magiva commented 1 year ago

config_entry-bluetooth-03daf732d8cb5cbce18de09ee7a787ba.json.txt Home assistant is installed as a supervised type which is why i say its dockered. I can putty into the host (pi) but i wouldnt know how to add the dbus share to the boot of the docker (?)

magiva commented 1 year ago

i think as you say, the issue is that bluetooth in home assistant is not working since they changed it. once im home i can try checking some things, i dont think this is related to the scale addon until i get bluetooth working in HA