Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nest Protects state won't update after device looses connectivity #63

Open
jprokopowich opened this issue Mar 17, 2022 · 26 comments
Open
Labels
bug Something isn't working p1

Comments

@jprokopowich
Copy link

jprokopowich commented Mar 17, 2022

The problem

I have 8 nest protects and some are showing constant occupancy. Since installation integration of devices (over 3 days).

What version of this integration (ha-nest-protect) has the issue?

0.3.3

What version of Home Assistant Core has the issue?

core-2022.3.5

Device / Model

Nest Protect wired (all)

Diagnostics information

nest_protect-35892183b4b12d5b93434ae1d74a1b83-Nest Protect (Master)-0cbce05c3735b0bf53ae08c61b68005a.json.txt

Home Assistant log

Seeing alot of this,

2022-03-17 15:12:29 DEBUG (MainThread) [custom_components.nest_protect] Subscriber: listening for new data
2022-03-17 15:12:47 DEBUG (MainThread) [custom_components.nest_protect] Subscriber: listening for new data
E0317 15:12:58.128674263     216 fork_posix.cc:70]           Fork support is only compatible with the epoll1 and poll polling strategies
E0317 15:13:58.130622027     220 fork_posix.cc:70]           Fork support is only compatible with the epoll1 and poll polling strategies
E0317 15:14:58.132299334     220 fork_posix.cc:70]           Fork support is only compatible with the epoll1 and poll polling strategies
E0317 15:15:58.133009206     215 fork_posix.cc:70]           Fork support is only compatible with the epoll1 and poll polling strategies
E0317 15:16:58.135773953     213 fork_posix.cc:70]           Fork support is only compatible with the epoll1 and poll polling strategies
E0317 15:17:58.135772884     219 fork_posix.cc:70]           Fork support is only compatible with the epoll1 and poll polling strategies
E0317 15:18:58.137139927     214 fork_posix.cc:70]           Fork support is only compatible with the epoll1 and poll polling strategies
E0317 15:19:58.141251612     220 fork_posix.cc:70]           Fork support is only compatible with the epoll1 and poll polling strategies
E0317 15:20:58.140739172     213 fork_posix.cc:70]           Fork support is only compatible with the epoll1 and poll polling strategies

Additional information

occurs on 3 devices at a minimum right now.

@jprokopowich jprokopowich added the bug Something isn't working label Mar 17, 2022
@iMicknl
Copy link
Owner

iMicknl commented Mar 18, 2022

Thanks for reporting! I am not sure why this doesn't work, since I don't see any exceptions in your log. Can you check your log to see if there are any warnings or exceptions? The subscriber listening for new data lines are correct. The subscriber will be reregistered when an event comes in and/or the subscriber is expired.

Do you have an idea what the fork_posix.cc line is in your log? I don't think this is related to this integration.

@jprokopowich
Copy link
Author

jprokopowich commented Mar 18, 2022

Hi,

Found these errors yesterday ,

2022-03-17 16:22:59 DEBUG (MainThread) [custom_components.nest_protect] Subscriber: listening for new data
2022-03-17 16:22:59 DEBUG (MainThread) [custom_components.nest_protect] Subscriber: retrieving new Google access token
2022-03-17 16:28:16 DEBUG (MainThread) [custom_components.nest_protect] Subscriber: listening for new data
2022-03-17 16:29:11 DEBUG (MainThread) [custom_components.nest_protect] Subscriber: listening for new data
2022-03-17 16:39:43 DEBUG (MainThread) [custom_components.nest_protect] Subscriber: listening for new data
2022-03-17 16:42:48 DEBUG (MainThread) [custom_components.nest_protect] Subscriber: listening for new data
2022-03-17 16:48:06 DEBUG (MainThread) [custom_components.nest_protect] Subscriber: listening for new data
2022-03-17 16:51:05 ERROR (MainThread) [custom_components.nest_protect] Subscriber: pynest exception.
Traceback (most recent call last):
  File "/config/custom_components/nest_protect/pynest/client.py", line 238, in subscribe_for_data
    result = await response.json()
  File "/usr/local/lib/python3.9/site-packages/aiohttp/client_reqrep.py", line 1103, in json
    raise ContentTypeError(
aiohttp.client_exceptions.ContentTypeError: 0, message='Attempt to decode JSON with unexpected mimetype: text/plain', url=URL('https://czfe05-front01-iad01.transport.home.nest.com/v6/subscribe')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/config/custom_components/nest_protect/__init__.py", line 128, in _async_subscribe_for_data
    result = await entry_data.client.subscribe_for_data(
  File "/config/custom_components/nest_protect/pynest/client.py", line 242, in subscribe_for_data
    raise PynestException(
custom_components.nest_protect.pynest.exceptions.PynestException: 200 error while subscribing - 
2022-03-17 16:52:05 DEBUG (MainThread) [custom_components.nest_protect] Subscriber: listening for new data
2022-03-17 16:52:06 ERROR (MainThread) [custom_components.nest_protect] Subscriber: pynest exception.
Traceback (most recent call last):
  File "/config/custom_components/nest_protect/pynest/client.py", line 238, in subscribe_for_data
    result = await response.json()
  File "/usr/local/lib/python3.9/site-packages/aiohttp/client_reqrep.py", line 1103, in json
    raise ContentTypeError(
aiohttp.client_exceptions.ContentTypeError: 0, message='Attempt to decode JSON with unexpected mimetype: text/plain', url=URL('https://czfe13-front01-iad01.transport.home.nest.com/v6/subscribe')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/config/custom_components/nest_protect/__init__.py", line 128, in _async_subscribe_for_data
    result = await entry_data.client.subscribe_for_data(
  File "/config/custom_components/nest_protect/pynest/client.py", line 242, in subscribe_for_data
    raise PynestException(
custom_components.nest_protect.pynest.exceptions.PynestException: 400 error while subscribing - 
2022-03-17 16:53:06 DEBUG (MainThread) [custom_components.nest_protect] Subscriber: listening for new data
2022-03-17 16:53:16 ERROR (MainThread) [custom_components.nest_protect] Subscriber: pynest exception.
Traceback (most recent call last):
  File "/config/custom_components/nest_protect/pynest/client.py", line 238, in subscribe_for_data
    result = await response.json()
  File "/usr/local/lib/python3.9/site-packages/aiohttp/client_reqrep.py", line 1103, in json
    raise ContentTypeError(
aiohttp.client_exceptions.ContentTypeError: 0, message='Attempt to decode JSON with unexpected mimetype: text/plain', url=URL('https://czfe01-front01-iad01.transport.home.nest.com/v6/subscribe')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/config/custom_components/nest_protect/__init__.py", line 128, in _async_subscribe_for_data
    result = await entry_data.client.subscribe_for_data(
  File "/config/custom_components/nest_protect/pynest/client.py", line 242, in subscribe_for_data
    raise PynestException(
custom_components.nest_protect.pynest.exceptions.PynestException: 400 error while subscribing - 
2022-03-17 16:54:16 DEBUG (MainThread) [custom_components.nest_protect] Subscriber: listening for new data
2022-03-17 16:54:18 ERROR (MainThread) [custom_components.nest_protect] Subscriber: pynest exception.
Traceback (most recent call last):
  File "/config/custom_components/nest_protect/pynest/client.py", line 238, in subscribe_for_data
    result = await response.json()
  File "/usr/local/lib/python3.9/site-packages/aiohttp/client_reqrep.py", line 1103, in json
    raise ContentTypeError(
aiohttp.client_exceptions.ContentTypeError: 0, message='Attempt to decode JSON with unexpected mimetype: text/plain', url=URL('https://czfe32-front01-iad01.transport.home.nest.com/v6/subscribe')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/config/custom_components/nest_protect/__init__.py", line 128, in _async_subscribe_for_data
    result = await entry_data.client.subscribe_for_data(
  File "/config/custom_components/nest_protect/pynest/client.py", line 242, in subscribe_for_data
    raise PynestException(
custom_components.nest_protect.pynest.exceptions.PynestException: 400 error while subscribing - 
2022-03-17 16:55:18 DEBUG (MainThread) [custom_components.nest_protect] Subscriber: listening for new data
2022-03-17 16:55:20 DEBUG (MainThread) [custom_components.nest_protect] Subscriber: listening for new data
2022-03-17 16:58:16 DEBUG (MainThread) [custom_components.nest_protect] Subscriber: listening for new data
2022-03-17 16:59:11 DEBUG (MainThread) [custom_components.nest_protect] Subscriber: listening for new data
2022-03-17 17:00:19 DEBUG (MainThread) [custom_components.nest_protect] Subscriber: listening for new data
2022-03-17 17:01:48 DEBUG (MainThread) [custom_components.nest_protect] Subscriber: listening for new data
2022-03-17 17:09:43 DEBUG (MainThread) [custom_components.nest_protect] Subscriber: listening for new data
2022-03-17 17:12:24 DEBUG (MainThread) [custom_components.nest_protect] Subscriber: listening for new data
2022-03-17 17:12:25 DEBUG (MainThread) [custom_components.nest_protect] Subscriber: listening for new data
2022-03-17 17:17:51 DEBUG (MainThread) [custom_components.nest_protect] Subscriber: listening for new data
2022-03-17 17:20:23 DEBUG (MainThread) [custom_components.nest_protect] Subscriber: listening for new data
2022-03-17 17:28:16 DEBUG (MainThread) [custom_components.nest_protect] Subscriber: listening for new data
2022-03-17 17:28:16 DEBUG (MainThread) [custom_components.nest_protect] Subscriber: retrieving new Google access token
2022-03-17 17:29:12 DEBUG (MainThread) [custom_components.nest_protect] Subscriber: listening for new data

@iMicknl
Copy link
Owner

iMicknl commented Mar 18, 2022

Thanks! It seems that it can recover from these errors, so I am not sure where we will miss a status update. I need to dive into this.

@ErikSGross
Copy link

Not sure if this is related, but adding in case it helps:

My Protect sensors in Home Assistant have been working well for about 2wk now.

Early this morning, my WAN connection went down for about 45min. I noticed that all my Protect occupancy sensors kept their values from when the internet became unavailable and then they did not update for about 6 hours after the internet connection was restored. I restarted Home Assistant and they began reporting occupancy correctly again. I didn't have debug logging enabled, but this would be an easy scenario to test (temporarily disable WAN to HA).

@brooksben11
Copy link

The occupancy sensor (and I presume all of the sensors, although I don't regularly have smoke in the house to check ;) ) gets locked to it's current state when the internet drops out. I found this out because I restart my router every evening; my temporary fix has been to schedule a HA restart shortly after my router restart.
@iMicknl, any luck into figuring this one out?

@iMicknl
Copy link
Owner

iMicknl commented Mar 26, 2022

@brooksben11 I haven't had time to have a look yet, however I should be able to pinpoint the issue and fix it :-). You don't need a restart though, a reload of the integration is enough.

And I need to set up a local environment for this probably, since this is hard to debug via GitHub Codespaces. When I kill my connection, I also lose access to my workspace 😄.

@Ibycus314
Copy link

Seeing same problem here. Interesting related to connectivity. I see it basically daily, reloading add-on fixes fir me. My internet us kind of flakey so makes sense on that front. (Basically state gets stuck and refuses to update)

@brooksben11
Copy link

@Ibycus314 Yeah, I only notice the issue when I restart my router nightly, but my internet is rock-solid (I don't think it's ever dropped even momentarily in the 5 years I've lived here. Google Fiber for the win!). Outside of this issue, the integration has been awesome for me; my only complaint is the 10 minute deal with the occupancy sensor, but that's Google's fault.

@iMicknl I'm fine doing a HA restart as a temporary fix, but is there a way to (easily) automate the reloading of an integration? A quick google search made it seem not easily doable and I don't feel like putting in much effort for an adjustment to a bandaid. :)

@iMicknl
Copy link
Owner

iMicknl commented Mar 31, 2022

@brooksben11, I recall that there should be a way to reload an integration / config entry. However, I will see if I can have a look at this someday. I agree that this is an important fix, but I just need to find some time to work on this. 😞

@iMicknl iMicknl added the p1 label Mar 31, 2022
@Ibycus314
Copy link

I haven’t looked at the code, but could it be some kind of authentication issue? I’m assuming some kind of cookie or some such associated with the API transaction. I wonder if the connection attempt fails the system needs to re-authenticate?

@iMicknl
Copy link
Owner

iMicknl commented Mar 31, 2022

@Ibycus314 I think that the issue is that we don't retry this scenario. In order to make sure that we don't end up in a 'retry loop', we only restart the event listener for known exceptions. It should be a relatively easy fix to check for disconnected exceptions, and retry accordingly.

@Ibycus314
Copy link

Sounds good, I’m sure you know your code way better than Me, I just know I’ve had tunnel vision in the past trying to track down bugs, figured a place to start anyways.

@Ibycus314
Copy link

Not sure if it helps, but I think it happens when the Smoke detector looses connectivity, rather than necessarily when the internet goes down (i.e. when home assistant looses connection). My microwave has a tendency to knock out my wifi, and just noticed the sensors seem to get stuck when the microwave runs (which shouldn’t impact home assistant’s connection)

@iMicknl
Copy link
Owner

iMicknl commented Apr 29, 2022

@lbycus314 and there is no mention in your log when the data is not updated? This one is hard for me to reproduce unfortunately.

@Ibycus314
Copy link

Had a bit of a dig, looks like most of the sensors (line power, battery health, etc) all say “Became unavailable” then immediately come back. Occupancy just stops updating (is there a specific part of the logs you’d like?)

@iMicknl
Copy link
Owner

iMicknl commented Apr 29, 2022

I wonder if there is an exception in your logs, or if this cannot be detected by our integration. In that case, we probably need to check if a device moves from unavailable to available and then refresh all states.

Probably not only occupancy stops updating, but all status updates.

@brooksben11
Copy link

So I recently did a quick test to determine whether it's the Nest devices or the Home Assistant instance losing connectivity that causes the sensors to stop updating (I also recently upgraded the Nest integration to the latest version, 0.3.5). I unplugged the ethernet cable to the Raspberry Pi running my Home Assistant instance for a few minutes and then reconnected. My logs look normal up until then and then just stop updating (as well as my motion sensor states staying stuck in their last state). So it's definitely an issue of the integration losing connectivity, not the Nest devices. Hopefully this helps narrow down the issue...

@Ibycus314
Copy link

Can confirm issue still present with latest releases. In terms of brooksben11’s comment, I would say either can loose connectivity and it be an issue. Every time I run my microwave for an extended period, it knocks out my wifi, causing the issue.

@iMicknl iMicknl changed the title Nest Protects motion integration Nest Protects state won't update after device looses connectivity Jun 15, 2022
@iMicknl
Copy link
Owner

iMicknl commented Jun 15, 2022

I am currently looking into this, however does the app show anything when there is no connectivity? In my situation I have disabled my wifi network for one of my Nest Protects, but it still shows green in the app...

@Ibycus314
Copy link

Ibycus314 commented Jun 15, 2022 via email

@brooksben11
Copy link

Not that I’m been able to tell. Just doesn’t update status when it changes….

Sent from my iPad
Sent from my iPad
On Jun 15, 2022, at 9:48 AM, Mick Vleeshouwer @.***> wrote:  I am currently looking into this, however does the app show anything when there is no connectivity? In my situation I have disabled my wifi network for one of my Nest Protects, but it still shows green in the app... — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.

Same for me. From what I remember everything looks normal but it doesn't update.

@iMicknl
Copy link
Owner

iMicknl commented Jun 16, 2022

That was my observation as well, so I need to see if there is a way to detect this...

@puterboy
Copy link

puterboy commented Dec 30, 2024

@iMicknl as you point out, seems like similar or same bug as the one I reported in #385.
However, my issue is with Nest remote temperature sensors.
As reported there, bug is reliably repeatable every time I reboot my router.

Have you made any further progress in troubleshooting and/or fixing this since the last post 2+ years ago?

@puterboy
Copy link

@iMicknl one thing that perhaps could help troubleshoot this is you had any standalone python (or other language) code that I could run and monitor. I can then "play" with the code, including adding more debugging output to get a better handle on where and why it is failing.

Is it possible to extract the code as a standalone python script that writes the output to stdout.

This would be easier for me than messing with my "production" HA setup since I hate to take it down and restart it unnecessarily.

@jazzyisj
Copy link

jazzyisj commented Jan 4, 2025

@puterboy it's probably a little easier for you to spin up a dev HA instance in a venv or container somewhere than it is for Mick to rewrite the integration to suit your needs. I'm sure he would love the help!

https://developers.home-assistant.io/docs/development_environment/

@iMicknl
Copy link
Owner

iMicknl commented Jan 5, 2025

This repository actually has a devcontainer that you can leverage as well (where HA is included).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working p1
Projects
None yet
Development

No branches or pull requests

7 participants