Govee BLE Thermometer/Hygrometer sensor

@Thrilleratplay Thanks for your work on this component! It’s been working well for me with 2x H5072 and 2x H5074. I also have 2x Moat S2 temperature/humidity sensors (https://www.amazon.com/dp/B08DKMZDRR) since they are said to work well in freezers (while Govee discourages that).
So of course I wanted to add my Moat S2 sensors to Home Assistant as well. I was able to successfully augment your code to read the Moat S2 broadcasts in addition to the Govee sensors, and now I have all 6 sensors being tracked in Home Assistant.

So, I’m wondering if you’d be interested in having that additional functionality included in your integration (which might warrant a name change as it would now cover multiple brands) or if you’d prefer I just make my own separate component.

In either case, I have a few minor improvements that I’d be happy to contribute back to your github repo.

I forgot that the values stored are a averages over the time period. Too much time debugging live data. What I meant was, if the packets were corrupted/truncated and bleeding into each other that at that moment the refrigerator sensor would report the temperature of the another device while the other wouldn’t. Although, thinking about how intermittent it is, this would be incredibly difficult and mind numbing to do with little benefit.

…if any benefit…huh, ok I’m stumped. The humidity and temperature are collected from the same data packet; which is why rssi, last packet id and battery level are the same. Yet, the last mean of the freezer temp is 26 and the freezer humidity is 8 meaning many of the humidity values are likely out of range.

What do the graphs look like with both humidity and temperature for the freezer and refrigerator?

While I think this is great, I think it would be best as its own component. Even if the alterations were only to the broadcasted device name, support may become confusing for devices I do not own and references to a Moat app I cannot use. Additionally, the repo could not be renamed without possibly causing a number of headaches for current users and those who only have the Moat sensors may overlook a Govee brand component when trying to integrate their sensors.

Could you expand on ‘work well in freezers (while Govee discourages that)’ ? I have had a H5052 in both a refrigerator and freezer for six months with no problems. I have found the H5052’s to handle a temperature range of 0 to 125 degrees fahrenheit well. Thx for info.

Makes sense. I’ll work on cleaning up my relevant changes into friendly pull requests for you.
Thanks again!

From Amazon.com: Customer Questions & Answers
The seller, Govee US, said “We do not recommend to apply the sensors to the refrigerator or freezer. Low-temperature circumstance will shorten the battery life and affect the devices’ connecting. The suggested long-time working temperature of circumstance is: 14°F - 140°F/-10°C - 60°C.”

That discouraged me from purchasing the Govee H5074 for our freezers, since I keep them around -2°F. I went with the more expensive Moat S2, since that seller seemed much more confident of their performance in freezers (although they included the reduced battery life and connectivity disclaimers as well).

I do not have this device so I have no way maintain the component. I am sure others would appreciate the component but it makes more sense to leave under your own control and for you to maintain it.

The humidity for the Refrigerator sensor always jumps up to the 89-90% range (and once to 80%), but it’s much more steady than the temperature reading. The temp reading will bounce back and forth between mirroring multiple other Govee temp readings, but the humidity reading during that time will stay at slightly varying 89-90% readings until it temp readings return to its own normal readings. That is, the humidity doesn’t bounce around like the temp does, it just stays at the elevated readings until the temp ping-ponging stops.

I saw these warnings as well, but since the sensor is known on the device (and works in < 0F temps), I figured other than them having not extensively tested it (and thus not wanting to warrant its functioning), the main limitation would be the battery. That’s why I went with the H5074 for my freezers, as it uses a standard lithium coin cell which should function well below home freezer temperatures, with the caveat of some reduced battery life. My chest freezer Govee returns readings as low as -17F at times (but it usually closer to -7 to -10F).

I was also tempted to use one for my attic, but was concerned my attic might exceed the maximum temperature for the lithium cell, and a failure due to heat in the attic could be much more catastrophic, so I held off. The Moat seems to use the same lithium type of coin cells, so my guess is is that they’ve done more testing at a wider range of temperatures than Govee.

I haven’t used the H5072, but I have H5075s with alkaline batteries in my refrigerator.

Sorry if I was unclear. By “relevant changes”, I meant only some bug fixes that are applicable to the Govee sensors. All the Moat stuff will live in my own github repo.
Quick summary of the fixes: I noticed that (1) the component will completely stop updating HA if all samples in a period are discarded (due to being considered spikes) and that (2) high humidity can skew the temperature upward by 1 degree for the Govee cases where you need to modulus the humidity out of the combined temperature + humidity value.

Apologies if this is too off topic: I am also trying to get the basic H5074 sensor data, but using a minimal scanner on an ESP32 for now.

What I have learned about the packets these H5074 devices (vs the H5075’s w their LCD display) send may be useful to others here, so I hope posting is ok even if information refers more to the device itself rather than HA plugin by Thriller.

Using Arduino BLE code (library from Neil Kolban for ESP32) I am finding that the H5074s emit 3 types of BLE packets, with different lengths (namely, 40, 56, and 29)

The length 40 packets are the ones that contain temperature, humidity and battery level data.
The other two do not (details below)
The 29 packets seem to be emitted every second. After a long break from scanning, I appear to randomly get some 40 and 56 packets but following the first scan, only receiving 29 packets any more. This is frustrating since those don’t actually contain any data :slight_smile:
I tried this with active and passive scanning, and with various scan periods, windows etc.

Just passive scanning and listening to length 40 packets containing sensor data does not appear to be working for H5074 devices:
After a long time of not scanning (eg ESP32 turned off) I might get a couple of data packets with actual temp but after that I only ever get length 29 “keepalive” type packets that do not contain temp data.

There seems to be something stateful to the scanning, ie. my scans influence what the H5074 emits subsequently, at least for a period of time.

Questions:

  • is anyone else seeing this “only length 29, not data containing packets” subsequent to initial scan behavior ? Or is everyone able to periodically (what period ?) fish out length 40 data containing packets out of the air ?

  • does the H5074 require active scanning (connecting to H5074 explicitly, asking for temp data) ?

More details on the packet types emitted by the H5074 device

------------------------------------------------------------------
Length 40 packet
all     : Name: Govee_H5074_C0A6, 
          Address: e3:8e:c8:c1:c0:a6, 
          manufacturer data: 88ec002f0941176402, 
          serviceUUID: 0000180a-0000-1000-8000-00805f9b34fb

raw data (for each data item: byte 1=len, byte 2=type, byte 3+=value)
02 01 06
07 03 0A 18 F5 FE 88 EC
11 09 47 6F 76 65 65 5F 48 35 30 37 34 5F 43 30 41 36
0A FF 88 EC 00 2F 09 41 17 64 02

Decoded data
length[ 1] type[  1 = flags] 06    .
length[ 6] type[  3 = BLEUUIDs of services available] 0A 18 F5 FE 88 EC    ......
length[16] type[  9 = full device name] 47 6F 76 65 65 5F 48 35 30 37 34 5F 43 30 41 36    Govee_H5074_C0A6
length[ 9] type[255 = mfg specific data] 88 EC 00 2F 09 41 17 64 02    .../.A.d.

Interpretation
BLEUUIDs of services available:
0x180A  device information
0xFEF5 ??
0xEC88 sensor readings (temp, humidity, battery) eg this packet

mfg specific data item:
0xEC88 = tmp/humidity/battery data follows
0x092F  = temperature = 2351 decimal / 100 ➟ 23.51 degrees C
0x1741  = humidity = 5953 decimal / 100 ➟ 59.53 % relative humidity
0x64      = battery level = 100 decimal ➟ 100% battery level

------------------------------------------------------------------
Length 56 packets

all     :  Name: Govee_H5074_C0A6
           Address: e3:8e:c8:c1:c0:a6
           manufacturer data: 4c000215494e54454c4c495f524f434b535f48575074a6c0c2
           serviceUUID: 0000180a-0000-1000-8000-00805f9b34fb
decoded data:
length[ 1] type[  1=flags] 06    .
length[ 6] type[  3=services] 0A 18 F5 FE 88 EC    ......
length[16] type[  9=device name] 47 6F 76 65 65 5F 48 35 30 37 34 5F 43 30 41 36    Govee_H5074_C0A6
length[25] type[255=mfg specific data] 4C 00 02 15 49 4E 54 45 4C 4C 49 5F 52 4F 43 4B 53 5F 48 57 50 74 A6 C0 C2    L...INTELLI_ROCKS_HWPt...

Interpretation
0x004C type of Govee data packet, mfg data follows ?
0x0215 ???
0x4E...50 INTELLI_ROCKS_HWP Intelli_rocks is the name of the mfg of the Govee devices. This data seems constant
0x74 ?
0xC0A6 last 4 of device name Govee_H5074_C0A6
0xC2 ???

This packet type doesn't appear to have enough bytes for device specific data for all hw, firmware versions, serial etc.

------------------------------------------------------------------
Length 29 packets

all     : Name: Govee_H5074_C0A6
          Address: e3:8e:c8:c1:c0:a6
          serviceUUID: 0000180a-0000-1000-8000-00805f9b34fb
length[ 1] type[  1] 06    .
length[ 6] type[  3] 0A 18 F5 FE 88 EC    ......
length[16] type[  9] 47 6F 76 65 65 5F 48 35 30 37 34 5F 43 30 41 36    Govee_H5074_C0A6

Interpretation
same flag value (6) and BLEUUIDs for services and device name
Just a "heartbeat" to signal the device is online ? Once per second seems very frequent for a low power device. Perhaps triggered by scanning

---------------------------------
1 Like

@haToad
I have been working on an ESPHome solution for ble scanning for the Govee H5074 temperature/humidity sensors and just finished getting it working. With ESPHome if was fairly straight forward with the biggest issues being reverse engineering the great Python package that was written to use the bluetooth on a HASSIO RPi to use the new ESPHome BLE functions. Once I figured out the data stream for the H5074 and got rid of the cobwebs on c and c++ (lamda functions for ESPHome are in c++) I got it to work. If you are familiar with ESPHome the code below will make sense. This is not a generic Govee solution as it only works for the H5074 but it has been working for me for about 2 days with no issues yet. Hopefully this helps. Eventually I may take the plunge and learn how to turn this into a Govee platform and bring in the other device types rather than the lamda functions. But for now, it works and I have the humidity values back after loosing them when I moved off of my RPi4 to a more powerful machine to run Hassio on. (the data size = 7 corresponds to what is in the manufacture data field for the length 40 data packets)

sensor:
#  - platform: wifi_signal
#    name: "WiFi Signal Strength"
#    update_interval: 60s
  
  - platform: template
    name: "Guest Bathroom Humidity"
    id: guest_bathroom_humidity
    unit_of_measurement: '%'
    icon: "mdi:water-percent"
  - platform: template
    name: "Master Bathroom Humidity"
    id: master_bathroom_humidity
    unit_of_measurement: '%'
    icon: "mdi:water-percent"
  - platform: template
    name: "Master Bathroom Temperature"
    id: master_bathroom_temperature
    unit_of_measurement: 'F'
    icon: "mdi:thermometer"
  - platform: template
    name: "Master Bathroom RSSI"
    id: master_bathroom_rssi
    unit_of_measurement: 'dB'
    icon: "mdi:wifi"
  - platform: template
    name: "Master Bathroom Battery"
    id: master_bathroom_battery
    unit_of_measurement: '%'
    icon: "mdi:battery"

esp32_ble_tracker:
  on_ble_advertise:
    - mac_address: XX:XX:XX:XX:XX:XX
      then:
        - lambda: |-
            for (auto data : x.get_manufacturer_datas()) {
                if(data.data.size()==7) {
                  uint16_t hum_lsb = data.data[3] + (data.data[4] << 8);
                  float humidity= float(hum_lsb)/100.0;
                  int16_t temp_lsb = data.data[1] + (data.data[2] << 8);
                  float temperature = float(temp_lsb)/100*9.0/5.0 + 32.0;
                  int16_t battery=data.data[5];
                  int16_t rssi=x.get_rssi();
                  id(master_bathroom_humidity).publish_state(humidity);
                  id(master_bathroom_temperature).publish_state(temperature);
                  id(master_bathroom_rssi).publish_state(rssi);
                  id(master_bathroom_battery).publish_state(battery);

                }
            }


3 Likes

This is interesting. Using the bleson library (only passive scanning as far as I can tell Edit: I’m wrong; corrected by @Thrilleratplay below), I see my Govee_H5074_04C8 broadcasting LE_ADVERTISING_REPORT packets of lengths 11, 27, and 29 (not counting the 10 byte header of 01 00 00 <6-byte address> <1-byte length> or 1-byte RSSI footer).
For me, the sensor measurement data is only in the 11 byte packets, of which I receive one roughly every 2 seconds. But just like yours, the measurement data is in a GAP_MFG_DATA of data length 9. For example:
88 ec 00 02 03 f2 0f 64 02

From the official Govee iOS app, I see that my H5074 Firmware version is 1.01.00. What version is yours?

Hmm, just realized,
11 (me only) + 29 (both of us) = 40 (you only)
and
27 (me only) + 29 (both of) = 56 (you only).
So I suspect ESP32 is queuing/combining the advertisements. I wonder if something is going wrong there.

Bleson does active scanning, at least it does for Linux.

1 Like

OK – I’ve made some significant progress. Got a bluetooth dongle, passed it through to the VM Machine, found the MAC address, and updated configuration to yaml.

I think where i’m getting hung up is covered in the repository documentation: Namely here:

If running Home Assistant without root access the Bleson Python library used for accessing bluetooth requires the following permissions applied to the Python 3 binary. If using a virtual environment for HA, this binary will be in the virtual environment path.

NOTE : Replace “path” with the path to the Python3 binary (example: /srv/homeassistant/bin/python3)

sudo setcap cap_net_raw,cap_net_admin+eip $(eval readlink -f path)

I’ve ran this linux command on where i thought this library was in /usr/bin/Python3.8 (and also Python3). I’m thinking this is not the right place given these logs. I’m running Ubuntu in a VM – anyone know where i can find the right place to run this?

Logger: homeassistant.components.sensor
Source: custom_components/govee_ble_hci/sensor.py:202
Integration: Sensor ([documentation](https://www.home-assistant.io/integrations/sensor), [issues](https://github.com/home-assistant/home-assistant/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+sensor%22))
First occurred: 12:01:02 PM (1 occurrences)
Last logged: 12:01:02 PM

Error while setting up govee_ble_hci platform for sensor

Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 184, in _async_setup_platform await asyncio.shield(task) File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run result = self.fn(*self.args, **self.kwargs) File "/config/custom_components/govee_ble_hci/sensor.py", line 202, in setup_platform adapter = get_provider().get_adapter(int(config[CONF_HCI_DEVICE][-1])) File "/usr/local/lib/python3.8/site-packages/bleson/providers/linux/linux_provider.py", line 11, in get_adapter adapter.off() File "/usr/local/lib/python3.8/site-packages/bleson/providers/linux/linux_adapter.py", line 100, in off self.send_cmd_value(HCIDEVDOWN, self.device_id) File "/usr/local/lib/python3.8/site-packages/bleson/providers/linux/linux_adapter.py", line 47, in send_cmd_value fcntl.ioctl(self._socket.fileno(), cmd, value) PermissionError: [Errno 1] Operation not permitted

If you have a bluetooth dongle and a VM, is the dongle correctly passed through to the Ubuntu guest system? Also, if there is another Bluetooth device, are you setting the correct hci device number? Both are probably easiest to determine by running the command hcitool in a terminal.

I had issues at first with getting temp data from the H5074. Like you, it seemed to only send out temp data containing packets occasionally, and be influenced by whether I had the Govee app open or not.

At first my attempts at active scanning (with hcitool) seemed to have no impact, but after rebooting my Ubuntu host and using active scanning again, the temp packets started showing up reliably.

In this case active just refers to the hcitool(hciscan?) flag, not specifically probing the H5074. It seems like the H5074 only emits the temp packets when some device is scanning with the active flag enabled.

1 Like

I have disabled the native bluetooth on my host device (a mac mini) – but honestly it wasn’t passing through Bluetooth at all; it wasn’t until i got the dongle and passed it through to the VM that a controller was even available (and there is only one).

Any idea how to find where the python3.8 binary is installed in ubuntu so i can try and run that permissions script from the repository?

whereis python

Running hciconfig in the VM only list one device, hci0, and has PSCAN?

not sure about PSCAN… heres what hciconfig says:

|hci0:|Type: Primary  Bus: USB|
|---|---|
||BD Address: 00:1A:7D:DA:71:13  ACL MTU: 310:10  SCO MTU: 64:8|
||UP RUNNING |
||RX bytes:1220 acl:0 sco:0 events:72 errors:0|
||TX bytes:2788 acl:0 sco:0 commands:72 errors:0|