HA stops reporting Wink state changes

Doesn’t look like an issue, I have seen those many times and it hasn’t caused me any issues.

I know the test script isnt a fix, but it isnt working any longer. The state wasn’t updating again so I ran the script but the state still didn’t update. I had to run the wink refresh service.

So after running the script and the refresh did everything start working again? The test script won’t update the states if they are already out of sync, it should hopefully make it start working again on the next state change.

Now that you say the test script won’t update a state that is already out of sync, I went back and did a test this morning. I turned on the light using the wink remote. HA did not update the state so I ran the test script. I turned the light off using the remote, waited for maybe a minute and turned it back on. HA’s state updated.

So it was my bad for thinking the test script updated the state if it was out of sync. Sorry, it is working.

Now, is there something I need to do to fix this? Or are you still working on a fix?

Well, I am still not sure how I could implement this in the HA code. I haven’t thought too much about it because I wasn’t sure if this would fix it or not. It seems like it’s working for you, but I would like some other users to test it as well. I would also like to try manually refreshing the existing access token in the HA code prior to doing the polling to see if that has the same result as this, as that would be much simpler. I will try to get you an update to test soon.

In the mean time you could setup a command line switch to run the test script you have and then set an automation to run every hour to temporarily fix your issue.

Thank you. I appreciate your help and contribution.

I thought about setting up a command line switch and I will probably do that for now.

From my tests using wink_test.py, it does make my HA start showing the correct states when something changes. And as @w1ll1am23 stated, the states out of sync did not get back into sync with the script. After running the script and testing state changes, I issued the wink.refresh_state_from_wink and that corrected the already out of sync states.

@w1ll1am23, thank you very much for putting together this script for testing. Please let me know if there is anything else that I can do to help test.

Interesting to find this thread. I have found the same or similar issue it seems. I have a Lutron Light and 3 leak Sensors.

Every once in a while I will notice that my light shows off even though my light is on and the sensors will not react to a test wet sensor. The thing that seems to fix it for me is simply watching the Wink app on my iPhone, and then HA seems to get back into sync again.

The light when in this state will flip on and then flip back off without actually working.

Odd that running the wink app fixes this, no?

If you read above about the “test script” it is basically doing what you are doing when you open the app so that makes perfect sense to me. I will try to put in some more work on this shortly and see if I can come up with an official way of implementing the test script.

Thanks. Prepped to run the wink test python script once it fails.

It has been almost 10 hours since I last ran the wink app and my sensors and light started working again. Just checked and home assistant no longer sees state changes on the light, and when I try to turn on the light nothing happens and the light slider switches back to off after a few seconds.

So, I ran the script, got the URL, went to wink site, logged in, got 404, copied code, entered and got token. Then pasted the token into wink test script, commented out the correct lines, uncommented the new one and ran the script, no output (as expected).

Tried to toggle the light from the wall switch, no state updates in home assistant. Tried this a few times. Then I tried to turn on the light from home assistant, and this time the light came on, but the slider still goes back to off after a few seconds.

So while I can control my lights (as in I can turn them on), the state didn’t update and since the slider is on off, I cannot turn off the light.

I opened the wink app on iPhone, then went back to home assistant ios app, and all is working fine again, state changes seem to track and I can turn on and off the light.

So, the script was’t really successful for me. Hope this helps us get closer to a solution. Do you feel full debug logs may help figure out why it is failing?

Just another followup, I just got home and again my wink light didn’t follow state. I tried the python scripts again, following all the steps and again it didn’t work to update the state.

Opened wink app and all is running.

This is also impacting my zigbee water sensors, which is my bigger concern.

I don’t think I am doing anything wrong. If there is something I can help with to debug this, let me know. I am a developer and comfortable with python.

Thank you.

Thanks for the feed back. I wonder if they have made a change to only accept updates from the official app. I will try to put together a test script with the Android user-agent and then have you try running that and see if it works.

Their API is published no? I would be surprised if they blocked that based on user Agent.

Looking at the code I realized that in my first run when I get the code I had both the set bearer and get devices call commented out. Was the first run suppose to call get devices as well?

Also, how long is the token generated good for? Should I regenerate it every time?

Need to see how to get the logger output into the screen to see if there are any errors as the second run never has any output.

The API is public but not documented well. I had to use the calls from the Android app to get a fully working library. For example the device type on each device isn’t sent back if you don’t call the API with a properly formated user agent, but that isn’t documented anywhere.

I am not sure how long token are good for, they don’t send an token expiration time back when we get a token.

The first run is just to get your token. That token is good for several weeks but I am not sure exactly how long.

If there were any errors it would output no output means it worked.

Thanks, that makes sense. This was a lot of work to figure out, thank you for doing it and sharing.

So, in an attempt to help, I turn on full debug logs for pubnub,wink,pywink.api and left it overnight. In the morning, sure enough the light state doesn’t follow the wall switch.

I have not opened the wink app, and I have not run any scripts yet. If there something worth trying, I will leave this as to experiment.

What I can say, all night and still continuing in the logs, the pubnub heart 5 minute poll and the 5 minute subscription long poll continue to operate and continue to get success 200. The hourly pywink.api poll “to keep pubnub updates flowing” keeps working as well with 200 success.

This is very useful, thanks. So not sure if you have been able to read through this entire thread I hope not lol. But this is the EXACT same issue that first started happening when I first put in push updates for Wink. The solution to the problem after a couple months was to poll the API with a different user-agent from the Home assistant user-agent. That work for a long time and still works for some users (me) but isn’t anymore. I will try to find the Wink Android user-agent real quick and get it sent over to you.

Okay that was easier than I thought.

Can you add a call before the call to get devices

pywink.set_user_agent(“Manufacturer/unknown-Android_SDK_built_for_x86 Android/4.4.2 WinkAndroid/6.9.0.65-production-debug”)

And try running that?

No luck. Same. I didn’t re-generate the token. I just used the same one from last night, but as you indicated the token should be good for a few months.

Also, I have a wink hub v1 if that is a difference.

Perhaps a robot on the wink hub side could keep it sending states to the cloud. Would need to think about this some more.

Thanks again.

Well that blows.

So I am trying to go through and see what is different in the official app calls vs what python-wink does. I noticed that there is a new header in the calls I don’t recall seeing before X-DEVICE-IDENTIFIER maybe we should try to add that? It is a random value that is sent by each platform I think. For Android it looks like e36659c47cce2843 so I don’t know if that will work.

Worth a shot. So odd that it works for a while normally and then would need a changed header.

How do you collect all the calls that the Android app makes? Using a tool like wireshark?
What are all the calls it makes?

Have you tried unsubscribing from pubnub and then re-subscribing to see if that fixes it? I am assuming now, since it seems pubnub is fine as once I run the offical app updates start coming through.

I also validated that the python script is getting back all my devices with the get_all_devices call by printing the object to the screen.