moroen / IKEA-Tradfri-plugin

A Python plugin for Domoticz to controll IKEA Gateway
68 stars 23 forks source link

Light Switches do not work #114

Closed Bolten88 closed 3 years ago

Bolten88 commented 4 years ago

Since today the switches react very bad or not at all. But i do not see any errors in the log. When i click to turn on a light just nothing is happening. This morning i saw in the IKEA app that there were updates installed. Did this broke the plugin? Sometimes the switch turns on/off when i wait for like 30 seconds.

moroen commented 4 years ago

Small update, plugin version 0.9.8, removed observe as a monitor option, since observe hasn't been implemented yet.

Tinus016 commented 4 years ago

I really appreciate the amount of effort its taken. But after updating to 0.9.7 the plugin completely stops working. In other words, it can't even start.

2020-09-27 00:51:43.951 Error: (IKEA-Tradfri) Failed to initialize tradfri module.
2020-09-27 00:51:43.951 Error: (IKEA-Tradfri) Unable to find tradfricoap

This what happens when I try to switch af light on:

2020-09-27 00:51:53.971 Error: (IKEA-Tradfri) 'onHeartbeat' failed 'NameError':'name 'close_connection' is not defined'.
2020-09-27 00:51:53.972 Error: (IKEA-Tradfri) ----> Line 811 in '/home/pi/domoticz/plugins/IKEA-Tradfri/plugin.py', function onHeartbeat
2020-09-27 00:51:53.972 Error: (IKEA-Tradfri) ----> Line 768 in '/home/pi/domoticz/plugins/IKEA-Tradfri/plugin.py', function onHeartbeat

If i try to configure again it also comes whit the message:

pi@Domoticz:~/domoticz/plugins/IKEA-Tradfri $ python3 plugin.py config 192.168.*.* "Code"
Module 'tradfricoap' not found!

Have you updated pycoap as well?

$ pip3 install -U pycoap

Yes I did. I think I found the issue, I was stil using the coapcmd. By reading the topic on the domoticz forum and in this tread. i was in the assumption that i had to use te coapmcd, my bad.

pi@Domoticz:~/domoticz/plugins/IKEA-Tradfri $ python3 plugin.py api coapcmd
pi@Domoticz:~/domoticz/plugins/IKEA-Tradfri $ python3 plugin.py config 192.168.*.* "code"
Module 'tradfricoap' not found!
pi@Domoticz:~/domoticz/plugins/IKEA-Tradfri $ python3 plugin.py api pycoap
pi@Domoticz:~/domoticz/plugins/IKEA-Tradfri $ python3 plugin.py config 192.168.*.* "code"
pi@Domoticz:~/domoticz/plugins/IKEA-Tradfri $ python3 plugin.py list
ikea_devices:
65539: ....
moroen commented 4 years ago

Have you updated pycoap as well? $ pip3 install -U pycoap

Yes I did. I think I found the issue, I was stil using the coapcmd. By reading the topic on the domoticz forum and in this tread. i was in the assumption that i had to use te coapmcd, my bad.

Glad it worked out, but all versions of the plugin should also support coapcmd. Fixed in the latest version (0.9.9), thank you for bringing this to my attention. In fact, thanks to everyone for all the feedback and bug-reports, the plugin wouldn't be where it is without it!

mbuurman78 commented 4 years ago

After plugin update to 0.9.9 a list-command displays all the devices, so the connectivity between plugin and IKEA-Hub seems te work correctly:

pi@pi3-domoticz:~/domoticz/plugins/IKEA-Tradfri $ python3 plugin.py list ikea_devices: 65539: lamp naast de TV (State: 0 - Level: 142 - Hex: f1e0b5) 65540: Lamp op de meidenkast (State: 1 - Level: 109 - Hex: f1e0b5) 65538: lamp achter de bank (State: 0 - Level: 142 - Hex: f1e0b5) 65537: lamp op de speelgoedkast (State: 0 - Level: 145 - Hex: f1e0b5)

Others: 65536: TRADFRI remote control (State: None - Level: None - Hex: None)

Batteries: 65536: TRADFRI remote control - 47

But Domoticz doesn't want to work with it, so the connectivity between plugin and Domoticz seems to have a problem:

2020-09-27 19:51:09.776 Error: (IKEA Tradfri) Failed to initialize tradfri module. 2020-09-27 19:51:09.776 Error: (IKEA Tradfri) Unable to find tradfricoap 2020-09-27 19:51:49.801 Error: (IKEA Tradfri) ----> Line 811 in '/home/pi/domoticz/plugins/IKEA-Tradfri/plugin.py', function onHeartbeat 2020-09-27 19:51:49.801 Error: (IKEA Tradfri) ----> Line 768 in '/home/pi/domoticz/plugins/IKEA-Tradfri/plugin.py', function onHeartbeat

basrieter commented 4 years ago

Exactly the same here.

moroen commented 4 years ago

Ah, nuts!

Fix one error, introduce two others...

Mental note to self: A bit more testing before committing changes...

Try 0.9.10...

Bolten88 commented 4 years ago

Hi @moroen thanks for the hard work.

How can i switch back to the master version?

moroen commented 4 years ago

@Bolten88

$ cd IKEA-Tradfri
$ git checkout master
$ git pull
Bolten88 commented 4 years ago

@Bolten88

$ cd IKEA-Tradfri
$ git checkout master
$ git pull

Thanks, will do that later today.

mbuurman78 commented 4 years ago

Updated to version 0.9.10 and it seems to work fine with Domoticz, no more errors and the devices react as normal. We will find out next hours/days if it stays stable.

Thanks for you effort!

mbuurman78 commented 4 years ago

Not completly flawless... I've deleted an IKEA-device from the hub and added a new one. The cli list-command works fine and displays the correct devices active on the hub.

After updating the plugin in Domoticz I see errors in the Domoticz-log and the new device isn't in the Domoticz device-list:

2020-09-28 16:37:13.743 (IKEA Tradfri) Debug logging mask set to: NONE 2020-09-28 16:37:13.735 Status: (IKEA Tradfri) Stop directive received. 2020-09-28 16:37:13.735 Status: (IKEA Tradfri) Exiting work loop. 2020-09-28 16:37:13.835 Status: (IKEA Tradfri) Stopping threads. 2020-09-28 16:37:13.837 Status: (IKEA Tradfri) Stopped. 2020-09-28 16:37:13.837 Status: (IKEA Tradfri) Started. 2020-09-28 16:37:14.033 Status: (IKEA Tradfri) Entering work loop. 2020-09-28 16:37:14.033 Status: (IKEA Tradfri) Initialized version 0.9.10, author 'moroen' 2020-09-28 16:37:14.102 Error: (IKEA Tradfri) 'onStart' failed 'KeyError'. 2020-09-28 16:37:14.102 Error: (IKEA Tradfri) ----> Line 767 in '/home/pi/domoticz/plugins/IKEA-Tradfri/plugin.py', function onStart 2020-09-28 16:37:14.102 Error: (IKEA Tradfri) ----> Line 590 in '/home/pi/domoticz/plugins/IKEA-Tradfri/plugin.py', function onStart 2020-09-28 16:37:14.102 Error: (IKEA Tradfri) ----> Line 396 in '/home/pi/domoticz/plugins/IKEA-Tradfri/plugin.py', function registerDevices 2020-09-28 16:37:14.102 Error: (IKEA Tradfri) ----> Line 291 in '/home/pi/domoticz/plugins/IKEA-Tradfri/plugin.py', function indexRegisteredDevices 2020-09-28 16:37:14.102 Error: (IKEA Tradfri) ----> Line 304 in '/home/pi/domoticz/plugins/IKEA-Tradfri/plugin.py', function updateDevice

When restarting the complete Domoticz-service the plugin doesn't give any errors in the log, but the new device is still not in the device-list of Domoticz.

UPDATE: Also changes in the plugin-settings like changing the 'Polling Interval' or 'Monitor batteries' results in the same errors in the Domoticz-log

moroen commented 4 years ago

@mbuurman78

I'm unable to test this, since for some reason, I'm not able to remove a device from the gateway using the Ikea app, but I believe the just released 0.9.11 will fix this...

mbuurman78 commented 4 years ago

Updated the plugin to 0.9.11 and it look likes it fixes the issue! Thanks again.

jeroenkl commented 4 years ago

'observe port', which number should I use?

moroen commented 4 years ago

@jeroenkl

Just ignore it at the moment, observations still doesn't work, it's a leftover from the development version. I'll remove it as soon as possible...

Bolten88 commented 4 years ago

@moroen thanks again for all the effort. I'm running version 0.9.11 for a few days now and it runs stable!

Tinus016 commented 4 years ago

@moroen, I have also updated to version 0.9.11 and works fine. Sinds today also observations is working again. (timer on 300 sec port not configured.) (I've seen in my Pi-Hole log that tradfri has installed an update (it has made a connection to a server thats delivers updates) maybe this has fixed the observations but I'm not sure)

SBergers commented 4 years ago

@moroen Thanks a million.

Man, I was seriously bummed the last couple of days with the lights not working. Only one turned on. I thought it was the lights but after i deleted the not-working-one and readded it another light didnt turn on. Now, i've updated to 0.9.13 and reinstalled my py3coap in the folder IKEA-Tradfri and it seems to work again. Thank you so much Moroen, love the work you put in to this project.

Marcdek65 commented 3 years ago

Today I have the same problems:

2020-10-16 20:55:05.845 Error: (IKEA HUB) 'onCommand' failed 'KeyError'. 2020-10-16 20:55:05.845 Error: (IKEA HUB) ----> Line 792 in '/home/pi/domoticz/plugins/IKEA-Tradfri/plugin.py', function onCommand 2020-10-16 20:55:05.845 Error: (IKEA HUB) ----> Line 709 in '/home/pi/domoticz/plugins/IKEA-Tradfri/plugin.py', function onCommand

Manual or script driven does not make a difference (I noticed the problem because the room stayed dark after sunset :P)

I did an update of both the plugin and pycoap

Any ideas?

P.S. How can I check the running version of the plugin (sorry, linux noob)

moroen commented 3 years ago

@Marcdek65

Has anything changed on the gateway? Devices added or removed? New firmware version?

To check the plugin version, in the plugin directory:

$ python3 plugin.py version
Marcdek65 commented 3 years ago

@Marcdek65

Has anything changed on the gateway? Devices added or removed? New firmware version?

To check the plugin version, in the plugin directory:

$ python3 plugin.py version

No nothing has changed on the gateway as far as I know. Last firmware update was from September 10th where I also got the same problem as most where the switches no longer functioned unless 30sec apart. Your new update solved that until yesterday.

The plugin version is: IKEA Tradfri Plugin - version 0.9.13

I also updated pycoap.

Tinus016 commented 3 years ago

Maybe there has been a Firmware update. My DNS server indicates that the Hub has connected to the update server yesterday (16-10-2020 09:52 See image below) I have no problems at te moment.

Schermafbeelding 2020-10-17 om 20 21 55

Edit: I also see that the Gateway has rebooted after that, my DNS lost its connection voor about 2 minutes

Marcdek65 commented 3 years ago

Maybe there has been a Firmware update. My DNS server indicates that the Hub has connected to the update server yesterday (16-10-2020 09:52 See image below) I have no problems at te moment.

Schermafbeelding 2020-10-17 om 20 21 55

Edit: I also see that the Gateway has rebooted after that, my DNS lost its connection voor about 2 minutes

No, the last firmware update is from september 10th. Current release is 1.14.0

Marcdek65 commented 3 years ago

Nobody has the same problem? May sunset/sundown lights off/on script won't work anymore. Not a disaster but I like to come home in a lit house :)

moroen commented 3 years ago

@Marcdek65

This is an error that's difficult to diagnose, since it's because the gateway returns data that doesn't conform to the format expected by the plugin.

I've made som changes to the development version that might make this easier to fix, so if you would care to try the development branch (please check the updated readme), post the error message you get, and the output of the list command:

$ git checkout development
$ git pull
$ rm -rf tradfricoap
$ sudo -H pip3 install tradfricoap
$ python3 plugin.py list
JeroenEeuwes commented 3 years ago

I've made som changes to the development version that might make this easier to fix, so if you would care to try the development branch (please check the updated readme), post the error message you get, and the output of the list command:

I'm not Mardeck65, but I tried your commands, anyway. Now the list command will only state "py3coap not found". If I try the version command it says:

python3 plugin.py version IKEA Tradfri Plugin: 0.9.16 Tradfricoap: 0.0.10 Py3coap: 0.8.0 coapcmd: Not found (Looking for /home/pi/domoticz/plugins/IKEA-Tradfri/bin/coapcmd).

I also tried command like "sudo -H pip3 install -U tradfricoap py3coap" which ran without errors, but the error remains.

moroen commented 3 years ago

@JeroenEeuwes

You have the wrong version of py3coap, it should be 0.9.0! pip3 install -U should do the trick, but it's possible to have more than one version of a module installed. To make sure that you get the latest version, try:

$ pip3 uninstall py3coap
$ sudo -H pip3 uninstall py3coap

Then make sure that python3 plugin version reports that py3coap can't be found, and install py3coap again!

JeroenEeuwes commented 3 years ago

@moroen I see, I thought that "sudo -H pip3 install -U tradfricoap py3coap" was supposed to do that, but apparently it didn't.

I manually did an uninstall like you said an installed it again and that worked. Thanks!

moroen commented 3 years ago

@JeroenEeuwes

It should, but it's actually possible to install several versions of a module, one with pip3 install and another with sudo -H pip3 install...

So, if you use sudo when issuing pip3 install -U the one installed with sudo is updated, while the one installed with just pip3 is not, and which version the plugin actually uses depends on several factors.

There are many things to love about Python, module- and version management is not one of those...

Marcdek65 commented 3 years ago

@Marcdek65

This is an error that's difficult to diagnose, since it's because the gateway returns data that doesn't conform to the format expected by the plugin.

I've made som changes to the development version that might make this easier to fix, so if you would care to try the development branch (please check the updated readme), post the error message you get, and the output of the list command:

$ git checkout development
$ git pull
$ rm -rf tradfricoap
$ sudo -H pip3 install tradfricoap
$ python3 plugin.py list

Sorry for being the noob but the git pull command gives me a permission error. Should I sudo this?

$ git pull remote: Enumerating objects: 55, done. remote: Counting objects: 100% (55/55), done. remote: Compressing objects: 100% (31/31), done. remote: Total 48 (delta 27), reused 37 (delta 16), pack-reused 0 error: insufficient permission for adding an object to repository database .git/objects fatal: failed to write object fatal: unpack-objects failed

I believe I had these kind of errors before (not sure if it was with this plugin) so I'm used to run every command with sudo.

moroen commented 3 years ago

@Marcdek65

$ git pull remote: Enumerating objects: 55, done. remote: Counting objects: 100% (55/55), done. remote: Compressing objects: 100% (31/31), done. remote: Total 48 (delta 27), reused 37 (delta 16), pack-reused 0 error: insufficient permission for adding an object to repository database .git/objects fatal: failed to write object fatal: unpack-objects failed

I believe I had these kind of errors before (not sure if it was with this plugin) so I'm used to run every command with sudo.

You should never use sudo with git (or most other commands as well). sudo should only be used when there is a need to install or remove something from one or more system directories. As a general rule of thumb, try a command without sudo first, and if it fails with permission error, consider using sudo.

I would guess you have used sudo with git pull previously, and that's the reason for the insufficient permission error, as some of the files are then owned by the root user. Now, you could work around this by using sudo git pull, but that will not fix the root cause. You should fix the file permissions and ownership:

$ cd plugins/IKEA-Tradfri
$ sudo chown -R USERNAME .

Please note the final dot in the last command.

I know, there is a certain irony in that you need to use sudo here, but since root owns the files, only root can change the owner. After this, all the files in the IKEA-Tradfri directory is owned by your user, and can be updated with git pull without sudo.

Marcdek65 commented 3 years ago

@moroen

I changed owner and with that the git pull command worked. Thanks. With the install of the tradfricoap I got a message:

$ sudo -H pip3 install tradfricoap Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple Collecting tradfricoap Downloading https://www.piwheels.org/simple/tradfricoap/tradfricoap-0.0.11-py3-none-any.whl (13 kB) Collecting appdirs Downloading appdirs-1.4.4-py2.py3-none-any.whl (9.6 kB) Requirement already satisfied: py3coap in /usr/local/lib/python3.7/dist-packages (from tradfricoap) (0.9.0) Installing collected packages: appdirs, tradfricoap Successfully installed appdirs-1.4.4 tradfricoap-0.0.11 WARNING: You are using pip version 20.2.3; however, version 20.2.4 is available. You should consider upgrading via the '/usr/bin/python3 -m pip install --upgrade pip' command.

Should I upgrade?

I also got an error with the last command:

$ python3 plugin.py list Connection timed out

Thanks for your help. I really appreciate your time and effort.

moroen commented 3 years ago

@Marcdek65

In my opinion, it's always a good idea to update pip to the latest version. As for connection time out, the first thing to do is to try reconfiguring the gateway. Please note that the syntax has changed slightly:

$ python3 plugin.py config gw IP KEY
Marcdek65 commented 3 years ago

@Marcdek65

In my opinion, it's always a good idea to update pip to the latest version. As for connection time out, the first thing to do is to try reconfiguring the gateway. Please note that the syntax has changed slightly:

$ python3 plugin.py config gw IP KEY

Somehow the GW got a different IP address. After finding that I did the gateway reconfiguring and after that the python3 plugin.py list command showed all my lights 👍

It still does not work. New error is:

2020-10-25 21:18:46.915 Status: User: Admin initiated a switch command (14/Spot 4/Off) 2020-10-25 21:18:46.961 Error: (IKEA HUB) OnCommand failed for device: 65542 with command: Off and level: 80

I've tried several lights, intensities, colors but each show the same error.

2020-10-25 21:22:44.146 Status: User: Admin initiated a switch command (17/Grote-lamp - Kleur/Set Level) 2020-10-25 21:22:44.159 Error: (IKEA HUB) OnCommand failed for device: 65537 with command: Set Level and level: 80

moroen commented 3 years ago

@Marcdek65

I've created a debug branch, with exception handling disabled for the onCommand. Perhaps that will give some indication on what's going on.

$ git fetch origin
$ git checkout debug
Marcdek65 commented 3 years ago

git checkout debug

the first command shows no output The second shows this error:

$ git checkout debug error: pathspec 'debug' did not match any file(s) known to git

Bolten88 commented 3 years ago

As far as i can see @moroen did not publish the debug branch. At least i cannot see that branch. Knipsel

Bolten88 commented 3 years ago

@Marcdek65 make sure your IKEA gateway get's a static IP address from your DHCP server. Then it won't happen again that the gateway receives a new IP address after you reboot it.

Marcdek65 commented 3 years ago

@Marcdek65 make sure your IKEA gateway get's a static IP address from your DHCP server. Then it won't happen again that the gateway receives a new IP address after you reboot it.

@Bolten88 I checked this and it was my mistake. There was a reservation but my documentation was behind....

moroen commented 3 years ago

@Bolten88, @Marcdek65

The debug branch har been pushed to github now...

Marcdek65 commented 3 years ago

@Bolten88, @Marcdek65

The debug branch har been pushed to github now...

$ git checkout debug Branch 'debug' set up to track remote branch 'debug' from 'origin'. Switched to a new branch 'debug' $ git pull Already up to date.

Not sure if this is what was to be expected?

moroen commented 3 years ago

@Marcdek65

No, it's not...

This just isn't my day... Try again now!

Marcdek65 commented 3 years ago

@Marcdek65

No, it's not...

This just isn't my day... Try again now!

I know the feeling...

Not sure what you've changed but the plugin is working again. To be complete: After the git pull I also issued these commands:

$ rm -rf tradfricoap $ sudo -H pip3 install tradfricoap $ python3 plugin.py list

for some reason after installing pip 3 I did get the same message about my version of pip WARNING: You are using pip version 20.2.3; however, version 20.2.4 is available.

But after trying to upgrade pip it told me I was already on 20.2.4.....

I rebooted the raspberri and I can again control the lights without errors in Domoticz.

Do you need any logs or something else?

moroen commented 3 years ago

@Marcdek65

The only thing that differentiates debug from the other version, is that debug has disabled error handling for the onCommand... The development version has been merged into master, so if you would be as kind as to try changing to the latest master?

Marcdek65 commented 3 years ago

@Marcdek65

The only thing that differentiates debug from the other version, is that debug has disabled error handling for the onCommand... The development version has been merged into master, so if you would be as kind as to try changing to the latest master?

Here are the results:

$ git checkout master Switched to branch 'master' Your branch is behind 'origin/master' by 17 commits, and can be fast-forwarded. (use "git pull" to update your local branch)

$ git pull Updating 197f89d..4c8da29 Fast-forward .bumpversion.cfg | 2 +- README-PI.md | 5 +- README.md | 98 +++++++----- install_coapcmd.sh | 2 +- plugin.py | 318 +++++++++++++++++--------------------- requirements.txt | 1 + tradfricoap/init.py | 12 -- tradfricoap/cli.py | 23 --- tradfricoap/coapcmd_api.py | 156 ------------------- tradfricoap/colors.py | 95 ------------ tradfricoap/config.py | 76 ---------- tradfricoap/constants.py | 29 ---- tradfricoap/device.py | 370 --------------------------------------------- tradfricoap/device_info.py | 4 - tradfricoap/errors.py | 40 ----- tradfricoap/gateway.py | 13 -- tradfricoap/observe.py | 30 ---- tradfricoap/pycoap_api.py | 81 ---------- tradfricoap/request.py | 36 ----- 19 files changed, 210 insertions(+), 1181 deletions(-) delete mode 100644 tradfricoap/init.py delete mode 100644 tradfricoap/cli.py delete mode 100644 tradfricoap/coapcmd_api.py delete mode 100644 tradfricoap/colors.py delete mode 100644 tradfricoap/config.py delete mode 100644 tradfricoap/constants.py delete mode 100644 tradfricoap/device.py delete mode 100644 tradfricoap/device_info.py delete mode 100644 tradfricoap/errors.py delete mode 100644 tradfricoap/gateway.py delete mode 100644 tradfricoap/observe.py delete mode 100644 tradfricoap/pycoap_api.py delete mode 100644 tradfricoap/request.py

I issued no other commands nor did I do a restart of Domoticz. The lamps can be switched on/off and there are no errors in the domoticz log.

Do I need to do these?

$ rm -rf tradfricoap $ sudo -H pip3 install tradfricoap $ python3 plugin.py list

moroen commented 3 years ago

@Marcdek65

You should restart domoticz in order to activate this version. There should be no need to update tradfricoap at this time.

Marcdek65 commented 3 years ago

@Marcdek65

You should restart domoticz in order to activate this version. There should be no need to update tradfricoap at this time.

I restarted and all remains the same. So far all commands work (except I seem to have lost 'Warm White' from the color selector). Looks like the problems have been solved. I hope the lights turn on ad sundown :)

I don't understand everything that has been changed or done but I'm happy if this is the solution. Thank you so much for all your effort.

Marcdek65 commented 3 years ago

In addition. The 'sundown' script also works again but turning on the lights (5) is slow. That's not a problem but just so you know how the plugin is performing when more then one is switched on at the same time.

JeroenEeuwes commented 3 years ago

@moroen I switched back to master, did git pull and restarted Domoticz. In the Setup-Hardware page it says version 0.10.0. So I think this is OK.

However when I try to switch the light on or of in Domoticz on the Switched page nothing seems to happen. In the log I can see that Domoticz saw my mouse click (User intiated a switch command).

If I switch them on manually this does not seem to register in Domoticz either.

When I try commands on the command line like "python3 plygin.py on 131076" this works immediately! The list command shows the correct states, too.

Then I tried again and now the commands in Domoticz work right away. However, a few minutes later the were not working anymore (and the command line still worked OK).

It still seems a bit of hit&miss if it works or not.

Is there something else I can try?

moroen commented 3 years ago

@Marcdek65. The delay when switching more than one device at the time, is known and is a result of the changes I had to implement to support the latest firmware.

@JeroenEeuwes. I don't see the same behaviour. Enable debug and take a look at the log when trying to switch a device, are there any timeouts?