tony-fav / tasmota-blerry

GNU General Public License v3.0
96 stars 29 forks source link

temperature with bthome driver doesn't work #87

Closed josch09 closed 2 months ago

josch09 commented 2 months ago

It's easy to fix. The issue is in line 66 of the blerry_driver_BTHome.be file. I tried to upload a patch file but it failed (I'm too lazy for forkining and creating a pull request for a one character fix) So here comes the fix directly (remove the '-' sign for the d_l in line 66) and then the temperature output in Celsius works fine.

0x02: {'d':'Temperature','u':'°C','d_l':2,'f':0.01},

Probably the other '-' signs in the lines after line 66 (e.g for dew_point) are also wrong/questionable.

tony-fav commented 2 months ago

Can you set the driver to the dev driver, collect some logs, and post? Thanks

josch09 commented 2 months ago

This is what I initially did to find out that the data which was sent by this 1€ - tuya device with alternative firmware is correct.

tasmota console output: 12:21:12.168 -- 38xxxxxxxx7D -- gf-br-th -- 12:21:12.169 Length: 0x02, Type: 0x01, Data: bytes('06') 12:21:12.180 Length: 0x11, Type: 0x16, Data: bytes('D2FC40008D016302120A0378190CB60B') 12:21:12.181 Length: 0x0C, Type: 0x09, Data: bytes('544842312D363633343744')

manually extracted (according BTHome V2): D2FC40008D016302120A0378190CB60B --> D2FC 40 008D 0163 02120A 037819 0CB60B 00 8D = packet id (1B) = 141 01 63 = battery (1B) = 99% 02 120A = temperature (2B = short int16) = 2578 = 25.78 C 03 7819 = humidity (2B = uint16) = 6520 = 65.20 % 0C B60B = voltage (2B = unit16) = 2998 = 2.998 V

I never programmed in berry but from what I see is that the 'd_l' means the data/payload length in bytes and the minus sign tries to correct the byte ordering.... And humidity (0x03) and Temperature (0x02) have the same byte ordering according to the BTHome V2 standard. So either the minus sign or the absence of the minus sign in line 66/67 had to be wrong... and so I gave it a try and removed the minus in line 66 and now it works.

In the meantime I also switched my XIAOMI TH sensors to use BTHomeV2 format instead of the custom ATCCpvvx format and driver and these are working too with this simple fix.

In combination with a esp32-c6 board and a self compiled bluetooth tasmota 14.1.0.3 it runs rock solid since last weekend

tony-fav commented 2 months ago

I have just pushed what I believe will fix this issue for you. (https://github.com/tony-fav/tasmota-blerry/commit/bada46cf91e172de387f396f4f9eb0ce3fd849c3)

The negative sign in d_l seems (I am not the original author of this driver) to indicate if the value is supposed to be signed or not (use the get versus geti method). But, the dp_len is use incorrectly in at least 1 spot.

Please give a try and report back so I can be sure of the fix.

josch09 commented 2 months ago

Can confirm that it works with both types of sensors using BTHomeV2 format

tony-fav commented 2 months ago

Great. So closed by https://github.com/tony-fav/tasmota-blerry/commit/bada46cf91e172de387f396f4f9eb0ce3fd849c3