[REQUEST] Ikea Trådfri Gateway (smart lights hub controller) plugin?

Python and python framework

Moderator: leecollings

espenf
Posts: 9
Joined: Tuesday 01 September 2015 21:21
Target OS: -
Domoticz version:
Contact:

Re: [REQUEST] Ikea Trådfri Gateway (smart lights hub controller) plugin?

Post by espenf »

Hi!

I've recently reinstalled my domoticz-system (sd-failure..), and i'm setting up this plugin on the new system, but i'm getting this message:
(IKEA Gateway) Failed to connect to IKEA tradfri COAP-adapter! Status: 111 Description: Connection refused

I guess that is has something to do with the PSK?
How can I get the plugin to "coap" with me again? :roll:

Great plugin, by the way!
moroen
Posts: 408
Joined: Sunday 15 January 2017 11:06
Target OS: Linux
Domoticz version: beta
Location: Norway
Contact:

Re: [REQUEST] Ikea Trådfri Gateway (smart lights hub controller) plugin?

Post by moroen »

espenf wrote: Monday 21 January 2019 20:29 Hi!

I've recently reinstalled my domoticz-system (sd-failure..), and i'm setting up this plugin on the new system, but i'm getting this message:
(IKEA Gateway) Failed to connect to IKEA tradfri COAP-adapter! Status: 111 Description: Connection refused

I guess that is has something to do with the PSK?
How can I get the plugin to "coap" with me again? :roll:

Great plugin, by the way!
Have you used configure.py to create a new ident/psk-pair? If the configure.py fails, ./configure.py --debug and post the output here!

Regards,
M
espenf
Posts: 9
Joined: Tuesday 01 September 2015 21:21
Target OS: -
Domoticz version:
Contact:

Re: [REQUEST] Ikea Trådfri Gateway (smart lights hub controller) plugin?

Post by espenf »

moroen wrote: Monday 21 January 2019 21:18 Have you used configure.py to create a new ident/psk-pair? If the configure.py fails, ./configure.py --debug and post the output here!

Regards,
M
It just says "Config created!" when I create the ident, and "Error: IP and KEY required!" if I try the debug option..
I've read somewhere that the key cannot be created twice, so maybe thats the case?
moroen
Posts: 408
Joined: Sunday 15 January 2017 11:06
Target OS: Linux
Domoticz version: beta
Location: Norway
Contact:

Re: [REQUEST] Ikea Trådfri Gateway (smart lights hub controller) plugin?

Post by moroen »

espenf wrote: Monday 21 January 2019 22:29
moroen wrote: Monday 21 January 2019 21:18 Have you used configure.py to create a new ident/psk-pair? If the configure.py fails, ./configure.py --debug and post the output here!

Regards,
M
It just says "Config created!" when I create the ident, and "Error: IP and KEY required!" if I try the debug option..
I've read somewhere that the key cannot be created twice, so maybe thats the case?
The configure.py script generates a unique ident/psk-pair every time, as it's not possible to generate a new PSK for an existing ident. If it says "Config created", you should have a ident/psk pair that works. To make sure, check the contents of "config.json"-file, rerun configure.py and make sure the ident and psk has changed. If it has, communication with the gateway is working. Then the next step is to run the adapter from the command line and start the plugin from domoticz. If it still fails, post the output of the adapter here.

Code: Select all

$ python3 tradfri.tac
Regards,
M
espenf
Posts: 9
Joined: Tuesday 01 September 2015 21:21
Target OS: -
Domoticz version:
Contact:

Re: [REQUEST] Ikea Trådfri Gateway (smart lights hub controller) plugin?

Post by espenf »

moroen wrote: Tuesday 22 January 2019 1:21
espenf wrote: Monday 21 January 2019 22:29
moroen wrote: Monday 21 January 2019 21:18 Have you used configure.py to create a new ident/psk-pair? If the configure.py fails, ./configure.py --debug and post the output here!

Regards,
M
It just says "Config created!" when I create the ident, and "Error: IP and KEY required!" if I try the debug option..
I've read somewhere that the key cannot be created twice, so maybe thats the case?
The configure.py script generates a unique ident/psk-pair every time, as it's not possible to generate a new PSK for an existing ident. If it says "Config created", you should have a ident/psk pair that works. To make sure, check the contents of "config.json"-file, rerun configure.py and make sure the ident and psk has changed. If it has, communication with the gateway is working. Then the next step is to run the adapter from the command line and start the plugin from domoticz. If it still fails, post the output of the adapter here.

Code: Select all

$ python3 tradfri.tac
Regards,
M
Ahh, finally got it working! Actually, the config was fine. I had to switch to localhost-ip and not the gw's ip in domoticz :roll:
It actually worked with the gw-ip before a power outage took my SD-card tho, so i didn't think of that before now.. :shock:

Takk så mye :)

ps. any tricks to restart the gw every now and then? It seems to freeze after a while..
moroen
Posts: 408
Joined: Sunday 15 January 2017 11:06
Target OS: Linux
Domoticz version: beta
Location: Norway
Contact:

Re: [REQUEST] Ikea Trådfri Gateway (smart lights hub controller) plugin?

Post by moroen »

espenf wrote: Tuesday 22 January 2019 21:43
moroen wrote: Tuesday 22 January 2019 1:21
espenf wrote: Monday 21 January 2019 22:29

It just says "Config created!" when I create the ident, and "Error: IP and KEY required!" if I try the debug option..
I've read somewhere that the key cannot be created twice, so maybe thats the case?
The configure.py script generates a unique ident/psk-pair every time, as it's not possible to generate a new PSK for an existing ident. If it says "Config created", you should have a ident/psk pair that works. To make sure, check the contents of "config.json"-file, rerun configure.py and make sure the ident and psk has changed. If it has, communication with the gateway is working. Then the next step is to run the adapter from the command line and start the plugin from domoticz. If it still fails, post the output of the adapter here.

Code: Select all

$ python3 tradfri.tac
Regards,
M
Ahh, finally got it working! Actually, the config was fine. I had to switch to localhost-ip and not the gw's ip in domoticz :roll:
It actually worked with the gw-ip before a power outage took my SD-card tho, so i didn't think of that before now.. :shock:

Takk så mye :)

ps. any tricks to restart the gw every now and then? It seems to freeze after a while..
Glad it worked out, I would guess you had an older version of the plugin on the previous installation?

As to the GW freezing, polling for changes with to small an interval is known to freeze the GW. Some users have reported that using intervals of 300 or greater makes the GW stable.

Regards,
M
kajam
Posts: 6
Joined: Wednesday 23 January 2019 19:39
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [REQUEST] Ikea Trådfri Gateway (smart lights hub controller) plugin?

Post by kajam »

Hi.
I have followed the guide on installing support for the IKEA gateway posted by DiSrUpTeR. Everything seems to work until I reach this point:

pi@raspberrypi:~/domoticz/plugins/IKEA-Tradfri $ ./configure.py --debug 192.168.0.110 ***-**-***
Traceback (most recent call last):
File "./configure.py", line 43, in <module>
psk = api_factory.generate_psk(args.key)
File "/home/pi/.local/lib/python3.5/site-packages/pytradfri/api/libcoap_api.py", line 164, in generate_psk
self._psk = self.request(Gateway().generate_psk(existing_psk_id))
File "/home/pi/.local/lib/python3.5/site-packages/pytradfri/api/libcoap_api.py", line 96, in request
return self._execute(api_commands, timeout=timeout)
File "/home/pi/.local/lib/python3.5/site-packages/pytradfri/api/libcoap_api.py", line 85, in _execute
raise RequestTimeout() from None
pytradfri.error.RequestTimeout

Any clue to what is wrong?

Regards MJ
moroen
Posts: 408
Joined: Sunday 15 January 2017 11:06
Target OS: Linux
Domoticz version: beta
Location: Norway
Contact:

Re: [REQUEST] Ikea Trådfri Gateway (smart lights hub controller) plugin?

Post by moroen »

kajam wrote: Wednesday 23 January 2019 20:01 Hi.
I have followed the guide on installing support for the IKEA gateway posted by DiSrUpTeR. Everything seems to work until I reach this point:

pi@raspberrypi:~/domoticz/plugins/IKEA-Tradfri $ ./configure.py --debug 192.168.0.110 ***-**-***
Traceback (most recent call last):
File "./configure.py", line 43, in <module>
psk = api_factory.generate_psk(args.key)
File "/home/pi/.local/lib/python3.5/site-packages/pytradfri/api/libcoap_api.py", line 164, in generate_psk
self._psk = self.request(Gateway().generate_psk(existing_psk_id))
File "/home/pi/.local/lib/python3.5/site-packages/pytradfri/api/libcoap_api.py", line 96, in request
return self._execute(api_commands, timeout=timeout)
File "/home/pi/.local/lib/python3.5/site-packages/pytradfri/api/libcoap_api.py", line 85, in _execute
raise RequestTimeout() from None
pytradfri.error.RequestTimeout

Any clue to what is wrong?

Regards MJ
The coap-client can't communicate with the gateway. The most common reason is wrong IP-address or key...

Regards,
M
kajam
Posts: 6
Joined: Wednesday 23 January 2019 19:39
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [REQUEST] Ikea Trådfri Gateway (smart lights hub controller) plugin?

Post by kajam »

moroen wrote: Wednesday 23 January 2019 20:26
kajam wrote: Wednesday 23 January 2019 20:01 Hi.
I have followed the guide on installing support for the IKEA gateway posted by DiSrUpTeR. Everything seems to work until I reach this point:

pi@raspberrypi:~/domoticz/plugins/IKEA-Tradfri $ ./configure.py --debug 192.168.0.110 ***-**-***
Traceback (most recent call last):
File "./configure.py", line 43, in <module>
psk = api_factory.generate_psk(args.key)
File "/home/pi/.local/lib/python3.5/site-packages/pytradfri/api/libcoap_api.py", line 164, in generate_psk
self._psk = self.request(Gateway().generate_psk(existing_psk_id))
File "/home/pi/.local/lib/python3.5/site-packages/pytradfri/api/libcoap_api.py", line 96, in request
return self._execute(api_commands, timeout=timeout)
File "/home/pi/.local/lib/python3.5/site-packages/pytradfri/api/libcoap_api.py", line 85, in _execute
raise RequestTimeout() from None
pytradfri.error.RequestTimeout

Any clue to what is wrong?

Regards MJ
The coap-client can't communicate with the gateway. The most common reason is wrong IP-address or key...

Regards,
M
A typing error in the key..

One step further, Now it stops on this step:

pi@raspberrypi:~/domoticz/plugins/IKEA-Tradfri $ python3 tradfri.tac
IKEA-tradfri COAP-adaptor version 0.8.7 started (command line)!

Nothing more...

Regards MJ
moroen
Posts: 408
Joined: Sunday 15 January 2017 11:06
Target OS: Linux
Domoticz version: beta
Location: Norway
Contact:

Re: [REQUEST] Ikea Trådfri Gateway (smart lights hub controller) plugin?

Post by moroen »

kajam wrote: Wednesday 23 January 2019 21:26
moroen wrote: Wednesday 23 January 2019 20:26
kajam wrote: Wednesday 23 January 2019 20:01 Hi.
I have followed the guide on installing support for the IKEA gateway posted by DiSrUpTeR. Everything seems to work until I reach this point:

pi@raspberrypi:~/domoticz/plugins/IKEA-Tradfri $ ./configure.py --debug 192.168.0.110 ***-**-***
Traceback (most recent call last):
File "./configure.py", line 43, in <module>
psk = api_factory.generate_psk(args.key)
File "/home/pi/.local/lib/python3.5/site-packages/pytradfri/api/libcoap_api.py", line 164, in generate_psk
self._psk = self.request(Gateway().generate_psk(existing_psk_id))
File "/home/pi/.local/lib/python3.5/site-packages/pytradfri/api/libcoap_api.py", line 96, in request
return self._execute(api_commands, timeout=timeout)
File "/home/pi/.local/lib/python3.5/site-packages/pytradfri/api/libcoap_api.py", line 85, in _execute
raise RequestTimeout() from None
pytradfri.error.RequestTimeout

Any clue to what is wrong?

Regards MJ
The coap-client can't communicate with the gateway. The most common reason is wrong IP-address or key...

Regards,
M
A typing error in the key..

One step further, Now it stops on this step:

pi@raspberrypi:~/domoticz/plugins/IKEA-Tradfri $ python3 tradfri.tac
IKEA-tradfri COAP-adaptor version 0.8.7 started (command line)!

Nothing more...

Regards MJ
The adapter waits for the connection from the plugin, any errors in the domoticz log?

Regards,
M
kajam
Posts: 6
Joined: Wednesday 23 January 2019 19:39
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [REQUEST] Ikea Trådfri Gateway (smart lights hub controller) plugin?

Post by kajam »

moroen wrote: Wednesday 23 January 2019 21:48
kajam wrote: Wednesday 23 January 2019 21:26
moroen wrote: Wednesday 23 January 2019 20:26

The coap-client can't communicate with the gateway. The most common reason is wrong IP-address or key...

Regards,
M
A typing error in the key..

One step further, Now it stops on this step:

pi@raspberrypi:~/domoticz/plugins/IKEA-Tradfri $ python3 tradfri.tac
IKEA-tradfri COAP-adaptor version 0.8.7 started (command line)!

Nothing more...

Regards MJ
The adapter waits for the connection from the plugin, any errors in the domoticz log?

Regards,
M
I have enabled logging in domoticz. But I don't get any messages regarding the IKEA-plugin. Since I am only on step 13 in the installation guide I thought that the connection with domoticz wasn't enabled yet?

Regards

MJ
kajam
Posts: 6
Joined: Wednesday 23 January 2019 19:39
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [REQUEST] Ikea Trådfri Gateway (smart lights hub controller) plugin?

Post by kajam »

DiSrUpTeR wrote: Wednesday 09 January 2019 23:03 Hi,

thanx all for the info in this tread.
did a new fresh install, with some problems regarding the ./configure.py <ip> <key> part.
but in the end got it to work.made some notes and did again a new/fresh install on an other pi, and made some changes
to the list of commands form Thijs.
this way it worked second time without any errors.

SD Card preparation:
1. Flash SD with Raspbian Lite
2. Start up with screen and keyboard and login.
On terminal:
raspi-config
Set wifi, date, country, timezone, keyboard, enable ssh / serial / spi , reset password

reboot and login

1. sudo apt-get update
2. sudo apt-get upgrade
2.1 cd /etc
2.2 ls check for pythonX.X folder (should be python2.7)
2.3 sudo apt-get remove python2.7 (just to be sure)
3. sudo apt-get install python3-pip autoconf libtool
3.1 sudo reboot
4. curl –L install.domoticz.com | sudo bash
5. cd /home/pi/domoticz/plugins
6. git clone https://github.com/moroen/IKEA-Tradfri-plugin.git IKEA-Tradfri
7. cd IKEA-Tradfri
8. bash ./install-coap-client.sh
9. pip3 install pytradfri
10. sudo pip3 install twisted
11. pip3 install service-identity
11. sudo reboot
12. ./configure.py --debug <IP adres tradfri hub> <security KEY on rear of hub>
13. python3 tradfri.tac
14. ./configure.py –-skip-config –-create-service
15. sudo cp ikea-tradfri.service /etc/systemd/system
16. sudo systemctl daemon-reload
17. sudo systemctl start ikea-tradfri.service
18. sudo systemctl enable ikea-tradfri.service
19. Sudo reboot
20. Add ikea tradfri in hardware
20.1 toggle: Observe changes to yes

hope it can help someone...
thanx for the help

regards
Mark
Thanks for the instructive guide. Unfortunately I haven't managed to get through all the steps yet but so far I have found two places where the guide didn't work for me:

I had to write like this
4. sudo curl –L install.domoticz.com | bash

This might be trivial, but I also needed this
11.1
cd /domoticz/plugins/IKEA-Tradfri

Regards

MJ
MarcoRietveld
Posts: 3
Joined: Thursday 24 January 2019 9:06
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10343
Location: Netherlands
Contact:

Re: [REQUEST] Ikea Trådfri Gateway (smart lights hub controller) plugin?

Post by MarcoRietveld »

Moroen,

Thank you for this great plugin. I was able to get the PSK, but did a few other things wrong, and decided to do a fresh installation of Domoticz and also started over with the IKEA plugin. But it appears I can only generate 1 time the PSK, so I am stuck at ./configure.py <IP adres tradfri hub> <security KEY on rear of hub>.
I do have the generated PSK saved in my notes, but how can I skip this step or regenerate a new one?

Many thanks in advance.

Marco
kajam
Posts: 6
Joined: Wednesday 23 January 2019 19:39
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [REQUEST] Ikea Trådfri Gateway (smart lights hub controller) plugin?

Post by kajam »

kajam wrote: Thursday 24 January 2019 8:04
moroen wrote: Wednesday 23 January 2019 21:48
kajam wrote: Wednesday 23 January 2019 21:26

A typing error in the key..

One step further, Now it stops on this step:

pi@raspberrypi:~/domoticz/plugins/IKEA-Tradfri $ python3 tradfri.tac
IKEA-tradfri COAP-adaptor version 0.8.7 started (command line)!

Nothing more...

Regards MJ
The adapter waits for the connection from the plugin, any errors in the domoticz log?

Regards,
M
I have enabled logging in domoticz. But I don't get any messages regarding the IKEA-plugin. Since I am only on step 13 in the installation guide I thought that the connection with domoticz wasn't enabled yet?

Regards

MJ
I completely misunderstood the line "python3 tradfri.tac". It just started the COAP-adaptor. If I go to Domoticz I am able to add the IKEA-gateway and control the lights. So far so good (as far as tradfri.tac is running)

The next step is to run it as a service, this is the output when trying to generate the "ikea-tradfri.service" file.

pi@raspberrypi:~/domoticz/plugins/IKEA-Tradfri $ ./configure.py –-skip-config –-create-service
Error: Failed to generate ID/PSK-pair.
Check that the IP and Master Key is correct.

Regards

MJ
kajam
Posts: 6
Joined: Wednesday 23 January 2019 19:39
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [REQUEST] Ikea Trådfri Gateway (smart lights hub controller) plugin?

Post by kajam »

kajam wrote: Thursday 24 January 2019 11:12
kajam wrote: Thursday 24 January 2019 8:04
moroen wrote: Wednesday 23 January 2019 21:48
The adapter waits for the connection from the plugin, any errors in the domoticz log?

Regards,
M
I have enabled logging in domoticz. But I don't get any messages regarding the IKEA-plugin. Since I am only on step 13 in the installation guide I thought that the connection with domoticz wasn't enabled yet?

Regards

MJ
I completely misunderstood the line "python3 tradfri.tac". It just started the COAP-adaptor. If I go to Domoticz I am able to add the IKEA-gateway and control the lights. So far so good (as far as tradfri.tac is running)

The next step is to run it as a service, this is the output when trying to generate the "ikea-tradfri.service" file.

pi@raspberrypi:~/domoticz/plugins/IKEA-Tradfri $ ./configure.py –-skip-config –-create-service
Error: Failed to generate ID/PSK-pair.
Check that the IP and Master Key is correct.

Regards

MJ
Solved!!
Just created ikea-tradfri.service manually. Then everything worked.

MJ
DiSrUpTeR
Posts: 3
Joined: Tuesday 16 October 2018 17:51
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.7900
Location: Netherlands
Contact:

Re: [REQUEST] Ikea Trådfri Gateway (smart lights hub controller) plugin?

Post by DiSrUpTeR »

Update

tips and tricks
Check your current location when you use a "cd" command that you are in the right location.
Linux is capital senitive example: curl -l will not work, curl -L does, sudo works Sudo doesn't, same with folders
Use sudo only when it is in the command, otherwise you'll get problems with file rights later, and you will get errors
In Putty press right mouse button to paste command in shell
In a Raspbian terminal window use shift+ctrl+v to paste command

SD Card preparation:
1. Flash SD with Raspbian Lite
2. Start up with a monitor / screen and keyboard and login.
On terminal:
raspi-config
Set wifi, date, country, timezone, keyboard, enable ssh / serial / spi , reset password

reboot and login

1. sudo apt-get update
2. sudo apt-get upgrade
3. cd /etc
4. ls
/// check for pythonX.X folder (should be python2.7)
5. sudo apt-get remove python2.7
/// just to be sure you don't get 2 versions of python mixed up
6. sudo apt-get install python3-pip autoconf libtool
7. sudo reboot
8. curl –L install.domoticz.com | sudo bash
/// watch the Upper L, if this doesn't work try: sudo curl –L install.domoticz.com | bash
9. cd /home/pi/domoticz/plugins
10. git clone https://github.com/moroen/IKEA-Tradfri-plugin.git IKEA-Tradfri
/// make sure you end with IKEA-Tradfri with the upper en lower letters as stated
11. cd IKEA-Tradfri
12. bash ./install-coap-client.sh
13. pip3 install pytradfri
14. sudo pip3 install twisted
15. pip3 install service-identity
16. sudo reboot
17. ./configure.py --debug <IP adres tradfri hub> <security KEY on rear of hub>
/// Example: ./configure.py --debug 192.168.4.128 CRT5aE4Ff2DfGbE3 don't use sudo command,
18. python3 tradfri.tac
/// service test, if terminal returns: IKEA-tradfri COAP-adaptor version 0.8.7 started (command line)! press ctrl+c and continue with 19
19. ./configure.py –-skip-config –-create-service
20. sudo cp ikea-tradfri.service /etc/systemd/system
21. sudo systemctl daemon-reload
22. sudo systemctl start ikea-tradfri.service
23. sudo systemctl enable ikea-tradfri.service
24. Sudo reboot

/// open domoticz in a browser
25. Add ikea tradfri in hardware
/// IP adress adapter is 127.0.0.1 not the IP of the tradfri gateway
26. toggle: Observe changes to yes
schulpr
Posts: 137
Joined: Thursday 01 January 2015 9:10
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: [REQUEST] Ikea Trådfri Gateway (smart lights hub controller) plugin?

Post by schulpr »

Hi,

I need some help. The plugin works great but when I want to create the service with "./configure.py –-skip-config –-create-service" I get an error "Error: Failed to generate ID/PSK-pair.
Check that the IP and Master Key is correct.

Does anyone has an idea how to fix this? Create manually??? How ;)

Thanks in advance for the help!

Kind regards, Rob
moroen
Posts: 408
Joined: Sunday 15 January 2017 11:06
Target OS: Linux
Domoticz version: beta
Location: Norway
Contact:

Re: [REQUEST] Ikea Trådfri Gateway (smart lights hub controller) plugin?

Post by moroen »

schulpr wrote: Sunday 27 January 2019 17:27 Hi,

I need some help. The plugin works great but when I want to create the service with "./configure.py –-skip-config –-create-service" I get an error "Error: Failed to generate ID/PSK-pair.
Check that the IP and Master Key is correct.

Does anyone has an idea how to fix this? Create manually??? How ;)

Thanks in advance for the help!

Kind regards, Rob
I just tested this, and on my system it works like it should. Would you mind trying:

Code: Select all

$ ./configure.py --create-service IP KEY
This should generate a new ident/psk and create a ikea-tradfri.service file.

Let me know if this works...

BTW: Which version of python do you have?

Code: Select all

$ python3 --version
Regards,
M
schulpr
Posts: 137
Joined: Thursday 01 January 2015 9:10
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: [REQUEST] Ikea Trådfri Gateway (smart lights hub controller) plugin?

Post by schulpr »

Hi M,

Thanks for your help! "--create-service" etc. did the trick. I'am on python 3.5.3. I made a complete new Domoticz image but couldn't get it to work.

Until now :-).

Thanks again and kind regards, Rob
pieter1964
Posts: 6
Joined: Wednesday 23 January 2019 15:40
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [REQUEST] Ikea Trådfri Gateway (smart lights hub controller) plugin?

Post by pieter1964 »

yes
finaly it works also for me

after 10 installations

last update here did the trick
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest