FilipDem / Domoticz-NEST-plugin

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

Python plugin error message #20

Closed jpslootmans closed 3 years ago

jpslootmans commented 3 years ago

After following all steps I get this messages in the log: 2021-03-04 17:09:38.043 Error: Python Plugin System: (Nest) 'onHeartbeat' failed 'NameError'. 2021-03-04 17:09:38.043 Error: Python Plugin System: (Nest) ----> Line 411 in '/home/pi/domoticz/plugins/GoogleNest/plugin.py', function onHeartbeat 2021-03-04 17:09:38.043 Error: Python Plugin System: (Nest) ----> Line 376 in '/home/pi/domoticz/plugins/GoogleNest/plugin.py', function onHeartbeat

My protect devices are not created in Domoticz and the log is filled with text concerning google nest (example:

Python Plugin System: (Nest) Pushing 'onHeartbeatCallback' on to queue 2021-03-04 17:19:18.198 (Nest) Processing 'onHeartbeatCallback' message 2021-03-04 17:19:18.198 Python Plugin System: (Nest) Calling message handler 'onHeartbeat'. 2021-03-04 17:19:18.200 Python Plugin System: (Nest) > {} 2021-03-04 17:19:18.200 Python Plugin System: (Nest) Local context: 2021-03-04 17:19:18.200 Python Plugin System: (Nest) ----> 'Devices' '{}' 2021-03-04 17:19:18.201 Python Plugin System: (Nest) ----> 'Domoticz' '<module 'Domoticz' (built-in)>' 2021-03-04 17:19:18.201 Python Plugin System: (Nest) ----> 'Images' '{'GoogleNest Nest Away': <Domoticz.Image object at 0xa6ca1900>, 'GoogleNest Nest Eco': <Domoticz.Image object at 0xa6ca1cc0>, 'GoogleNest Nest Heating': <Domoticz.Image object at 0xa6c5e4a0>, 'GoogleNest Nest Heating Off': <Domoticz.Image object at 0xa6cae4c0>, 'GoogleNest Nest Protect': <Domoticz.Image object at 0xa6cae480>}' 2021-03-04 17:19:18.201 Python Plugin System: (Nest) ----> 'Parameters' '{'HardwareID': 15, 'HomeFolder': '/home/pi/domoticz/plugins/GoogleNest/', 'StartupFolder': '/home/pi/domoticz/', 'UserDataFolder': '/home/pi/domoticz/', 'WebRoot': '', 'Database': '/home/pi/domoticz/domoticz.db', 'Language': 'nl', 'Version': '2.0.0', 'Author': 'Filip Demaertelaere', 'Name': 'Nest', 'Address': '', 'Port': '0', 'SerialPort': '', 'Username': '', 'Password': '', 'Key': 'GoogleNest', 'Mode1': .........................................(several pages long)

When I test outside Domoticz, as suggested at the end of the readme.md, everything seems top work OK and I can see my Nest protect devices are working ok πŸ‘ Got nest devices 5: thermostats [] - protects ['6416660000CE26B6', '6416660000CE39DE', '6416660000CE0180', '6416660000CB3216', '6416660000CB2F67'] {} {'Smoke_status': 0, 'Serial_number': '06AA01AC2719049B', 'Co_previous_peak': '0', 'Where': 'Entryway', 'Battery_low': '0', 'Battery_level': '5197'} {'Smoke_status': 0, 'Serial_number': '06AA01AC2719054L', 'Co_previous_peak': '0', 'Where': 'Upstairs', 'Battery_low': '0', 'Battery_level': '5212'} {'Smoke_status': 0, 'Serial_number': '06AA01AC151902R7', 'Co_previous_peak': '0', 'Where': 'Basement', 'Battery_low': '0', 'Battery_level': '5179'} {'Smoke_status': 0, 'Serial_number': '06AA01AC151902DZ', 'Co_previous_peak': '0', 'Where': 'Living Room', 'Battery_low': '0', 'Battery_level': '5234'} All good

FilipDem commented 3 years ago

Hi, I would anyway the full log. So perhaps you can attach it as a separate file. I would expect the reason because you don't have a NEST thermostat... Now honestly integrating it in Domoticz for only the NEST Protects won't give a lot of value. OK. You will be able to see if the alarm goes off (but I hope you will never see this :-)). If you upload the complete log, I can take a look whether I can figure out the problem...

Please also redo it outside Domoticz, however just make a small change to print all the information that is retrieved from the NEST server. This could be done by adding a line in the code as indicated below (between the .. ; don't copy the stars). I didn't test it myself so hopefully I was not too fast in my thinking...:

def GetProtectInformation(self, device_id):
    info = {}
    try:
        if self._mode == self.GETSTATUSMOBILEUSER:
            structure_id = [structure for structure in self._status['structure'].keys() if 'topaz.{}'.format(device_id) in self._status['structure'][structure]['swarm']][0]
            device = self._status['topaz'][device_id]
            wheres = {where['where_id'] : where['name'] for where in self._status['where'][structure_id]['wheres']}
        elif self._mode == self.GETSTATUSUSERBUCKETS:
            device = [bucket['value'] for bucket in self._status['updated_buckets'] if bucket['object_key'] == 'topaz.{}'.format(device_id)][0]
            structure_id = [bucket['object_key'][10:] for bucket in self._status['updated_buckets'] if (bucket['object_key'].split('.')[0] == 'structure' and 'topaz.{}'.format(device_id) in bucket['value']['swarm'])][0]
            wheres = {where['where_id'] : where['name'] for bucket in self._status['updated_buckets'] if bucket['object_key'] == 'where.{}'.format(structure_id) for where in bucket['value']['wheres']}
        **print(device)**    
        info = {
            'Smoke_status': device['smoke_status'],
            'Serial_number': str(device['serial_number']),
            'Co_previous_peak': str(device['co_previous_peak']),
            'Where': wheres[device['spoken_where_id']],
            'Battery_low': str(device['battery_health_state']),
            'Battery_level': str(device['battery_level']),
jpslootmans commented 3 years ago

@FilipDem Thanks for helping! The Nest Protects do more than just detect smoke, CO or heat, they also detect human presence and day/night. A useful implementation could be to switch on ventilation (extraction) in the room where a fire hazard is detected to evacuate smoke and to switch off extraction in the other areas to prevent smoke from being pulled in. The Nest app does not always give a warning when you are not at home, domoticz can do that. I have put the log in a separate file, included here. I hope it will be of use. Thanks in advance, JP Log_dump.txt Added the return from Nest from outside domoticz Nest_dump.txt

FilipDem commented 3 years ago

Thanks. I see that it indeed indicates a line error where the problem happens. Will look later to put. I don't remember that the Nest server gives back information about the presence. Did you saw my corrected message. Asking also to add the print instruction and do it outside Domoticz. This will give me a bien on the data returned.

Op vr 5 mrt. 2021 18:08 schreef jpslootmans notifications@github.com:

@FilipDem https://github.com/FilipDem Thanks for helping! The Nest Protects do more than just detect smoke, CO or heat, they also detect human presence and day/night. A useful implementation could be to switch on ventilation (extraction) in the room where a fire hazard is detected to evacuate smoke and to switch off extraction in the other areas to prevent smoke from being pulled in. The Nest app does not always give a warning when you are not at home, domoticz can do that. I have put the log in a separate file, included here. I hope it will be of use. Thanks in advance, JP Log_dump.txt https://github.com/FilipDem/Domoticz-NEST-plugin/files/6092063/Log_dump.txt

β€” You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/FilipDem/Domoticz-NEST-plugin/issues/20#issuecomment-791555288, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD3SGC623Y2VQTY6F2KW4GTTCEF2PANCNFSM4YTRSZ3Q .

FilipDem commented 3 years ago

Hi Jean-Pierre, The problem should be solved. Update the nest.py (and plugin.py optionally because another improvement was done here). There was a problem with one Nest Protection that the location could not be found... So you should now have one device per Nest Protect. It will be triggered in case of smoke alarm (or with the new version of the plugin.py also in case of heat and CO alarm).

About the "away"-detection... I still need to do some research... Seen I have a Nest Thermostat also, it will perhaps be difficult to test a potential solution myself and will need your help. Will let you know once ready.

Could you do a test to see if the problem with the Nest Protects is solved and give feedback?

(if happy with the support, small contributions are always welcome with the donation button in the beginning of the 'readme').

Thanks,

Filip

Filip

FilipDem commented 3 years ago

Hi Jean Pierre, Could you use once the nest.py in this comment below outside Domoticz (don't copy it yet into your Domoticz directory)? This normally should give you a status if you are at home or not... In the printed log, it prints a line "General Nest information". This line contains an "Away" attribute. If you are at home, it should be set to "False", otherwise "True". If it works, I integrate it into the plugin to create a device that shows you the "Away"-status. Filip nest.py.txt (remove the .txt extension)

jpslootmans commented 3 years ago

Hi Filip,

this what I get when I run the nest.py in a command window:

pi@RPIHomeAutomation:~/domoticz/plugins/GoogleNest $ python3 nest.py Got bearer token Got access token and user id (17223515) Got user Traceback (most recent call last): File "nest.py", line 193, in UpdateDevices return self.GetDevicesAndStatus() File "nest.py", line 315, in GetDevicesAndStatus status = self.GetStatusUserBuckets() File "nest.py", line 282, in GetStatusUserBuckets with open('../Nest_dump.txt') as json_file: FileNotFoundError: [Errno 2] No such file or directory: '../Nest_dump.txt'

Unforseen exception occured in Nest class: [Errno 2] No such file or directory: '../Nest_dump.txt'

FilipDem commented 3 years ago

Sorry, this is some debug information... Could you remove the 2 lines of code at line number 282. It should be lines with (just delete the whole line)

with open('Nest_dump.txt') as json_file:
    self._status = json.load(json_file) 

My apologize. Filip

jpslootmans commented 3 years ago

Hi Filip,

done that. Here is the response. There indeed is "Away" information at the end and probably because I am at home while doing this, it is 'false'.

Nest_dump.txt

FilipDem commented 3 years ago

OK. I will integrate this in Domoticz now and keep you informed. Not sure if it will be done this weekend, but you can count on it. Btw: after a bit of research it become clear that NEST Protects don't go online very often (to save battery). So don't know how fast it will be triggered. I am not at home this week, so I cannot test it myself. To be continued. F

FilipDem commented 3 years ago

Hi Jean Pierre, I uploaded the new plugin.py and nest.py in my Domoticz and it is working correctly. I update the version in GitHub. As my setup has a Nest Thermostat, I cannot test it in a scenario with only Nest Protects. So if you could give it a try and give feedback (to potentially close the topic)... If you are happy with my work/support, don't hesitate for a small donation.

jpslootmans commented 3 years ago

Hi Filip,

replaced the plugin.py and nest.py, restarted Domoticz and put the Nest hardware active again. The Protect devices and the 'Away' switch are created and updated regularly. Everything seems to be working OK. I only get lots of debug information in the log when updating takes place. I wanted to donate a small amount to thank you for your work, but I just cancelled my PayPal account and even when I want to use a credit card I must create a new PayPal account. So I'm struck there. Anyway, thanks again.

FilipDem commented 3 years ago

I haven't any debug information anymore at my side... So I suppose you have the "debug" option on. In the hardware settings, be sure that the "Debug" is set to "False" (and don't forget to click on the button "update"). image If you still would have debug information (which I would be amazed of, but then I forgot somewhere to remove), post the file with the debug information here and based on which info I can easily identify. Thanks you. Anyway the plugin is now also improved and other can benefit of it also. Btw: let me know if the debug disappeared so that I can close the topic. Filip

jpslootmans commented 3 years ago

Ok, missed the debug setting. Everything Ok now. You can close the topic.

FilipDem commented 3 years ago

Update the readme and now it is possible to make small contributions using your standard banking application and scan the indicated QR code.

jpslootmans commented 3 years ago

Hello Filiip,

tried to use the QR-code but get "Ongeldige QR-code" in my Payconiq app (both for 5 and 10).

Kindest regards, JP

Op vr 12 mrt. 2021 om 21:28 schreef Filip @.***>:

Update the readme and now it is possible to make small contributions using your standard banking application and scan the indicated QR code.

β€” You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/FilipDem/Domoticz-NEST-plugin/issues/20#issuecomment-797736370, or unsubscribe https://github.com/notifications/unsubscribe-auth/AF4DAIX2EMH3ER2KP4X65RLTDJ2NLANCNFSM4YTRSZ3Q .

FilipDem commented 3 years ago

Jean Pierre, It is not a Payconiq QR code, it is only possible with a standard mobile banking app... I use the European QR code that triggers a standard fund transfer ("overschrijving") in the banking app... I tried it with the KBC banking app and it works. An alternative: BE07737023961366 :-)

jpslootmans commented 3 years ago

Hello Filip,

there still is a small cosmetic problem, which I had not noticed until now. There are beautiful Nest icons available in the list, but they cannot be used for the protect devices (see screenshots). For the Protect the standard smoke detector icon is used and it can not be changed. For the "Away" switch the Nest heating icon is used. [image: Protect.jpg] [image: Protect icon.jpg]

Kindest regards, JP

Op za 13 mrt. 2021 om 16:44 schreef Filip @.***>:

Jean Pierre, It is not a Payconiq QR code, it is only possible with a standard mobile banking app... I use the European QR code that triggers a standard fund transfer ("overschrijving") in the banking app... I tried it with the KBC banking app and it works. An alternative: BE07737023961366 :-)

β€” You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/FilipDem/Domoticz-NEST-plugin/issues/20#issuecomment-798532276, or unsubscribe https://github.com/notifications/unsubscribe-auth/AF4DAITCD4RXC54OF62PSKTTDOB5PANCNFSM4YTRSZ3Q .

FilipDem commented 3 years ago

Hi Jean Pierre,

For the Nest Protect, this is a restriction of Domoticz. For some standard devices (like a smoke sensor) it is not possible to change the icon. I already searched quite some times for a solution on the internet, however without success.

For all the other Nest devices (mostly with the Nest Thermostat), I used indeed icons I made myself and available in the plugin (and thus in the icon set of Domoticz). For the Nest Away I have chosen to use the Nest icon - black if Away and put it on red if not Away... This is indeed similar to the heating icon... If you would have ideas of other icons for the Away, all suggestions are welcome. This is easy to add (most time is making the graphics).

Btw: I don't see the images in your comment...

jpslootmans commented 3 years ago

I hope you see the pictures here:

[image: afbeelding.png]

[image: afbeelding.png] JP

Op wo 17 mrt. 2021 om 15:28 schreef Jean Pierre Slootmans < @.***>:

Hello Filip,

there still is a small cosmetic problem, which I had not noticed until now. There are beautiful Nest icons available in the list, but they cannot be used for the protect devices (see screenshots). For the Protect the standard smoke detector icon is used and it can not be changed. For the "Away" switch the Nest heating icon is used. [image: Protect.jpg] [image: Protect icon.jpg]

Kindest regards, JP

Op za 13 mrt. 2021 om 16:44 schreef Filip @.***>:

Jean Pierre, It is not a Payconiq QR code, it is only possible with a standard mobile banking app... I use the European QR code that triggers a standard fund transfer ("overschrijving") in the banking app... I tried it with the KBC banking app and it works. An alternative: BE07737023961366 :-)

β€” You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/FilipDem/Domoticz-NEST-plugin/issues/20#issuecomment-798532276, or unsubscribe https://github.com/notifications/unsubscribe-auth/AF4DAITCD4RXC54OF62PSKTTDOB5PANCNFSM4YTRSZ3Q .

FilipDem commented 3 years ago

For one reason or another, I can again not see the images... Btw: do you know https://domoticz-icon.aurelien-loyer.fr/? This can be used to import images into Domoticz - Setup - More Options - Custom Icons. I am always willing to add the icons in the plugin (if they are in line with my other Nest icons), but then I need to get the images :-).

jpslootmans commented 3 years ago

Hello Filip,

the images are screenshots from my computer to show the difference between the icons available in Domoticz and the ones used in the devices. The one for away is clearly the one for the thermostat because it has 20 in the red circle. By the way, I installed a VPN to be able to connect to my pi from outside the network and I checked when the house was empty (we had to take the cat to the vet) and it still says "away" false. So I think that function is not working.

Regards, JP

Op zo 21 mrt. 2021 om 16:54 schreef Filip @.***>:

For one reason or another, I can again not see the images... Btw: do you know https://domoticz-icon.aurelien-loyer.fr/? This can be used to import images into Domoticz - Setup - More Options - Custom Icons. I am always willing to add the icons in the plugin (if they are in line with my other Nest icons), but then I need to get the images :-).

β€” You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/FilipDem/Domoticz-NEST-plugin/issues/20#issuecomment-803608889, or unsubscribe https://github.com/notifications/unsubscribe-auth/AF4DAIXJUNJ73VJR7N64CIDTEYJBPANCNFSM4YTRSZ3Q .

FilipDem commented 3 years ago

I think that the function is indeed working. At least that is what I get from the Nest servers. As already indicated previous, if your Nest Protects are battery based, there is not a regular update of the status to the Nest servers... I didn't checked it yet, however on the internet I found somewhere once a day... This is to save the battery. Seems if the Nest Protect is connected to the mains power, the update is frequently... Filip