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

Python and python framework
Yossarian
Posts: 7
Joined: Friday 17 November 2017 17:59
Target OS: Raspberry Pi
Domoticz version:
Contact:

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

Post by Yossarian » Friday 17 November 2017 22:29

Coap client v.0.4
Gateway Firmware just updated v.1.2.42
I run domoticz v3.8153

BTW, when i do

sudo service Ikea-tradfri statut

i get this error

ikea-tradfri.service - IKEA Tradfri COAP-adapter
Loaded: loaded (/lib/systemd/system/ikea-tradfri.service; enabled; vendor pre
Active: failed (Result: exit-code) since Fri 2017-11-17 18:45:45 CET; 21s ago
Process: 19395 ExecStart=/usr/local/bin/twistd --nodaemon --rundir=${IKEA_HOME
Main PID: 19395 (code=exited, status=217/USER)

nov. 17 18:45:45 raspberrypi systemd[1]: ikea-tradfri.service: Unit entered fail
nov. 17 18:45:45 raspberrypi systemd[1]: ikea-tradfri.service: Failed with resul
nov. 17 18:45:45 raspberrypi systemd[1]: ikea-tradfri.service: Service hold-off
nov. 17 18:45:45 raspberrypi systemd[1]: Stopped IKEA Tradfri COAP-adapter.
nov. 17 18:45:45 raspberrypi systemd[1]: ikea-tradfri.service: Start request rep
nov. 17 18:45:45 raspberrypi systemd[1]: Failed to start IKEA Tradfri COAP-adapt
nov. 17 18:45:45 raspberrypi systemd[1]: ikea-tradfri.service: Unit entered fail
nov. 17 18:45:45 raspberrypi systemd[1]: ikea-tradfri.service: Failed with resul

but when i do
pi@raspberrypi:~ $ cd /home/pi/domoticz/plugins/IKEA-Tradfri
pi@raspberrypi:~/domoticz/plugins/IKEA-Tradfri $ /usr/local/bin/twistd -n -y tradfri.tac

I get

Removing stale pidfile /home/pi/domoticz/plugins/IKEA-Tradfri/twistd.pid
2017-11-17T21:26:47+0100 [-] Removing stale pidfile /home/pi/domoticz/plugins/IKEA-Tradfri/twistd.pid
2017-11-17T21:26:47+0100 [-] Loading tradfri.tac...
2017-11-17T21:26:49+0100 [-] Loaded.
2017-11-17T21:26:49+0100 [twisted.scripts._twistd_unix.UnixAppLogger#info] twistd 17.9.0 (/usr/bin/python3 3.5.3) starting up.
2017-11-17T21:26:49+0100 [twisted.scripts._twistd_unix.UnixAppLogger#info] reactor class: twisted.internet.epollreactor.EPollReactor.
2017-11-17T21:26:49+0100 [-] AdaptorFactory starting on 1234
2017-11-17T21:26:49+0100 [builtins.AdaptorFactory#info] Starting factory <AdaptorFactory object at 0xb6057930>
^C2017-11-17T21:27:05+0100 [-] Received SIGINT, shutting down.
2017-11-17T21:27:05+0100 [-] (TCP Port 1234 Closed)
2017-11-17T21:27:05+0100 [builtins.AdaptorFactory#info] Stopping factory <AdaptorFactory object at 0xb6057930>
2017-11-17T21:27:05+0100 [-] Main loop terminated.
2017-11-17T21:27:05+0100 [twisted.scripts._twistd_unix.UnixAppLogger#info] Server Shut Down.

I did change the pathin the ikea-tradfri.serice by changing /opt/... by /home/pi/...

moroen
Posts: 150
Joined: Sunday 15 January 2017 12:06
Target OS: Linux
Domoticz version: beta
Location: Norway
Contact:

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

Post by moroen » Sunday 19 November 2017 13:49

Yossarian wrote:
Friday 17 November 2017 22:29
Coap client v.0.4
Gateway Firmware just updated v.1.2.42
I run domoticz v3.8153

BTW, when i do

sudo service Ikea-tradfri statut

i get this error

ikea-tradfri.service - IKEA Tradfri COAP-adapter
Loaded: loaded (/lib/systemd/system/ikea-tradfri.service; enabled; vendor pre
Active: failed (Result: exit-code) since Fri 2017-11-17 18:45:45 CET; 21s ago
Process: 19395 ExecStart=/usr/local/bin/twistd --nodaemon --rundir=${IKEA_HOME
Main PID: 19395 (code=exited, status=217/USER)

nov. 17 18:45:45 raspberrypi systemd[1]: ikea-tradfri.service: Unit entered fail
nov. 17 18:45:45 raspberrypi systemd[1]: ikea-tradfri.service: Failed with resul
nov. 17 18:45:45 raspberrypi systemd[1]: ikea-tradfri.service: Service hold-off
nov. 17 18:45:45 raspberrypi systemd[1]: Stopped IKEA Tradfri COAP-adapter.
nov. 17 18:45:45 raspberrypi systemd[1]: ikea-tradfri.service: Start request rep
nov. 17 18:45:45 raspberrypi systemd[1]: Failed to start IKEA Tradfri COAP-adapt
nov. 17 18:45:45 raspberrypi systemd[1]: ikea-tradfri.service: Unit entered fail
nov. 17 18:45:45 raspberrypi systemd[1]: ikea-tradfri.service: Failed with resul

but when i do
pi@raspberrypi:~ $ cd /home/pi/domoticz/plugins/IKEA-Tradfri
pi@raspberrypi:~/domoticz/plugins/IKEA-Tradfri $ /usr/local/bin/twistd -n -y tradfri.tac

I get

Removing stale pidfile /home/pi/domoticz/plugins/IKEA-Tradfri/twistd.pid
2017-11-17T21:26:47+0100 [-] Removing stale pidfile /home/pi/domoticz/plugins/IKEA-Tradfri/twistd.pid
2017-11-17T21:26:47+0100 [-] Loading tradfri.tac...
2017-11-17T21:26:49+0100 [-] Loaded.
2017-11-17T21:26:49+0100 [twisted.scripts._twistd_unix.UnixAppLogger#info] twistd 17.9.0 (/usr/bin/python3 3.5.3) starting up.
2017-11-17T21:26:49+0100 [twisted.scripts._twistd_unix.UnixAppLogger#info] reactor class: twisted.internet.epollreactor.EPollReactor.
2017-11-17T21:26:49+0100 [-] AdaptorFactory starting on 1234
2017-11-17T21:26:49+0100 [builtins.AdaptorFactory#info] Starting factory <AdaptorFactory object at 0xb6057930>
^C2017-11-17T21:27:05+0100 [-] Received SIGINT, shutting down.
2017-11-17T21:27:05+0100 [-] (TCP Port 1234 Closed)
2017-11-17T21:27:05+0100 [builtins.AdaptorFactory#info] Stopping factory <AdaptorFactory object at 0xb6057930>
2017-11-17T21:27:05+0100 [-] Main loop terminated.
2017-11-17T21:27:05+0100 [twisted.scripts._twistd_unix.UnixAppLogger#info] Server Shut Down.

I did change the pathin the ikea-tradfri.serice by changing /opt/... by /home/pi/...
Is there a stale .pid file in the plugin-directory? If so, delete it before trying system again...

You might get more information if you run:

Code: Select all

$ sudo journalctl -f -u ikea-tradfri
in another window and then try to start the service with systemd...

Regards,
M

Yossarian
Posts: 7
Joined: Friday 17 November 2017 17:59
Target OS: Raspberry Pi
Domoticz version:
Contact:

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

Post by Yossarian » Sunday 19 November 2017 17:58

Hi

I got my PSK while using the three port together instead one by one
coap-client -m post -u "Client_identity" -k "xxxxxxxxxxx" -e '{"9090":"Ikea"}' "coaps://192.168.1.95:5684/15011/9063"

Buuuuut, now i've got in domoticz log
2017-11-19 16:55:34.562 PluginSystem: Starting I/O service thread.
2017-11-19 16:55:34.562 (Ikea) Connect directive received, action initiated successfully.
2017-11-19 16:55:34.613 (Ikea) Calling message handler 'onConnect'.
2017-11-19 16:55:34.613 (Ikea) Failed to connect to IKEA tradfri COAP-adapter! Status: 111 Description: Connection refused
2017-11-19 16:55:36.520 (Ikea) Calling message handler 'onHeartbeat'.
2017-11-19 16:55:36.520 (Ikea) Not connected - nextConnect: 3
2017-11-19 16:55:38.526 (Ikea) Calling message handler 'onHeartbeat'.
2017-11-19 16:55:38.527 (Ikea) Not connected - nextConnect: 2
2017-11-19 16:55:40.533 (Ikea) Calling message handler 'onHeartbeat'.
2017-11-19 16:55:40.534 (Ikea) Not connected - nextConnect: 1
2017-11-19 16:55:40.534 (Ikea) Transport set to: 'TCP/IP', 127.0.0.1:1234.

No .pid filein IKEA-Tradfri folder

When i type

Code: Select all

$ sudo journalctl -f -u ikea-tradfri
It returns
sudo journalctl -f -u ikea-tradfri
-- Logs begin at Thu 2016-11-03 18:16:44 CET. --
nov. 19 16:48:14 raspberrypi systemd[31591]: ikea-tradfri.service: Failed at step USER spawning /usr/local/bin/twistd: No such process
nov. 19 16:48:14 raspberrypi systemd[1]: ikea-tradfri.service: Main process exited, code=exited, status=217/USER
nov. 19 16:48:14 raspberrypi systemd[1]: ikea-tradfri.service: Unit entered failed state.
nov. 19 16:48:14 raspberrypi systemd[1]: ikea-tradfri.service: Failed with result 'exit-code'.
nov. 19 16:48:14 raspberrypi systemd[1]: ikea-tradfri.service: Service hold-off time over, scheduling restart.
nov. 19 16:48:14 raspberrypi systemd[1]: Stopped IKEA Tradfri COAP-adapter.
nov. 19 16:48:14 raspberrypi systemd[1]: ikea-tradfri.service: Start request repeated too quickly.
nov. 19 16:48:14 raspberrypi systemd[1]: Failed to start IKEA Tradfri COAP-adapter.
nov. 19 16:48:14 raspberrypi systemd[1]: ikea-tradfri.service: Unit entered failed state.
nov. 19 16:48:14 raspberrypi systemd[1]: ikea-tradfri.service: Failed with result 'exit-code'.

wich is weird as i have twistd already installed

Yossarian
Posts: 7
Joined: Friday 17 November 2017 17:59
Target OS: Raspberry Pi
Domoticz version:
Contact:

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

Post by Yossarian » Sunday 19 November 2017 18:22

After restart
2017-11-19 17:19:01.709 (Ikea) Failed to connect to IKEA tradfri COAP-adapter! Status: 111 Description: Connection refused

then when i type

Code: Select all

pi@raspberrypi:~ $ cd /home/pi/domoticz/plugins/IKEA-Tradfri
pi@raspberrypi:~/domoticz/plugins/IKEA-Tradfri $ /usr/local/bin/twistd -n -y tradfri.tac
it shows
2017-11-19 17:19:07.635 PluginSystem: Starting I/O service thread.
2017-11-19 17:19:07.686 (Ikea) Connected successfully to: 192.168.1.95
2017-11-19 17:19:07.688 (Ikea) Received: b'{"version": "0.4", "status": "Ok", "action": "clientConnect"}'
2017-11-19 17:19:18.087 (Ikea) Received: b'{"error": "Connection timed out", "status": "Failed", "action": "setConfig"}'
2017-11-19 17:19:18.092 (Ikea) Command setConfig failed with error: Connection timed out.
2017-11-19 17:19:18.092 (Ikea) {'action': 'setConfig', 'status': 'Failed', 'error': 'Connection timed out'}

while i see in putty
2017-11-19T17:55:22+0100 [-] Loading tradfri.tac...
2017-11-19T17:55:25+0100 [-] Loaded.
2017-11-19T17:55:25+0100 [twisted.scripts._twistd_unix.UnixAppLogger#info] twistd 17.9.0 (/usr/bin/python3 3.5.3) starting up.
2017-11-19T17:55:25+0100 [twisted.scripts._twistd_unix.UnixAppLogger#info] reactor class: twisted.internet.epollreactor.EPollReactor.
2017-11-19T17:55:25+0100 [-] AdaptorFactory starting on 1234
2017-11-19T17:55:25+0100 [builtins.AdaptorFactory#info] Starting factory <AdaptorFactory object at 0xb6040910>
2017-11-19T17:56:21+0100 [stdout#info] Connected from IPv4Address(TCP, '127.0.0.1', 41152)
2017-11-19T17:56:57+0100 [-] Received SIGINT, shutting down.
2017-11-19T17:56:57+0100 [-] (TCP Port 1234 Closed)
2017-11-19T17:56:57+0100 [builtins.AdaptorFactory#info] Stopping factory <AdaptorFactory object at 0xb6040910>
2017-11-19T17:56:57+0100 [stdout#info] Disconnected
2017-11-19T17:56:57+0100 [-] Main loop terminated.
2017-11-19T17:56:57+0100 [twisted.scripts._twistd_unix.UnixAppLogger#info] Server Shut Down.


So,from what I understand (I don't know python at all ... and maybe I'm totally wrong :roll: ), I've got 2 problems :
1: my IKEA-Tradfri.service seems unable to call directly the tradfri.tac --> do I have to change Something in the IKEA-Tradfri.service file? BTW, does the User/group have to match the IKEA-Tradrfi.service folder or the /user/bin/local/twistd folder?
2: when i can call it using /usr/local/bin/twistd -n -y tradfri.tac, it can connect to the Gateway but the connection is lost because TCP port 1234 is closed. I've tried port forwarding but unsuccessfully

moroen
Posts: 150
Joined: Sunday 15 January 2017 12:06
Target OS: Linux
Domoticz version: beta
Location: Norway
Contact:

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

Post by moroen » Sunday 19 November 2017 20:33

Yossarian wrote:
Sunday 19 November 2017 18:22
So,from what I understand (I don't know python at all ... and maybe I'm totally wrong :roll: ), I've got 2 problems :
1: my IKEA-Tradfri.service seems unable to call directly the tradfri.tac --> do I have to change Something in the IKEA-Tradfri.service file? BTW, does the User/group have to match the IKEA-Tradrfi.service folder or the /user/bin/local/twistd folder?
2: when i can call it using /usr/local/bin/twistd -n -y tradfri.tac, it can connect to the Gateway but the connection is lost because TCP port 1234 is closed. I've tried port forwarding but unsuccessfully
The first step is to get the adaptor and domoticz to work while running the adaptor from the command-line, and when you have successfully gotten the plugin to work from the command-line, try using systemd...

I notice a couple of things from your log:
1. 2017-11-19 17:19:07.688 (Ikea) Received: b'{"version": "0.4", "status": "Ok", "action": "clientConnect"}'
2. 2017-11-19 17:19:18.087 (Ikea) Received: b'{"error": "Connection timed out", "status": "Failed", "action": "setConfig"}'

1. indicates that domoticz is able to connect to the adapter, and
2. the adapter is unable to connect to the ikea-gateway (the second line), and is correctly returning this error to domoticz


And this line:
2017-11-19T17:56:57+0100 [-] Received SIGINT, shutting down.

That shouldn't happen unless you close the adapter using ctrl-c?

Regards,
M

Yossarian
Posts: 7
Joined: Friday 17 November 2017 17:59
Target OS: Raspberry Pi
Domoticz version:
Contact:

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

Post by Yossarian » Sunday 19 November 2017 21:47

I do close the adapter using ctrl+C because nothing happens.should I wait longer?
2. the adapter is unable to connect to the ikea-gateway (the second line), and is correctly returning this error to domoticz
So is the problem comming from my router? my Gateway ?

How can I bring you more precision?

Regards

(BTW : thanks alot for your time and help)

Yossarian
Posts: 7
Joined: Friday 17 November 2017 17:59
Target OS: Raspberry Pi
Domoticz version:
Contact:

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

Post by Yossarian » Sunday 19 November 2017 23:52

UPDATE :Finally got it!!!
I didn't have the right user/group set in the Ikea-tradfri.service. I tought it had to match /home/pi/domoticz/plugins/IKEA-Trafri folderbut it had to match the /lib/systemd/system/ folder

When nothing works, start again from the beginning...
I did the setup again and now it works. I guess I must have missed some sudo command ...

So I can switch on/off lights now only if i do :

Code: Select all

pi@raspberrypi:~ $ cd /home/pi/domoticz/plugins/IKEA-Tradfri
pi@raspberrypi:~/domoticz/plugins/IKEA-Tradfri $ sudo python3 tradfri.tac 
Note that I have to sudo to make it works
Otherwise i get

Code: Select all

pi@raspberrypi:~ $ cd /home/pi/domoticz/plugins/IKEA-Tradfri
pi@raspberrypi:~/domoticz/plugins/IKEA-Tradfri $ python3 tradfri.tac
Traceback (most recent call last):
  File "tradfri.tac", line 14, in <module>
    from pytradfri.api.libcoap_api import APIFactory
ImportError: cannot import name 'APIFactory'
When i close putty, nothing works anymore.

My ikea-tradfri.service status shows that it is running fine ans is in the lib/systemcl/system folder

Any suggestions?

moroen
Posts: 150
Joined: Sunday 15 January 2017 12:06
Target OS: Linux
Domoticz version: beta
Location: Norway
Contact:

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

Post by moroen » Monday 20 November 2017 20:30

Yossarian wrote:
Sunday 19 November 2017 23:52
UPDATE :Finally got it!!!
I didn't have the right user/group set in the Ikea-tradfri.service. I tought it had to match /home/pi/domoticz/plugins/IKEA-Trafri folderbut it had to match the /lib/systemd/system/ folder

When nothing works, start again from the beginning...
I did the setup again and now it works. I guess I must have missed some sudo command ...

So I can switch on/off lights now only if i do :

Code: Select all

pi@raspberrypi:~ $ cd /home/pi/domoticz/plugins/IKEA-Tradfri
pi@raspberrypi:~/domoticz/plugins/IKEA-Tradfri $ sudo python3 tradfri.tac 
Note that I have to sudo to make it works
Otherwise i get

Code: Select all

pi@raspberrypi:~ $ cd /home/pi/domoticz/plugins/IKEA-Tradfri
pi@raspberrypi:~/domoticz/plugins/IKEA-Tradfri $ python3 tradfri.tac
Traceback (most recent call last):
  File "tradfri.tac", line 14, in <module>
    from pytradfri.api.libcoap_api import APIFactory
ImportError: cannot import name 'APIFactory'
When i close putty, nothing works anymore.

My ikea-tradfri.service status shows that it is running fine ans is in the lib/systemcl/system folder

Any suggestions?
It appears to be something slightly odd with your python installation. Modules installed with sudo pip3... should (as far as I know) be available to non-root users as well... The error when trying to run pytradfri.tac as a non-root user suggests that the pytradfri-module isn't available to a regular user?

Anyway, as long as the adapter runs as root, the following ikea-tradfri.service file should work:

Code: Select all

[Unit]
Description=IKEA Tradfri COAP-adapter

[Service]
Type=simple
Environment=IKEA_HOME=/opt/domoticz/plugins/IKEA-Tradfri
ExecStart=/usr/local/bin/twistd --nodaemon \
      --rundir=${IKEA_HOME} \
      --pidfile=${IKEA_HOME}/twistd.pid \
      --python=${IKEA_HOME}/tradfri.tac

User=root
Group=root

Restart=always

[Install]
WantedBy=multi-user.target
provided that you substitute IKEA_HOME for the real path to the plugin...

Regards,
M

Yossarian
Posts: 7
Joined: Friday 17 November 2017 17:59
Target OS: Raspberry Pi
Domoticz version:
Contact:

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

Post by Yossarian » Tuesday 21 November 2017 17:51

provided that you substitute IKEA_HOME for the real path to the plugin...
I did. Don't know what's wrong but in the end I can make it work.

Anyway, thank you for your help and the great job you did with this plugin

Best regards

Siopaos
Posts: 2
Joined: Wednesday 22 November 2017 0:56
Target OS: -
Domoticz version:
Contact:

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

Post by Siopaos » Wednesday 22 November 2017 1:12

Hello,
I've been trying to get the plugin to work, but I was having trouble with the PSK from the Pytradfri at first. I fixed this by manually adding the Gateway Identity and PSK on two places in "libcoap_api.py', but now I'm getting the following error when trying to use tradfri.tac:

Initializing gateway
Unhandled Error
Traceback (most recent call last):
File "/home/pi/.local/lib/python3.5/site-packages/twisted/python/log.py", line 103, in callWithLogger
return callWithContext({"system": lp}, func, *args, **kw)
File "/home/pi/.local/lib/python3.5/site-packages/twisted/python/log.py", line 86, in callWithContext
return context.call({ILogContext: newCtx}, func, *args, **kw)
File "/home/pi/.local/lib/python3.5/site-packages/twisted/python/context.py", line 122, in callWithContext
return self.currentContext().callWithContext(ctx, func, *args, **kw)
File "/home/pi/.local/lib/python3.5/site-packages/twisted/python/context.py", line 85, in callWithContext
return func(*args,**kw)
--- <exception caught here> ---
File "/home/pi/.local/lib/python3.5/site-packages/twisted/internet/posixbase.py", line 614, in _doReadOrWrite
why = selectable.doRead()
File "/home/pi/.local/lib/python3.5/site-packages/twisted/internet/tcp.py", line 205, in doRead
return self._dataReceived(data)
File "/home/pi/.local/lib/python3.5/site-packages/twisted/internet/tcp.py", line 211, in _dataReceived
rval = self.protocol.dataReceived(data)
File "tradfri.tac", line 76, in dataReceived
self.factory.initGateway(self, command)
File "tradfri.tac", line 275, in initGateway
self.devices = self.api(self.api(self.gateway.get_devices()))
File "/usr/local/lib/python3.5/dist-packages/pytradfri-4.0.3-py3.5.egg/pytradfri/api/libcoap_api.py", line 98, in request

File "/usr/local/lib/python3.5/dist-packages/pytradfri-4.0.3-py3.5.egg/pytradfri/api/libcoap_api.py", line 82, in _execute

Do you know how I could fix the problem?

moroen
Posts: 150
Joined: Sunday 15 January 2017 12:06
Target OS: Linux
Domoticz version: beta
Location: Norway
Contact:

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

Post by moroen » Wednesday 22 November 2017 10:04

Siopaos wrote:
Wednesday 22 November 2017 1:12
Hello,
I've been trying to get the plugin to work, but I was having trouble with the PSK from the Pytradfri at first. I fixed this by manually adding the Gateway Identity and PSK on two places in "libcoap_api.py', but now I'm getting the following error when trying to use tradfri.tac:
Do you know how I could fix the problem?
If you have a PSK and identity from pytradfri that works, I would recommend to input them into the plugin. The default IDENT from pytradfri is pytradfri, combined with the PSK from the text file...

Regards,
M

Siopaos
Posts: 2
Joined: Wednesday 22 November 2017 0:56
Target OS: -
Domoticz version:
Contact:

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

Post by Siopaos » Wednesday 22 November 2017 10:23

moroen wrote:
Wednesday 22 November 2017 10:04
If you have a PSK and identity from pytradfri that works, I would recommend to input them into the plugin. The default IDENT from pytradfri is pytradfri, combined with the PSK from the text file...

Regards,
M
I have added the PSK and identity in the plugin in domoticz as well as in the gateway_psk.txt file in the pytradfri folder, but it doesn't seem to work:

IKEA-tradfri COAP-adaptor version 0.5 started (command line)!
Connected from IPv4Address(TCP, '127.0.0.1', 38238)
Data received: b'{"groups": "False", "action": "setConfig", "identity": "MYIDENTITYWASHERE", "pollinterval": "30", "psk": "MYPSKWASHERE", "observe": "False", "gateway": "192.168.1.34"}'
then the error as above

It still seems to be going wrong somehow..

moroen
Posts: 150
Joined: Sunday 15 January 2017 12:06
Target OS: Linux
Domoticz version: beta
Location: Norway
Contact:

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

Post by moroen » Wednesday 22 November 2017 10:42

Siopaos wrote:
Wednesday 22 November 2017 10:23
moroen wrote:
Wednesday 22 November 2017 10:04
If you have a PSK and identity from pytradfri that works, I would recommend to input them into the plugin. The default IDENT from pytradfri is pytradfri, combined with the PSK from the text file...

Regards,
M
I have added the PSK and identity in the plugin in domoticz as well as in the gateway_psk.txt file in the pytradfri folder, but it doesn't seem to work:

IKEA-tradfri COAP-adaptor version 0.5 started (command line)!
Connected from IPv4Address(TCP, '127.0.0.1', 38238)
Data received: b'{"groups": "False", "action": "setConfig", "identity": "MYIDENTITYWASHERE", "pollinterval": "30", "psk": "MYPSKWASHERE", "observe": "False", "gateway": "192.168.1.34"}'
then the error as above

It still seems to be going wrong somehow..
just need to ask to be sure: You have reverted the changes you did in "libcoap_api.py'? What's your OS?

Regards,
M

dalecooper
Posts: 5
Joined: Wednesday 21 December 2016 10:39
Target OS: Raspberry Pi
Domoticz version:
Contact:

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

Post by dalecooper » Wednesday 06 December 2017 16:46

moroen wrote:
Monday 20 November 2017 20:30
Yossarian wrote:
Sunday 19 November 2017 23:52
UPDATE :Finally got it!!!
I didn't have the right user/group set in the Ikea-tradfri.service. I tought it had to match /home/pi/domoticz/plugins/IKEA-Trafri folderbut it had to match the /lib/systemd/system/ folder

When nothing works, start again from the beginning...
I did the setup again and now it works. I guess I must have missed some sudo command ...

So I can switch on/off lights now only if i do :

Code: Select all

pi@raspberrypi:~ $ cd /home/pi/domoticz/plugins/IKEA-Tradfri
pi@raspberrypi:~/domoticz/plugins/IKEA-Tradfri $ sudo python3 tradfri.tac 
Note that I have to sudo to make it works
Otherwise i get

Code: Select all

pi@raspberrypi:~ $ cd /home/pi/domoticz/plugins/IKEA-Tradfri
pi@raspberrypi:~/domoticz/plugins/IKEA-Tradfri $ python3 tradfri.tac
Traceback (most recent call last):
  File "tradfri.tac", line 14, in <module>
    from pytradfri.api.libcoap_api import APIFactory
ImportError: cannot import name 'APIFactory'
When i close putty, nothing works anymore.

My ikea-tradfri.service status shows that it is running fine ans is in the lib/systemcl/system folder

Any suggestions?
It appears to be something slightly odd with your python installation. Modules installed with sudo pip3... should (as far as I know) be available to non-root users as well... The error when trying to run pytradfri.tac as a non-root user suggests that the pytradfri-module isn't available to a regular user?

Anyway, as long as the adapter runs as root, the following ikea-tradfri.service file should work:

Code: Select all

[Unit]
Description=IKEA Tradfri COAP-adapter

[Service]
Type=simple
Environment=IKEA_HOME=/opt/domoticz/plugins/IKEA-Tradfri
ExecStart=/usr/local/bin/twistd --nodaemon \
      --rundir=${IKEA_HOME} \
      --pidfile=${IKEA_HOME}/twistd.pid \
      --python=${IKEA_HOME}/tradfri.tac

User=root
Group=root

Restart=always

[Install]
WantedBy=multi-user.target
provided that you substitute IKEA_HOME for the real path to the plugin...

Regards,
M

Fwiw, had the same problem.
Made the installation with sudo while logged in throught putty with pi user.

My plugins folder is /home/pi/domoticz/plugins/.
Had to edit user and group settings in the config file.

User avatar
bitjeverkeerd
Posts: 12
Joined: Monday 13 April 2015 20:39
Target OS: Raspberry Pi
Domoticz version: beta
Contact:

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

Post by bitjeverkeerd » Monday 11 December 2017 17:32

I have this very cool (development version) of the ikea tradfri plugin working. Observe changes and add group as devices are both on. Debug is off.
I can switch the lights from Domoticz and I can see that the status of the lights changes when I switch them with the Tradfri remote.
My question is whether it is possible to see the status of the Tradfri remote in Domoticz. Then I could also switch other devices with this remote..

djac
Posts: 7
Joined: Tuesday 24 October 2017 9:41
Target OS: Raspberry Pi
Domoticz version:
Contact:

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

Post by djac » Friday 15 December 2017 16:06

bitjeverkeerd wrote:
Monday 11 December 2017 17:32
I have this very cool (development version) of the ikea tradfri plugin working. Observe changes and add group as devices are both on. Debug is off.
I can switch the lights from Domoticz and I can see that the status of the lights changes when I switch them with the Tradfri remote.
My question is whether it is possible to see the status of the Tradfri remote in Domoticz. Then I could also switch other devices with this remote..
How do you get the bulb connected to both GW and remote? When I try to connect the remote the bulb loose connection to the GW?

moroen
Posts: 150
Joined: Sunday 15 January 2017 12:06
Target OS: Linux
Domoticz version: beta
Location: Norway
Contact:

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

Post by moroen » Friday 15 December 2017 23:13

bitjeverkeerd wrote:
Monday 11 December 2017 17:32
I have this very cool (development version) of the ikea tradfri plugin working. Observe changes and add group as devices are both on. Debug is off.
I can switch the lights from Domoticz and I can see that the status of the lights changes when I switch them with the Tradfri remote.
My question is whether it is possible to see the status of the Tradfri remote in Domoticz. Then I could also switch other devices with this remote..
Sorry for the late reply, I've been occupied elsewhere for a while. At the moment it's not possible to monitor the remotes directly. You could work around this by assigning a bulb to the remote, and then use event-scripts (python, lua or dzVents) for this bulb to trigger a scene or the other devices. Due to the way observations are done at the moment, there will be somewhat of a delay, but it should work.

Regards,
M

User avatar
bitjeverkeerd
Posts: 12
Joined: Monday 13 April 2015 20:39
Target OS: Raspberry Pi
Domoticz version: beta
Contact:

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

Post by bitjeverkeerd » Thursday 21 December 2017 22:15

Thanks for the reply. For the time being I will use my old zwave switches to switch on the tradfri lighting. Maybe in the future I will completely switch to zigbee/ikea tradfri. Thanks for all the work you have put into this plugin. I keep testing.

JCred
Posts: 2
Joined: Monday 25 December 2017 15:56
Target OS: Raspberry Pi
Domoticz version:
Contact:

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

Post by JCred » Monday 25 December 2017 16:20

I'm also trying to get the plugin to work on a raspberry pi running raspbian Jessie, but I am getting stuck at getting a PSK.
after I type in:

>$ coap-client -m post -u "client_identity" -k "MY-GATEWEY-KEY" -e '{"9090":"IKEA"}' "coaps://MY-IP:5684/15011/9063"

I get the following reponse:
> v:1 t:CON c:POST i:1135 {} [ ]
> Dec 25 14:52:13 ALRT 115 invalidate peer
> Dec 25 14:52:13 WARN received alert, peer has been invalidated

I have googled the ALRT 115 error, but could not find any leads. Can anyone help me get past this step?

moroen
Posts: 150
Joined: Sunday 15 January 2017 12:06
Target OS: Linux
Domoticz version: beta
Location: Norway
Contact:

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

Post by moroen » Monday 25 December 2017 22:39

JCred wrote:
Monday 25 December 2017 16:20
I'm also trying to get the plugin to work on a raspberry pi running raspbian Jessie, but I am getting stuck at getting a PSK.
after I type in:

>$ coap-client -m post -u "client_identity" -k "MY-GATEWEY-KEY" -e '{"9090":"IKEA"}' "coaps://MY-IP:5684/15011/9063"

I get the following reponse:
> v:1 t:CON c:POST i:1135 {} [ ]
> Dec 25 14:52:13 ALRT 115 invalidate peer
> Dec 25 14:52:13 WARN received alert, peer has been invalidated

I have googled the ALRT 115 error, but could not find any leads. Can anyone help me get past this step?
It's a subtle fault in your command, Client_identity is with a capital C, so the correct line would be:

Code: Select all

$ coap-client -m post -u "Client_identity" -k "MY-GATEWEY-KEY" -e '{"9090":"IKEA"}' "coaps://MY-IP:5684/15011/9063"
Hopefully that should provide you with at PDSK for the IKEA ident!

Regards,
M

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests