Govee BLE Thermometer/Hygrometer sensor

@Litrecola Yes, I did. Here’s the modified python script. I’m using bluepy directly.

My setup is a raspberry pi reading the govee bluetooth advertisements, and then publishing it out via ethernet over MQTT to InfluxDB, using Grafana to visualize. Works well with the latest raspbian, tested on Pi 3B+ and Pi4. Make sure to update and upgrade your Raspbian install which should update your bluez also. The dependencies needed are at the top of the script. I like my sensor gateways pure, not tied to HA or anything.

2 Likes

@electronichamsters This is wonderful (and remarkably short). Thank you so much!

I tried to read most of this giant thread but I believe its not possible to get the very latest reading instead of the mean/median because it comes in a batch. Is that correct? In the govee app there’s an option for it to send alerts if it goes past a certain threshold… Is it possible to pass the alert if it hits that threshold or is that not possible?

I’d like to create something that turns off a humidifier when it reaches a certain point. With the current return being a mean/median it makes it hard to accurately time when to turn it off since its not the latest reading. I was hoping that if the alert could be passed through I would know that it was reached and I can turn it off through Home assistant. Is this at all possible?

I’m new to all this so sorry if this is a bad question.

Technically correct, but for your use case I think you are over thinking it. The average of the temperature/humidity is to correct for anomalies in readings or dropped signal between the Govee device and your Home Assistant Bluetooth receiver. If you want, you can lower the period from 60 seconds to 15 or 30 to turn it off once it hits a certain level.

Although, with something like a humidifier, the humidity will be higher closer to the humidifier and less further away until the air is saturated. There will be some trial and error trying to find a sweet spot in the room where is a certain balance. After finding that, you are going to want to place thresholds in where if the humidity is under X turn it on and over Y turn it off. You do not want these to be the same number as it will be constantly turning on and off. Given all of this, the average humidity within a minute is not going to make as much of a difference as you think.

Thanks I didn’t consider changing the period time. I definitely was over thinking it. I just got the pi last week and just trying to figure out how to do stuff lol. Haven’t started learning python yet (coming from c# background) but is in the future plans

@iamhueman In order to do this I had to make a second sensor that takes the value of the humidity and do a calculation. my example below (lmk if theres a better way to do this… I’m just cobbling together random google searches into something that works)

sensor:
  - platform: govee_ble_hci
    period: 10
    govee_devices:
      - mac: "e3:46:88:f1:74:87"
        name: Sensor 1
      - mac: "a4:c1:22:08:44:aa"
        name: Sensor 2
  - platform: template
    sensors:
      sensor1_calibrated:
        friendly_name: "Sensor 1 humidty Calibrated"
        unit_of_measurement: '%'
        value_template: "{{ (states('sensor.hygrometer_1_humidity')|float - 3.8) | round(2) }}"

the “- 3.8” is what you would change to do the calculation for your case

@Thrilleratplay

Can you explain how the period works? I think I’m misunderstanding something. I have it so the period is at 10. In the last hour the high for my meter has been 48ish but the mean is coming back at a little over 50?

Shouldn’t the short period make it have the mean under 50?

To answer your question, the Home Assistant componet is saying within the past 10 seconds, the average humidity of the sensor has been 50.2% based on 3 broadcast it received. The Govee app, which I do not use and know nothing about how it displays information, I suspect, pulls all of the information from the component’s memory and creates an average based on that across a period of time. So these may so some data deviation based on how much data the Home Assistant component collected and how much change there has been over the period of time.

However…in the post preceding this one you show how you are altering the display of humidity averaging between two different sensors with a difference within the same range you are now asking about here. So the images are meaningless as I do not have context to what you did in either. There is also no guarantee that the readings are from the same sensors. I also want to point out that 3 reading in 10 seconds is low and suggest either moving the receiver closer to the device, removing interference or increasing the time period to prevent times where no reading is given.

thanks for the explanation.

I’m not sure I followed your second paragraph though. The post above makes no change to the actual govee sensor. It makes a new fake sensor that uses the value of sensor 1 humidity and subtracts 3.8% to account for calibration. This new calibrated sensor is not shown in the screenshots nor is the same senor as the grow room one. Why wouldn’t the readings correlate to each sensor?

But I do not know this. The screenshots have no meaning to me on what you have done. You also have two physical sensors, which based on the MAC addresses are likely different models or very least difference sensor components within. I do not know if you are reading one sensor’s data in the app and another sensor in the HA. Because there are different models, they can be next to each other and give different values. You are asking for explanations but adding in too many variables to be able to answer.

I’ll break it down. None of those variables you are talking about really apply. All I did was add 2 separate sensors. The sensor in the HA screenshots are indeed the same sensor as the one in the govee app screenshot . I know which one is which based on the bluetooth id name. The calibrated sensor does not apply in this situation. I’m just reading the info that’s coming in and comparing it to the govee app with 0 changes to the sensor besides period time. Originally I didn’t change period time but it was still a little off like the screenshots posted above and thought changing the period time would help it get closer to the govee app

OK. Thank you for clearing that up. If these are the raw values from the same sensor then the Govee App much do some massaging of the data. If this device has an LCD, the values sent to HA should match that number.

cool thanks. I’ll do some comparisons with the actual led instead of the app sometime soon just to be sure.

In your example, -3.8 means 3.8% difference between the sensor reading and calibrated value?

Yea the - 3.8 is what is the calibration in the Govee app. So just take that number and add or subtract it in the example in place of minis 3.8

Hi, trying to get this to work on Home Assistant OS (the official image for NUCs flashed on the drive, no VM or Docker) but I’m running into errors.

My first assumption is that the Bluetooth dongle I’m using is not compatible with the system since that can be hit or miss, but before I go and buy a new one does anyone have any visibility on the error type? I’ve tried searching but haven’t found anything related to this error number in this thread.

Output from the logs is the following ;

Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/helpers/entity_platform.py”, line 199, 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 206, 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 12, in get_adapter
adapter.on()
File “/usr/local/lib/python3.8/site-packages/bleson/providers/linux/linux_adapter.py”, line 97, in on
self.send_cmd_value(HCIDEVUP, 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)
FileNotFoundError: [Errno 2] No such file or directory

The error means the OS does not recognize the default HCI device 0 as the bluetooth adapter. If this is on HA OS and are using a USB Bluetooth dongle, chances are you just need to adjust the HCI adapter. Try using the setting hci_device: hci1 in your config and restart.

That was it, error logs are clean now. Thanks!

I am using a Pi4. I was able to set up Home Assistant without any issues, but I have no data.
When running ‘bluetoothctl scan on’ I am not able to see the senor, other devices show up. The H5075 shows up using a scanner on my Android phone. Is there something else that needs to be enabled on the Pi4?

What does your config look like? Are you using any other bluetooth devices with the Pi4? Are there any errors in the core log?