custom-components / ble_monitor

BLE monitor for passive BLE sensors
https://community.home-assistant.io/t/passive-ble-monitor-integration/
MIT License
1.9k stars 245 forks source link

[Bug]: Some Govee readings cycle between two widely separated values #907

Closed fovea1959 closed 2 years ago

fovea1959 commented 2 years ago

What happened?

I have a Govee 5178; ble_monitor has started reporting the battery level as changing between 69 and 48 on a frequent basis (17 or 18 times per hour).

Screenshot from 2022-06-23 09-41-40

The Govee app on my phone does not show this; it does show the current level for the battery in the base unit to be 3 of 5 bars, and the battery in the remote sensor to be 2 of 5 bars.

I have also had some like this happen with a H5075's temperature readings. Removing and replacing the (same) battery solved it.

Is there a way to get a raw dump of the packets coming in so troubleshooting can proceed?

Sensor type

H5178, H5075

Relevant log output

(none)
Ernst79 commented 2 years ago

I normally add the following to the code to do some debugging

_LOGGER.error("Data: %s ", data.hex())

e.g. in govee.py

fovea1959 commented 2 years ago

ok, added a _LOGGER.debug into the H5178.

2022-06-29 12:30:23 DEBUG (Thread-3) [custom_components.ble_monitor.ble_parser.govee] H5178 packet: 039c23, sensor_id 1, batt 43
2022-06-29 12:30:25 DEBUG (Thread-3) [custom_components.ble_monitor.ble_parser.govee] H5178 packet: 039ff1, sensor_id 0, batt 68
2022-06-29 12:30:29 DEBUG (Thread-3) [custom_components.ble_monitor.ble_parser.govee] H5178 packet: 039ff1, sensor_id 0, batt 68
2022-06-29 12:30:31 DEBUG (Thread-3) [custom_components.ble_monitor.ble_parser.govee] H5178 packet: 039c23, sensor_id 1, batt 43
2022-06-29 12:30:33 DEBUG (Thread-3) [custom_components.ble_monitor.ble_parser.govee] H5178 packet: 039ff4, sensor_id 0, batt 68
2022-06-29 12:30:35 DEBUG (Thread-3) [custom_components.ble_monitor.ble_parser.govee] H5178 packet: 039c23, sensor_id 1, batt 43

I think that battery level being reported by the H5178 is the battery level for whichever sensor the temp/hum data is for; sensor 0 is the indoor (base) unit, and sensor 1 is the remote (outdoor) unit.

In the H5178 leg of govee.py:

    ####
    _LOGGER.debug(f'H5178 packet: {packet_5178}, sensor_id {sensor_id}, batt {batt}')
    ####
    if sensor_id == 0:
        result.update(
            {
                "temperature": temp,
                "humidity": humi,
                "battery": batt,
                "sensor id": sensor_id
            }
        )
    elif sensor_id == 1:
        result.update(
            {
                "temperature outdoor": temp,
                "humidity outdoor": humi,
                "battery": batt,
                "sensor id": sensor_id
            }
        )

If the sensor_id is 1, does it make sense to map the battery level into the result dict as item 'battery outdoor'?

fovea1959 commented 2 years ago

Just looked at the rest of the code; no provision for "battery outdoor". Need to do one of:

Ernst79 commented 2 years ago

Ah, that makes sense. I will fix it, probably by adding “battery outdoor”. Splitting it in two devices is way more complicated, as all devices are based on the MAC address, and the Govee only has one MAC for both devices.

fovea1959 commented 2 years ago

Let me know if I can help with testing... Could appending a suffix to the base unit MAC for the outdoor sensor be a viable solution for separating the 2 units?

Sent from AT&T Yahoo Mail on Android

On Wed, Jun 29, 2022 at 1:28 PM, Ernst @.***> wrote:

Ah, that makes sense. I will fix it, probably by adding “battery outdoor”. Splitting it in two devices is way more complicated, as all devices are based on the MAC address, and the Govee only has one MAC for both devices.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

Ernst79 commented 2 years ago

Yes, that might also be an option, but I need to check th consequences, as all code depends the MAC address, also e.g. the device settings. I’ll look into it

Ernst79 commented 2 years ago

Try 8.9.3, sensor is split into two devices. I had to increase the MAC address of the outdoor sensor with 1, it wasn't possible to add a suffix to the MAC, as there are quite some checks that the MAC address is 12 characters long, in a certain format.

fovea1959 commented 2 years ago

fix works as expected.