flavio20002 / mitemp_bt

Home Assistant Sensor for the Mijia Temperature Sensor
MIT License
27 stars 5 forks source link

Issue with Temperature value less than 10degC #2

Closed randomdisco closed 5 years ago

randomdisco commented 6 years ago

Hi, It appears as if the sensor platform code stops returning values if the temperature is below 10degC. This possibly also affects humidity but I can't verify this.

I'm running Hass.io on a RPI 3 with several of these sensors. The ones above 10degC continue to work normally; only one is dropping below 10deg C and when it does temperature, humidity, and battery values for only this sensor freeze and don't update until temp goes back above 10degC.

Suspect there is a single digit temperature (and humidity) bug in the code? I've never debugged python code before but I'm happy to try and look tonight.

I've had a quick look at the code and this might be the issue:

    # Parse the output
    res = re.search("( [0-9a-fA-F][0-9a-fA-F])+", result)

which is in def write_readnotif_ble(mac, handle, value, retries=3, timeout=20, adapter=‘hci0’): and def read_ble(mac, handle, retries=3, timeout=20, adapter=‘hci0’):

Appears as if it needs to have 2 characters for a result to be found… But if the display is returning a 0 in front this should work. Wondering if the parse of the handle from the sensor (in format 0xXX) is only returning 1 (e.g. 8.3) rather than 2 (e.g. 08.3) characters for the non-decimal part…

Some comments are here with 2 other users with the same issue: https://community.home-assistant.io/t/xiaomi-mijia-bluetooth-temperature-humidity-sensor-compatibility/43568/36

Great work on the sensor code - it was a breeze to get the sensors configured and running. Happy to help with this bug if I can!

Cheers, Stewart

randomdisco commented 6 years ago

I was actually looking at the wrong code, so apologies. I still think there is a bug with the line I mentioned though. If you're still developing this I think this might be better:

data=bytearray.fromhex(result).decode()
temp,humid  = data.replace("T=", "").replace("H=", "").rstrip(' \t\r\n\0').split(" ")
flavio20002 commented 6 years ago

You are right. I will fix it. Thanks.

Flavio

taulen commented 6 years ago

This issue is still there right ? Not working for me.

flavio20002 commented 5 years ago

Fixed with 189f5e00a0033fcfc2ad3e31bb7f1e258a6a1c9f