Home-Is-Where-You-Hang-Your-Hack / sensor.goveetemp_bt_hci

Govee Temperature/Humidity BLE Home Assistant Component
MIT License
161 stars 29 forks source link

Trying to understand payload #20

Closed kgjamieson closed 4 years ago

kgjamieson commented 4 years ago

Thanks for developing this, just what I've been looking for.

I'm trying to understand how to access the data from the Govee H5074_4C97 from macOS or on a raspberry pi without the need to go through home assistant. So I'm trying to disentangle what is home assistant and what is extracting the temperature and humidity from this device.

If I just run bleson observer on MacOS in a minimal example printing out any advertisement that contains "govee" in the name, I get output like this:

Advertisement(flags=0x00, name='Govee_H5074_4C97', txpower=None, uuid16s=[], uuid128s=[], rssi=-64, mfg_data=b'L\x00\x02\x15INTELLI_ROCKS_HWPt\x97L\xc2')

Advertisement(flags=0x00, name='Govee_H5074_4C97', txpower=None, uuid16s=[], uuid128s=[], rssi=-60, mfg_data=b'\x88\xec\x00\x96\x08\x93\x15d\x02')

Because these messages never change, I'm assuming that the temperature and humidity info is not encoded in either of these mfg_data messages.

I've spent quite a bit of time trying to unpack sensor.py. From what I can gather, Observer is just a wrapper around adapter (though strangely, when I use the adapter I can find devices but if I don't use the wrapper and use the adapter directly it doesn't find any devices).

In any case, what I believe is passed to handle_meta_event() in sensor.py is just an Advertisement object which is being printed out above, which does not seem to indicate temperature info. So how are you extracting it? The data extraction scheme in govee_advertisement.py seems magical -- is there a datasheet that decodes this bytecode for these Govee devices?

Thanks for all your help!

Thrilleratplay commented 4 years ago

@kgjamieson The H5074 is finicky. It actually sends out 4 different broadcast, sometimes it takes a reboot before all are recognized on Raspberry PIs, not sure if this would work on a Mac.

I believe the second Advertisement contains the data you are looking for mfg_data=b'\x88\xec\x00\x96\x08\x93\x15d\x02, the relevant bytes are 96 08 93 15.

The first two octets contain the temperature, 96 08 and the second two contain the humidity, 93 15. The data returned is little endian, so the data the order is reversed. 08 96 and 15 93. This is converted from hex to decimal and divided by 100.

int("0896", 16)/100
21.98
int("1593", 16)/100
55.23

21.98 should be your temperature in Celsius and 55.23% should be humidity. The two's compliment of the temperature would need to be calculated before converting to an integer for temperatures that are close to freezing.