asednev / homebridge-plugin-govee

Govee H-series Thermometer Hygrometer plugin for Homebrige.
Apache License 2.0
53 stars 9 forks source link

Stale Data not Updating #19

Open Foxtrot79 opened 3 years ago

Foxtrot79 commented 3 years ago

Describe Your Problem: The H5075 hygrometers load into Homebridge just fine with the plugin. I see a flurry of updates from the hygrometers after the boot has completed of HomeBridge and it stabilizes. The issue is after a little bit of time the status changes don't appear to happen and the data in the Home App becomes stale and does not update. I can sometimes trigger an update by closing the Home App and opening it back up but this is rare.

I have tried to trigger changes with one of the hygrometers and even after a 5 degree change in temperature there is no change in the HomeBridge logs with debugging turned on. I know the hygrometers are working beucase I am also using their data in Home Asistant and the sensors in there react to the data coming from the hygrometers.

Logs: The only thing after the initial updates that I see in the logs with debugging turned on is the like the following. It appears that only one is giving updates.

[28/01/2021, 16:39:37] [Backyard Christmas Lights Plug 2] Retrieved status unsuccessfully. [28/01/2021, 16:39:37] [Backyard Christmas Lights Plug 2] getOnCharacteristicHandler: false [28/01/2021, 16:39:37] [Govee-Home-Hygrometers-3] getStatusLowBattery [28/01/2021, 16:39:37] [Govee-Home-Hygrometers-3] getCurrentTemperature 21.5369 [28/01/2021, 16:39:37] [Govee-Home-Hygrometers-3] getCurrentRelativeHumidity 36.9 offset 0 [28/01/2021, 16:39:38] [Garage Door] Current state CLOSED [28/01/2021, 16:39:43] [Garage Door] Current state CLOSED [28/01/2021, 16:39:48] [Garage Door] Current state CLOSED [28/01/2021, 16:39:53] [Garage Door] Current state CLOSED [28/01/2021, 16:40:02] [Garage Door] Current state CLOSED [28/01/2021, 16:40:03] [Garage Door] Current state CLOSED [28/01/2021, 16:40:08] [Garage Door] Current state CLOSED [28/01/2021, 16:40:13] [Garage Door] Current state CLOSED [28/01/2021, 16:40:18] [Garage Door] Current state CLOSED [28/01/2021, 16:40:23] [Garage Door] Current state CLOSED [28/01/2021, 16:40:28] [Garage Door] Current state CLOSED [28/01/2021, 16:40:33] [Garage Door] Current state CLOSED

Show the Homebridge logs here, remove any sensitive information.

[28/01/2021, 16:39:37] [Backyard Christmas Lights Plug 2] Retrieved status unsuccessfully. [28/01/2021, 16:39:37] [Backyard Christmas Lights Plug 2] getOnCharacteristicHandler: false [28/01/2021, 16:39:37] [Govee-Home-Hygrometers-3] getStatusLowBattery [28/01/2021, 16:39:37] [Govee-Home-Hygrometers-3] getCurrentTemperature 21.5369 [28/01/2021, 16:39:37] [Govee-Home-Hygrometers-3] getCurrentRelativeHumidity 36.9 offset 0 [28/01/2021, 16:39:38] [Garage Door] Current state CLOSED [28/01/2021, 16:39:43] [Garage Door] Current state CLOSED [28/01/2021, 16:39:48] [Garage Door] Current state CLOSED [28/01/2021, 16:39:53] [Garage Door] Current state CLOSED [28/01/2021, 16:40:02] [Garage Door] Current state CLOSED [28/01/2021, 16:40:03] [Garage Door] Current state CLOSED [28/01/2021, 16:40:08] [Garage Door] Current state CLOSED [28/01/2021, 16:40:13] [Garage Door] Current state CLOSED [28/01/2021, 16:40:18] [Garage Door] Current state CLOSED [28/01/2021, 16:40:23] [Garage Door] Current state CLOSED [28/01/2021, 16:40:28] [Garage Door] Current state CLOSED [28/01/2021, 16:40:33] [Garage Door] Current state CLOSED Plugin Config: { "name": "Govee-Home-Hygrometers-3", "batteryThreshold": 25, "debug": false, "humidityOffset": 0, "platform": "GoveeHomebridgePlugin" }


{
    "bridge": {
        "name": "ABIT-H-HomeBR",
        "username": "XXXX",
        "port": XXXX,
        "pin": "XXX-XX-XXX"
    },
    "accessories": [
        {
            "model": "MSG100",
            "name": "Garage Door",
            "deviceUrl": "172.30.20.70",
            "channel": 0,
            "messageId": "XXXXXX",
            "timestamp": XXXXXX,
            "sign": "XXXXX",
            "garageDoorOpeningTime": 20,
            "accessory": "Meross"
        },
        {
            "model": "MSS620",
            "name": "South Fence Rope Light",
            "deviceUrl": "172.30.20.72",
            "channel": 1,
            "messageId": "XXX",
            "timestamp": XXX,
            "sign": "XXX",
            "accessory": "Meross"
        },
        {
            "model": "MSS620",
            "name": "Backyard Christmas Lights Plug 2",
            "deviceUrl": "172.30.20.72",
            "channel": 2,
            "messageId": "XXXXX",
            "timestamp": XXXXX,
            "sign": "XXXXX",
            "accessory": "Meross"
        },
        {
            "model": "MSS620",
            "name": "North Fence Rope Light",
            "deviceUrl": "172.30.20.71",
            "channel": 2,
            "messageId": "XXXX",
            "timestamp": XXXX,
            "sign": "XXXXX",
            "accessory": "Meross"
        },
        {
            "model": "MSS620",
            "name": "Stars and Pole Rope Lights",
            "deviceUrl": "172.30.20.71",
            "channel": 1,
            "messageId": "XXXXX",
            "timestamp": XXXXX,
            "sign": "XXXX",
            "accessory": "Meross"
        }
    ],
    "platforms": [
        {
            "name": "ABIT-H-HomeBridge1911",
            "port": XXXX,
            "auth": "form",
            "theme": "auto",
            "tempUnits": "f",
            "lang": "auto",
            "platform": "config"
        },
        {
            "name": "Nest",
            "googleAuth": {
                "issueToken": "XXXXXX",
                "cookies": "XXXXX"
            },
            "platform": "Nest"
        },
        {
            "name": "ABIT-HUB",
            "hubIP": "172.30.20.92",
            "hubName": "ABIT-HUB",
            "platform": "HarmonyHubWebSocket"
        },
        {
            "name": "Camera FFmpeg",
            "cameras": [
                {
                    "name": "Front Yard",
                    "videoConfig": {
                        "source": "-i rtsp://XXXXXX",
                        "maxStreams": 3,
                        "maxFPS": 0,
                        "audio": true
                    }
                },
                {
                    "name": "Side Yard",
                    "videoConfig": {
                        "source": "-i rtsp://XXXX:XXXXXX",
                        "maxStreams": 3,
                        "maxFPS": 0
                    }
                }
            ],
            "platform": "Camera-ffmpeg"
        },
        {
            "name": "Wemo",
            "discoveryInterval": 30,
            "disableDiscovery": false,
            "disableDeviceLogging": false,
            "debug": false,
            "disablePlugin": false,
            "noMotionTimer": 60,
            "doorOpenTimer": 20,
            "manualDevices": [
                "http://172.30.40.70:49153/setup.xml",
                "http://172.30.40.71:49153/setup.xml",
                "http://172.30.40.72:49153/setup.xml",
                "http://172.30.40.73:49153/setup.xml",
                "http://172.30.40.74:49153/setup.xml",
                "http://172.30.40.75:49153/setup.xml"
            ],
            "makerTypes": [
                {
                    "makerTimer": 20
                }
            ],
            "platform": "BelkinWeMo"
        },
        {
            "name": "Govee-Home-Hygrometers-3",
            "batteryThreshold": 25,
            "debug": false,
            "humidityOffset": 0,
            "platform": "GoveeHomebridgePlugin"
        }
    ]
}

Screenshots:

Environment:

IMG_0646

asednev commented 3 years ago

@Foxtrot79 It seems that homebridge plugin is working correctly. This is likely an integration of Homebridge with Apple Home.

[28/01/2021, 16:39:37] [Govee-Home-Hygrometers-3] getStatusLowBattery
[28/01/2021, 16:39:37] [Govee-Home-Hygrometers-3] getCurrentTemperature 21.5369
[28/01/2021, 16:39:37] [Govee-Home-Hygrometers-3] getCurrentRelativeHumidity 36.9 offset 0

Two things to check:

  1. Is you Homebridge added to your Apple Home as a bridge? i.e. the answer is yes if you have any other accessories exposed to Apple Home through Homebridge.
  2. Did you check other rooms in your Apple Home? Your screenshot shows "Office" room, new accessory might be added into a different room depending on Apple Home settings.
Foxtrot79 commented 3 years ago

I do have other accessories through Homebridge showing just fine and operating normally. These are only devices like Wemo but not any other sensors through Homebridge. The other hygrometers I have from Govee are also showing the same issue. I have a total of 9 and they show correctly in Homebridge but with stale data. The update that you showed does update the data in HomeBridge but not that frequent. I see a flurry of updates from all the hygrometers when I reboot with debugging on. These updates do not continue after awhile and move back to a trickle to none.

asednev commented 3 years ago

Do you see Govee sensors on the "Accessories" tab in your Homebridge web UI?

Foxtrot79 commented 3 years ago

I do see the sensors in the Accessories tab but the data is not changing. I forced a temperature change on the Office sensor and it is not reflecting the change. It still shows the temperature is 68.7 F degrees when the temperature on the physical sensor is 80 F.

asednev commented 3 years ago

@Foxtrot79 EDIT (removed the part about Homebridge <> Apple Home integration)

I think there's something about your bluetooth module where subscription dies out after some time. There might be a workaround to renew that automatically. Thank you for your report!

Foxtrot79 commented 3 years ago

I can reach out to the home bridge community about the module but I have tried two different bluetooth modules and the same results happen. Is there a place that I should pose the question about the module in particular that you could recommend?

asednev commented 3 years ago

@Foxtrot79 Respberry PI or Raspbian community will be more likely to help than Homebridge. Also, this plugin uses noble to handle bluetooth, worth checking out their issues page and see if anyone else experiences similar issue: https://github.com/abandonware/noble/issues

Foxtrot79 commented 3 years ago

Thank you for your help.

clogan2 commented 3 years ago

I'm absolutely experiencing this too @asednev . I've tried a couple different USB bluetooth adapters (x86_64 running on Ubuntu Server).

I dug into the code a little bit, and it looked to me like there was no code to refresh the temperature/humidity data (only on plugin initialization).

Perhaps your homebridge instance is being rebooted routinely, giving you the illusion of temperature/humidity updates?

asednev commented 3 years ago

@clogan2 thank you for looking into the code. Here's the line where subscription for peripheral discovery takes place: https://github.com/asednev/homebridge-plugin-govee/blob/master/src/platform.ts#L66

All events captured from bluetooth are passed into the instance of accessory right here: https://github.com/asednev/homebridge-plugin-govee/blob/master/src/platform.ts#L88

It's not accidental that temperature & humidity updates are working without homebridge reboot. I suspect that on some devices subscription to peripheral discovery is short lived. Might be worth digging into noble. Here's relevant API that this plugin uses underneath: https://github.com/noble/noble#peripheral-discovered

asednev commented 3 years ago

@Foxtrot79 @clogan2 I implemented some logic to restart subscription if it dies. Could you try testing this and provide feedback on whether this helped?

You will need to install version 1.1.0 - beta: https://www.npmjs.com/package/homebridge-plugin-govee/v/1.1.0

this gif shows how to install beta plugins:

asednev commented 3 years ago

@Foxtrot79 @clogan2 There is a new beta version 1.1.1. which incorporates this fix and a fix for another issue. Look forward to hearing if the fix worked for you.

Foxtrot79 commented 3 years ago

I tried to install the beta but the GIF you are showing is to install a beta for Home Bridge itself. I tried running the command that is on the page for 1.1.0 in the Home Bridge terminal but it errors out with the following:

pi@homebridge:/var/lib/homebridge $ npm i homebridge-plugin-govee@1.1.0

usb@1.6.5 install /var/lib/homebridge/node_modules/usb prebuild-install --verbose || node-gyp rebuild

prebuild-install info begin Prebuild-install version 5.3.6 prebuild-install info looking for cached prebuild @ /home/pi/.npm/_prebuilds/b839e8-usb-v1.6.5-node-v83-linux-arm.tar.gz prebuild-install http request GET https://github.com/tessel/node-usb/releases/download/v1.6.5/usb-v1.6.5-node-v83-linux-arm.tar.gz prebuild-install http 404 https://github.com/tessel/node-usb/releases/download/v1.6.5/usb-v1.6.5-node-v83-linux-arm.tar.gz prebuild-install WARN install No prebuilt binaries found (target=14.16.0 runtime=node arch=arm libc= platform=linux) make: Entering directory '/var/lib/homebridge/node_modules/usb/build' CC(target) Release/obj.target/libusb/libusb/libusb/core.o CC(target) Release/obj.target/libusb/libusb/libusb/descriptor.o CC(target) Release/obj.target/libusb/libusb/libusb/hotplug.o CC(target) Release/obj.target/libusb/libusb/libusb/io.o CC(target) Release/obj.target/libusb/libusb/libusb/strerror.o CC(target) Release/obj.target/libusb/libusb/libusb/sync.o CC(target) Release/obj.target/libusb/libusb/libusb/os/poll_posix.o CC(target) Release/obj.target/libusb/libusb/libusb/os/threads_posix.o CC(target) Release/obj.target/libusb/libusb/libusb/os/linux_usbfs.o CC(target) Release/obj.target/libusb/libusb/libusb/os/linux_udev.o ../libusb/libusb/os/linux_udev.c:40:10: fatal error: libudev.h: No such file or directory

include

      ^~~~~~~~~~~

compilation terminated. make: *** [libusb.target.mk:148: Release/obj.target/libusb/libusb/libusb/os/linux_udev.o] Error 1 make: Leaving directory '/var/lib/homebridge/node_modules/usb/build' gyp ERR! build error gyp ERR! stack Error: make failed with exit code: 2 gyp ERR! stack at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:194:23) gyp ERR! stack at ChildProcess.emit (events.js:315:20) gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12) gyp ERR! System Linux 5.4.79-v7l+ gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild" gyp ERR! cwd /var/lib/homebridge/node_modules/usb gyp ERR! node -v v14.16.0 gyp ERR! node-gyp -v v5.1.0 gyp ERR! not ok npm WARN saveError ENOENT: no such file or directory, open '/var/lib/homebridge/package.json' npm WARN enoent ENOENT: no such file or directory, open '/var/lib/homebridge/package.json' npm WARN homebridge No description npm WARN homebridge No repository field. npm WARN homebridge No README data npm WARN homebridge No license field. npm WARN optional SKIPPING OPTIONAL DEPENDENCY: usb@1.6.5 (node_modules/usb): npm WARN optional SKIPPING OPTIONAL DEPENDENCY: usb@1.6.5 install: prebuild-install --verbose || node-gyp rebuild npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1

6 packages are looking for funding run npm fund for details

found 0 vulnerabilities

pi@homebridge:/var/lib/homebridge $

Thanks.

asednev commented 3 years ago

@Foxtrot79 right, the gif shows how to update homebridge to beta but the process is the same for plugins. Here are a couple of screenshots to guide you:

  1. Select "Plugins" in the main menu

  2. image
  3. image
Foxtrot79 commented 3 years ago

The install worked fine and there was a flurry of events with the debug turned on but the updating showing in the Home App seems to stop the same as it did with the previous version. I moved a thermometer closer to a heat source and in the home App the temperature climbed to the same as the thermometer was showing but when I moved it away an the temperature on the thermometer dropped the Home App still showed the stale high temperature. The difference was about 7 degrees F.

asednev commented 3 years ago

@Foxtrot79 could you capture logs for this plugin after homebridge restart between the moment that updates to temperature come through and stop?

Foxtrot79 commented 3 years ago

This is with debugging turned on for the plugin. I don't really see anything with debugging turned off. What I am seeing would go on for pages here but mostly it is these lines repeating over and over until they stop and things appear to sit idle.

iscovered a4c138264172 a4c138264172 a4:c1:38:26:41:72 disconnected -81 invalid peripheral, manufacturerData=[4c000215494e54454c4c495f524f434b535f48575075f2ffc2] discovered a4c1382a512c a4c1382a512c a4:c1:38:2a:51:2c disconnected -86 a4c1382a512c: 88ec0002e8485900 discovered a4c1382a512c a4c1382a512c a4:c1:38:2a:51:2c disconnected -85 invalid peripheral, manufacturerData=[4c000215494e54454c4c495f524f434b535f48575075f2ffc2] discovered a4c138552f32 a4c138552f32 a4:c1:38:55:2f:32 disconnected -86 a4c138552f32: 88ec00031e9f5b00 discovered a4c1383a77be a4c1383a77be a4:c1:38:3a:77:be disconnected -85 a4c1383a77be: 88ec0003170b5700 discovered a4c1383a77be a4c1383a77be a4:c1:38:3a:77:be disconnected -84 invalid peripheral, manufacturerData=[4c000215494e54454c4c495f524f434b535f48575075f2ffc2] discovered a4c13823affe a4c13823affe a4:c1:38:23:af:fe disconnected -75 a4c13823affe: 88ec0002cc595100 discovered a4c13823affe a4c13823affe a4:c1:38:23:af:fe disconnected -74 invalid peripheral, manufacturerData=[4c000215494e54454c4c495f524f434b535f48575075f2ffc2] discovered a4c13843a068 a4c13843a068 a4:c1:38:43:a0:68 disconnected -74 a4c13843a068: 88ec0003037a5800 discovered a4c138264172 a4c138264172 a4:c1:38:26:41:72 disconnected -86 a4c138264172: 88ec00032a515700 discovered a4c1382a512c a4c1382a512c a4:c1:38:2a:51:2c disconnected -87 a4c1382a512c: 88ec0002e8475900 discovered a4c1382a512c a4c1382a512c a4:c1:38:2a:51:2c disconnected -85 invalid peripheral, manufacturerData=[4c000215494e54454c4c495f524f434b535f48575075f2ffc2] discovered a4c1389b7410 a4c1389b7410 a4:c1:38:9b:74:10 disconnected -99 a4c1389b7410: 88ec000339f25c00 discovered a4c13823affe a4c13823affe a4:c1:38:23:af:fe disconnected -75 a4c13823affe: 88ec0002cc595100 discovered a4c13823affe a4c13823affe a4:c1:38:23:af:fe disconnected -74 invalid peripheral, manufacturerData=[4c000215494e54454c4c495f524f434b535f48575075f2ffc2] discovered a4c13843a068 a4c13843a068 a4:c1:38:43:a0:68 disconnected -74 a4c13843a068: 88ec0003037b5800 discovered a4c138264172 a4c138264172 a4:c1:38:26:41:72 disconnected -87 a4c138264172: 88ec00032a505700 discovered a4c138264172 a4c138264172 a4:c1:38:26:41:72 disconnected -85 invalid peripheral, manufacturerData=[4c000215494e54454c4c495f524f434b535f48575075f2ffc2] [Front Yard] The image snapshot handler for the given accessory didn't respond at all! See https://git.io/JtMGR for more info. discovered a4c1383a77be a4c1383a77be a4:c1:38:3a:77:be disconnected -84 a4c1383a77be: 88ec0003170b5700 discovered a4c13823affe a4c13823affe a4:c1:38:23:af:fe disconnected -85 a4c13823affe: 88ec0002cc595100 discovered a4c13823affe a4c13823affe a4:c1:38:23:af:fe disconnected -84 invalid peripheral, manufacturerData=[4c000215494e54454c4c495f524f434b535f48575075f2ffc2] discovered a4c13843a068 a4c13843a068 a4:c1:38:43:a0:68 disconnected -75 a4c13843a068: 88ec0003037b5800 discovered a4c138264172 a4c138264172 a4:c1:38:26:41:72 disconnected -87 a4c138264172: 88ec00032a515700 discovered a4c138264172 a4c138264172 a4:c1:38:26:41:72 disconnected -86 invalid peripheral, manufacturerData=[4c000215494e54454c4c495f524f434b535f48575075f2ffc2] discovered a4c1381422e2 a4c1381422e2 a4:c1:38:14:22:e2 disconnected -82 a4c1381422e2: 88ec00029daa5a00 discovered a4c1389b7410 a4c1389b7410 a4:c1:38:9b:74:10 disconnected -101 a4c1389b7410: 88ec000339f25c00 discovered a4c1383a77be a4c1383a77be a4:c1:38:3a:77:be disconnected -83 a4c1383a77be: 88ec0003170b5700 discovered a4c1383a77be a4c1383a77be a4:c1:38:3a:77:be disconnected -82 invalid peripheral, manufacturerData=[4c000215494e54454c4c495f524f434b535f48575075f2ffc2] discovered a4c13843a068 a4c13843a068 a4:c1:38:43:a0:68 disconnected -76 a4c13843a068: 88ec0003037c5800 discovered a4c1381422e2 a4c1381422e2 a4:c1:38:14:22:e2 disconnected -87

Furtivo360 commented 3 years ago

Hey! I've noticed the issue too.

I do have HomeBridge v1.3.4 installed on a UbuntuServer VM on ProxMox.

The range of my bluetooth dongle is pretty good, no issues with signal only the data did't refresh on the home app after the first connection as mentioned above...

What I did was setting up an automatic task via crontab that is restarting the "hb-service" every 10mins

From ProxMox VM terminal or SSH, as sudo, run:

crontab -e (I think you will be asked to choose your preferred application to modify text)

add:

0,10 * * * * hb-service restart

Save and exit.

So far so good!

Note: you can setup your own restart time 0,10 is 10mins, 0,20 is 20mins and so on...)

Thanks

Diego

asednev commented 3 years ago

Thanks for your feedback @Furtivo360.

I am considering other ways to restart bluetooth connection. An options that I have in mind is to add a timeout for last time data, if there is no new data in X seconds, restart the connection. Interval X could be configured in settings.

Foxtrot79 commented 3 years ago

I had been using the cron method and that worked great for keeping the data up to date, it did create havoc with some of my other accessories in home bridge. It caused many of the older Wemo switches to not be available when automations needed to run. Having a way to only restart the BT connection or something like it would work better since it wouldn't affect the other accessories. Thanks again for the continued development.

ChrisPatten commented 2 years ago

Thanks for your feedback @Furtivo360.

I am considering other ways to restart bluetooth connection. An options that I have in mind is to add a timeout for last time data, if there is no new data in X seconds, restart the connection. Interval X could be configured in settings.

I found this issue while trying to figure out how to fork this and do exactly that, because I’m having this same problem. This is exactly how I wish it worked. Or is it possible to poll periodically and listen for X seconds every Y seconds?