FilipDem / Domoticz-NEST-plugin

NEST Plugin for Domoticz using the Google credentials.
13 stars 4 forks source link

Cookie expired #10

Closed rolfie23 closed 3 years ago

rolfie23 commented 4 years ago

Hello,

Today I found out the Nest plugin logged out, there was a error in my log. Not watching there a lot, but it was already 9 days ago.

Is it possible to get a message or something when it's logged out in cause of expired cookies? I use the switched for some script so I need to have it working most of the time.

FilipDem commented 4 years ago

Hi, I configured Domoticz that I got automatically an email if an error was generated. In the Settings - email, you can activate "send errors as notifications". Very effective... Then you got a mail when this error comes up. Thanks, Filip

rolfie23 commented 4 years ago

Hello,

Thanks for the reply. That's the problem, I've got a lot of errors in the log which I can't get off.... Tried a lots of times already.

Multiple messages a day, are here unwanted. Is there a way I can filter that to your plugin and send an massage?

FilipDem commented 4 years ago

Thanks for the explanation.

First of all, it seems not normal that so much errors are generated in normal working conditions... Normally this should be exceptional. I have about 15 different plugins and about 100 devices and don't have this problem.

I hope that you understand that I cannot predict until when the credentials will remain valid. It stays a workaround and hope NEST will deliver a formal API this year (they announced end of year).

I looked a bit and a plugin has no direct access to the notification system. It seems only possible through http requests, which makes it a bit complex and not clean. However if this would be the only solution I can look later. But you understand that I prefer to avoid.

What you could do as a solution is creating a small script that checks if the device timed out. Normally I time out the device if credentials are no longer valid. I will check if I published it already on GitHub. A script (like lua) has direct access to the notifications. Don't know if "blocky" scripting has a trigger on the timeout state.

Filip

Op ma 22 jun. 2020 11:43 schreef rolfie23 notifications@github.com:

Hello,

Thanks for the reply. That's the problem, I've got a lot of errors in the log which I can't get off.... Tried a lots of times already.

Multiple messages a day, are here unwanted. Is there a way I can filter that to your plugin and send an massage?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/FilipDem/Domoticz-NEST-plugin/issues/10#issuecomment-647407462, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD3SGC6FDFNXIU7VGQBIM6DRX4RVVANCNFSM4OEBL7UQ .

FilipDem commented 4 years ago

Just looked that I didn't have uploaded the most recent plugin to GitHub. Will do it later today. The new version will timeout the devices if the credentials are expired. Don't forget to reboot after having updated the file!

rolfie23 commented 4 years ago

Hello Filip,

I know the errors, but they are off Domoticz. Also have an lot of plugins and devices, but if I search for the errors you read a lot about them. (Http error, checkauthtoken etc.) Only one of the buienradar plugin which I didn't investigate yet.

The new version wil update the sensors ever time it checks? Than I can use last update as notification. Now if there is no change on the sensor it doesn't update. Now in the summer it means my heating has an old last update date.

FilipDem commented 4 years ago

This is indeed changed with the new version. Even if there is no update to do, I update the "last seen" with the current time if there is still a link with the NEST devices. If the link is broken because of expired credentials, the device will timeout (so in red). This is all included in the latest version I uploaded about an hour ago. Kr, Filip

Op ma 22 jun. 2020 om 16:41 schreef rolfie23 notifications@github.com:

Hello Filip,

I know the errors, but they are off Domoticz. Also have an lot of plugins and devices, but if I search for the errors you read a lot about them. (Http error, checkauthtoken etc.) Only one of the buienradar plugin which I didn't investigate yet.

The new version wil update the sensors ever time it checks? Than I can use last update as notification. Now if there is no change on the sensor it doesn't update. Now in the summer it means my heating has an old last update date.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/FilipDem/Domoticz-NEST-plugin/issues/10#issuecomment-647561762, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD3SGC4MMIZUDKRJLURJJ4TRX5UQVANCNFSM4OEBL7UQ .

rolfie23 commented 4 years ago

Great! Will try when I have time!

rolfie23 commented 4 years ago

Hmmm, after the update it's not working as aspected.

Last update gets every minute an update, but when I put een notification on last update on example the thermostat after 120min I get the message after 120 min, but the date updates. When I don't reload the page the old date will stay and it doesn't update. It seems like it needs an page refresh to have it updated.

Also I had 2 errors in my log: 2020-06-23 08:46:46.445 Error: (Nest) PyDomoticz_Error failed to parse parameters: string expected. 2020-06-23 08:46:46.445 Error: (Nest) 'PyDomoticz_Error' failed 'TypeError':'argument 1 must be str, not None'.

FilipDem commented 4 years ago

I am running the plugin since some weeks now without any problem. However this night I got the same error (but only once). So I will monitor if it is exceptional or not... Anyway I don't know yet where the error is coming from.

Op di 23 jun. 2020 08:57 schreef rolfie23 notifications@github.com:

Hmmm, after the update it's not working as aspected.

Last update gets every minute an update, but when I put een notification on last update on example the thermostat after 120min I get the message after 120 min, but the date updates.

Also I had 2 errors in my log: 2020-06-23 08:46:46.445 Error: (Nest) PyDomoticz_Error failed to parse parameters: string expected. 2020-06-23 08:46:46.445 Error: (Nest) 'PyDomoticz_Error' failed 'TypeError':'argument 1 must be str, not None'.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/FilipDem/Domoticz-NEST-plugin/issues/10#issuecomment-647948791, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD3SGC3A5M7BWAFWQNFLXK3RYBG65ANCNFSM4OEBL7UQ .

rolfie23 commented 4 years ago

Did get another error: 2020-06-23 12:48:36.110 Error: (Nest) PyDomoticz_Error failed to parse parameters: string expected. 2020-06-23 12:48:36.110 Error: (Nest) 'PyDomoticz_Error' failed 'TypeError':'argument 1 must be str, not None'

But the Last Update doesn't work well. In the GUI you need to refresh to see the new date, not as usual it changes when received. This results in only an update when state changes so a message if last update is longer than 120 minutes a go doesn't work.

FilipDem commented 4 years ago

The refresh is is only for the visualisation. It is linked to Domotica itself and the caching. Nothing to do with the plugin. If you request the info by script, you will get the right info.

I got indeed now the same error about once every day/2 days. Strange while I am running this version of the plugin since weeks... Will need to debug to know where it comes from...

Filip

Op wo 24 jun. 2020 10:00 schreef rolfie23 notifications@github.com:

Did get another error: 2020-06-23 12:48:36.110 Error: (Nest) PyDomoticz_Error failed to parse parameters: string expected. 2020-06-23 12:48:36.110 Error: (Nest) 'PyDomoticz_Error' failed 'TypeError':'argument 1 must be str, not None'

But the Last Update doesn't work well. In the GUI you need to refresh to see the new date, not as usual it changes when received. This results in only an update when state changes so a message if last update is longer than 120 minutes a go doesn't work.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/FilipDem/Domoticz-NEST-plugin/issues/10#issuecomment-648662371, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD3SGC6HPGNWDBANCPXUKQ3RYGXAXANCNFSM4OEBL7UQ .

FilipDem commented 4 years ago

Looked a bit around and seem I am not the only one... In a post [(https://github.com/DaanJJansen/domoticz-spotify/issues/3)]() this error was reported also coming up since July 19th , but solved by updating Domoticz. Cannot 100% believe we have the same problem as I didn't update Domoticz neither since a while (I am using the build version 2020-06-08 07:21:49)... And as indicated earlier I got from time to time also the error (3 times in about 4 days so far)... I added some debug information at my site to see where the problem could be located. Seen the problem does not occur often, it could take a bit of time to find the root cause (code reading didn't gave me an indication). Sorry for this...

FilipDem commented 4 years ago

Hi, just to keep you informed... I have a track towards a possible problem. It would be indeed a bug in the code, however strange I haven't received it before seen I already use this version since weeks... Once I am sure about the problem and solution, I let you know.

rolfie23 commented 4 years ago

Great!!

But also with an script the last update doesn't work... It still gives messages of device offline while the plugin still works.

FilipDem commented 4 years ago

Could indeed be this... Will try to debug tomorrow. Sorry for the inconvenience.

Op ma 29 jun. 2020 21:47 schreef rolfie23 notifications@github.com:

Great!!

But also with an script the last update doesn't work... It still gives messages of device offline while the plugin still works.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/FilipDem/Domoticz-NEST-plugin/issues/10#issuecomment-651322609, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD3SGC7JYEDK4DGH43G53DLRZDVU5ANCNFSM4OEBL7UQ .

FilipDem commented 4 years ago

The problem was identified: some functions in the nest.py returned an error without giving error information back to the Domoticz plugin. Printing the error gave then indeed "(Nest) PyDomoticz_Error failed to parse parameters: string expected". I increased the error handling and now all errors should be captured to avoid this error. However: the root cause of the problem (somewhere an error should occur when updating the nest status) is not yet found. The extended error code will help me now to identify this root cause. I installed it already on my Domoticz... Let's see... If you want to run it also, it will be welcome (and perhaps I have the error feedback earlier).

rolfie23 commented 4 years ago

Don't know if it's easy to do, but if it helps you....

FilipDem commented 4 years ago

Hi, So far all goes well at my side... No new special errors received. Except one real that the credentials were expired... So I suppose that the problem is solved. Will wait to close after your feedback. I will certainly continue monitoring in detail during the weekend. Filip

Op wo 1 jul. 2020 om 16:31 schreef rolfie23 notifications@github.com:

Don't know if it's easy to do, but if it helps you....

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/FilipDem/Domoticz-NEST-plugin/issues/10#issuecomment-652454010, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD3SGC3MRBVNDHBVE3LOWFDRZNCEPANCNFSM4OEBL7UQ .

rolfie23 commented 4 years ago

So the code uploaded 3 days a go is the new version? Didn't know you put it there online. Will try!

FilipDem commented 4 years ago

Yes I did.

Op vr 3 jul. 2020 11:24 schreef rolfie23 notifications@github.com:

So the code uploaded 3 days a go is the new version? Didn't know you put it there online. Will try!

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/FilipDem/Domoticz-NEST-plugin/issues/10#issuecomment-653447690, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD3SGCZDBHFW7MFFDQ5PB7LRZWPT5ANCNFSM4OEBL7UQ .

rolfie23 commented 4 years ago

Okay, it's running here! Will see!

rolfie23 commented 4 years ago

Till now no errors, but still the date one the GUI updates every interval (after refresh page) but when a script runs on checking when last update was, is still get the last date of transmitted data.

FilipDem commented 4 years ago

This has nothing to do with the plugin, but rather with Domoticz. I did a test myself and there is indeed a difference. In the browser I got (2020-07-04 13:04:12): Browser As expected and due to refresh of browser and caching... No worry reloading the browser solves the problem.

However if I look in the Devices, I got the following (2020-07-04 18:01:58), which seems normal because the column is named "Last Seen". image When I reload the browser (refresh), I got the same information (2020-07-04 18:01:58)...

So far so good.

I made a small script with print(otherdevices_lastupdate['Nest - Living Room Heating']) and got indeed another information (2020-07-02 14:24:09)

2020-07-04 18:03:00.195 Status: LUA: 2020-07-02 14:24:09
2020-07-04 18:04:00.206 Status: LUA: 2020-07-02 14:24:09
2020-07-04 18:05:00.217 Status: LUA: 2020-07-02 14:24:09

This means that the LUA script really takes the "last update" (when a change was done). This corresponds with what I found on the internet. After browsing a bit, I understood that it would only be possible with a API/JSON call... I tested it and indeed it works. If you use http://_YYY_/json.htm?type=devices&rid=_XXX_, you got the information back. The field "LastUpdate" is here really the "LastSeen". I tested it and the result is indeed as below (the slight difference in time is because I did the test slightly later). Of course this means that you will need to do the API call in your script. Normally this is not a big deal and should be easy. { "ActTime" : 1593879951, "AstrTwilightEnd" : "00:00", "AstrTwilightStart" : "00:00", "CivTwilightEnd" : "22:46", "CivTwilightStart" : "04:52", "DayLength" : "16:23", "NautTwilightEnd" : "23:54", "NautTwilightStart" : "03:45", "ServerTime" : "2020-07-04 18:25:51", "SunAtSouth" : "13:49", "Sunrise" : "05:38", "Sunset" : "22:01", "app_version" : "2020.2 (build 12130)", "result" : [ { "AddjMulti" : 1.0, "AddjMulti2" : 1.0, "AddjValue" : 0.0, "AddjValue2" : 0.0, "BatteryLevel" : 255, "CustomImage" : 150, "Data" : "Off", "Description" : "", "DimmerType" : "none", "Favorite" : 1, "HardwareID" : 31, "HardwareName" : "Nest", "HardwareType" : "Nest Thermostat/Protect Google", "HardwareTypeVal" : 94, "HaveDimmer" : true, "HaveGroupCmd" : true, "HaveTimeout" : false, "ID" : "001F0001", "Image" : "GoogleNest Nest Heating", "IsSubDevice" : false, "LastUpdate" : "2020-07-04 18:24:28", "Level" : 0, "LevelInt" : 0, "MaxDimLevel" : 100, "Name" : "Nest - Living Room Heating", "Notifications" : "false", "PlanID" : "4", "PlanIDs" : [ 4 ], "Protected" : false, "ShowNotifications" : true, "SignalLevel" : "-", "Status" : "Off", "StrParam1" : "", "StrParam2" : "", "SubType" : "Switch", "SwitchType" : "On/Off", "SwitchTypeVal" : 0, "Timers" : "false", "Type" : "Light/Switch", "TypeImg" : "lightbulb", "Unit" : 1, "Used" : 1, "UsedByCamera" : false, "XOffset" : "275", "YOffset" : "263", "idx" : "581" } ], "status" : "OK", "title" : "Devices" }

FilipDem commented 4 years ago

Hi, In the meantime I have discovered a small error. Once the devices are in "timeout" (eg because of expired cookie), they don't come back with manual restart of the plugin (or reboot). To solve this, one line of code changed, however I added also some extra debug information if something goes wrong (http status code are included in the error messages). I uploaded you change already. Just wanted to inform you... Still running at my side to see if all goes well on the long term.

You also saw my previous message how to recover the "last seen" in a script?

rolfie23 commented 4 years ago

Hello Filip, Yes I saw it. But because of no time didn't look at it. My scripting is worse, but will look at it when I have time! Now I deed I use the otherdevices lastupdate. How to implent the API call I need to investigate at my site. Will take a time. Don't know when I have it. Wil add your code also when have time!

Thanks for al the help!

rolfie23 commented 3 years ago

Will close this issue, cant get good message of offline device. or user logged out, my log is full of errors and cant get ridd of them. Plugin is working, only when user is logged out, the last seen date is also still updated. The script didn't gett to work for a notice.