lolouk44 / xiaomi_mi_scale

Connector for Xiaomi Mi Scale
MIT License
325 stars 69 forks source link

Error When I get off the scale #49

Closed ibanmda closed 2 years ago

ibanmda commented 2 years ago
2022-01-03 23:32:55 - Starting Xiaomi mi Scale...
2022-01-03 23:32:55 - Loading Config From Add-On Options...
2022-01-03 23:32:55 - Config Loaded...
Traceback (most recent call last):
  File "/opt/miscale/Xiaomi_Scale.py", line 276, in <module>
    main()
  File "/opt/miscale/Xiaomi_Scale.py", line 242, in main
    discovery()
  File "/opt/miscale/Xiaomi_Scale.py", line 129, in discovery
    publish.single(
  File "/usr/local/lib/python3.8/site-packages/paho/mqtt/publish.py", line 227, in single
    multiple([msg], hostname, port, client_id, keepalive, will, auth, tls,
  File "/usr/local/lib/python3.8/site-packages/paho/mqtt/publish.py", line 163, in multiple
    client.connect(hostname, port, keepalive)
  File "/usr/local/lib/python3.8/site-packages/paho/mqtt/client.py", line 937, in connect
    return self.reconnect()
  File "/usr/local/lib/python3.8/site-packages/paho/mqtt/client.py", line 1071, in reconnect
    sock = self._create_socket_connection()
  File "/usr/local/lib/python3.8/site-packages/paho/mqtt/client.py", line 3522, in _create_socket_connection
    return socket.create_connection(addr, source_address=source, timeout=self._keepalive)
  File "/usr/local/lib/python3.8/socket.py", line 808, in create_connection
    raise err
  File "/usr/local/lib/python3.8/socket.py", line 796, in create_connection
    sock.connect(sa)
socket.timeout: timed out

Mi Body Composition Scale 2 XMTZC05HM HA core-2021.12.7 - Home Assistant OS 7.1 Raspberry Pi 3b

Why can it happen???

Thanks in advance!

lolouk44 commented 2 years ago

It looks like an issue connecting to mqtt. Check your config to ensure you have the correct mqtt details

ibanmda commented 2 years ago

Ok. I was wrong in ip address of MQTT server... But now only return this:

-------------------------------------
2022-01-03 23:53:00 - Starting Xiaomi mi Scale...
2022-01-03 23:53:00 - Loading Config From Add-On Options...
2022-01-03 23:53:00 - Config Loaded...
2022-01-03 23:53:00 - Discovery Completed...
2022-01-04 00:45:54 - Bluetooth connection error: Failed to execute management command 'scanend' (code: 13, error: Invalid Parameters)
2022-01-04 00:46:24 - Bluetooth connection error: Failed to execute management command 'scanend' (code: 13, error: Invalid Parameters)
2022-01-04 00:46:54 - Bluetooth connection error: Failed to execute management command 'scanend' (code: 13, error: Invalid Parameters)
2022-01-04 00:47:24 - Bluetooth connection error: Failed to execute management command 'scanend' (code: 13, error: Invalid Parameters)
2022-01-04 00:48:29 - Bluetooth connection error: Failed to execute management command 'scanend' (code: 13, error: Invalid Parameters)
2022-01-04 00:48:59 - Bluetooth connection error: Failed to execute management command 'scanend' (code: 13, error: Invalid Parameters)
2022-01-04 00:49:29 - Bluetooth connection error: Failed to execute management command 'scanend' (code: 13, error: Invalid Parameters)
sensor.iban_weightiban weight unknown
HCI_DEV: hci0
BLUEPY_PASSIVE_SCAN: true
MISCALE_MAC: XX:XX:XX:XX:XX:XX
MQTT_PREFIX: miscale
MQTT_HOST: 192.168.1.2
MQTT_USERNAME: user
MQTT_PASSWORD: password
MQTT_PORT: 1883
TIME_INTERVAL: 30
MQTT_DISCOVERY: true
MQTT_DISCOVERY_PREFIX: homeassistant
USERS:
  - NAME: iban
    SEX: male
    GT: 60
    LT: 80
    HEIGHT: 177
    DOB: '1980-01-01'
lolouk44 commented 2 years ago

Now you need to step on the scale to get a measurement

ibanmda commented 2 years ago

After I step on the scale:

-------------------------------------
2022-01-04 16:28:44 - Starting Xiaomi mi Scale...
2022-01-04 16:28:44 - Loading Config From Add-On Options...
2022-01-04 16:28:44 - Config Loaded...
2022-01-04 16:28:44 - Discovery Completed...

Results from Log Viewer (HA):


2022-01-04 16:28:44 INFO (MainThread) [homeassistant.components.mqtt.discovery] Component has already been discovered: sensor miscale iban, sending update
2022-01-04 16:28:44 INFO (MainThread) [homeassistant.components.mqtt.mixins] Got update for entity with hash: ('sensor', 'miscale iban') '{'name': 'iban Weight', 'state_topic': 'miscale/iban/weight', 'value_template': '{{ value_json.weight }}', 'json_attributes_topic': 'miscale/iban/weight', 'icon': 'mdi:scale-bathroom', 'platform': 'mqtt'}'
2022-01-04 16:28:44 INFO (MainThread) [homeassistant.components.mqtt.mixins] Ignoring unchanged update for: sensor.iban_weight_3

However, in developer tools (HA), all states from sensors are "unknow"


sensor.iban_weight iban weight | unknown | unit_of_measurement: kg icon: mdi:scale-bathroom friendly_name: iban weight
sensor.iban_weight_2 Iban Weight | unknown | icon: mdi:scale-bathroom friendly_name: Iban Weight
sensor.iban_weight_3 iban Weight | unknown | icon: mdi:scale-bathroom friendly_name: iban Weight

sensor.yaml

  - platform: mqtt
    name: "iban Weight"
    state_topic: "miscale/iban/weight"
    value_template: "{{ value_json['weight'] }}"
    unit_of_measurement: "kg"
    json_attributes_topic: "miscale/iban/weight"
    icon: mdi:scale-bathroom

  - platform: mqtt
    name: "iban BMI"
    state_topic: "miscale/iban/weight"
    value_template: "{{ value_json['bmi'] }}"
    icon: mdi:human-pregnant
    unit_of_measurement: "kg/m2"

I'm very lossed. Excuse me :|

lolouk44 commented 2 years ago

After I step on the scale:

-------------------------------------
2022-01-04 16:28:44 - Starting Xiaomi mi Scale...
2022-01-04 16:28:44 - Loading Config From Add-On Options...
2022-01-04 16:28:44 - Config Loaded...
2022-01-04 16:28:44 - Discovery Completed...

if this is all you see from the add-on logs, your scale is not communicating correctly. 1) do you have the Xiaomi App running on your phone? If so kill it, the scale can only communicate with 1 bluetooth device simultaneously 2) are you sure you have the correct MAC address for your scale in the settings? 3) are you sure your scale is close enough to the Raspberry Pi? 4) can you share your sensor templates?

ibanmda commented 2 years ago

if this is all you see from the add-on logs, your scale is not communicating correctly.

  1. do you have the Xiaomi App running on your phone? If so kill it, the scale can only communicate with 1 bluetooth device simultaneously

No. I don't have Xiaomi App in my smartphone. Never has been installed. Bluetooth OFF in my phone. Not Bluetooth devices near. Only a zigbee devices. Its a problem?

  1. are you sure you have the correct MAC address for your scale in the settings?
[bluetooth]# scan on
Discovery started
[NEW] Device 5X:XX:XX:XX:XX:X1 MIBFS

Confirmated. Same MAC address.

  1. are you sure your scale is close enough to the Raspberry Pi?

In this question i have to say it that is a bit far from Raspberry Pi (about ~6m), because this devices are in differents rooms. I did but it still doesn't work. Logs are similary to the previous messages

Maybe my mistake be the mqtt settings?

MQTT_HOST = 192.168.1.2 (Adress IP of (HA) Mosquitto broker?) My Hassio runs over Raspberry Pi 3b with ip 192.168.1.2

lolouk44 commented 2 years ago

ok that's odd...

[bluetooth]# scan on Discovery started [NEW] Device 5X:XX:XX:XX:XX:X1 MIBFS

If you get this then the scale is within range. Try and take the batteries out then back in again, wait for it to initialise and step on. Once your weight is registered on the scale, logs should show something like this:

2021-12-30 08:50:42 - Publishing data to topic miScale/Lolo/weight: {"weight":72.90,"weight_unit":"kg","bmi":23.80,"basal_metabolism":1453.24,"visceral_fat":13.04,"timestamp":"2021-12-30 08:50:42.140029"}
2021-12-30 08:50:42 - Data Published ...

Would show more if you stepped barefeet and your scale has biometic capabilities. this may take a few seconds depending on your settings. Can you try a tool like MQTT Explorer to confirm what get sent to the broker? can you share your sensor templates?

ibanmda commented 2 years ago

Finally it works! I taked out the batteries. Then I upgraded and rebooted the HA with succesfuly!

A lot of thanks for your help!