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

Python and python framework
moroen
Posts: 177
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 » Tuesday 21 August 2018 13:22

Philos31 wrote:
Tuesday 21 August 2018 10:18
Hi, I am allready busy for 2 days to get this working.
Everything seems ok, but there is something strange going on.
In the domoticz log I see:

Code: Select all

2018-08-21 10:04:21.915 Error: (Tradfri) ----> Line 280 in '/home/pi/domoticz/plugins/IKEA-Tradfri/plugin.py, function onMessage
2018-08-21 10:04:21.915 Error: (Tradfri) ----> Line 190 in '/home/pi/domoticz/plugins/IKEA-Tradfri/plugin.py, function onMessage
2018-08-21 10:04:22.567 Error: (Tradfri) ----> Line 280 in '/home/pi/domoticz/plugins/IKEA-Tradfri/plugin.py, function onMessage
2018-08-21 10:04:22.567 Error: (Tradfri) ----> Line 190 in '/home/pi/domoticz/plugins/IKEA-Tradfri/plugin.py, function onMessage
When I try:

Code: Select all

python3 tradfri.tac
It is stuck when initializing

Code: Select all

IKEA-tradfri COAP-adaptor version 0.6 started (command line)!
Connected from IPv4Address(type='TCP', host='127.0.0.1', port=52704)
Data received: b'{"identity": "domoticz", "gateway": "192.168.1.136", "action": "setConfig", "pollinterval": "30", "groups": "False", "psk": "*****************", "observe": "True"}'
Initializing gateway
And it stays initializing, doing nothing further...
Any idea?
Sorry for the late reply! It would appear that you're using the latest beta of domoticz?

I commited a small fix to the development-branch of the plugin a couple of days ago, that should address this issue. If it still fails, feel free to open a issue on github or let me know here in the forum.

Regards,
M

ivarka
Posts: 12
Joined: Sunday 17 April 2016 21:00
Target OS: Raspberry Pi
Domoticz version:
Contact:

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

Post by ivarka » Wednesday 22 August 2018 9:36

IKEA will launch a smart plug in october: https://teknikveckan.com/nyheter/ikea-g ... rt-i-host/

Philos31
Posts: 54
Joined: Friday 15 August 2014 22:37
Target OS: Raspberry Pi
Domoticz version:
Contact:

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

Post by Philos31 » Wednesday 22 August 2018 9:41

moroen wrote:
Tuesday 21 August 2018 13:22
Philos31 wrote:
Tuesday 21 August 2018 10:18

Code: Select all

IKEA-tradfri COAP-adaptor version 0.6 started (command line)!
Connected from IPv4Address(type='TCP', host='127.0.0.1', port=52704)
Data received: b'{"identity": "domoticz", "gateway": "192.168.1.136", "action": "setConfig", "pollinterval": "30", "groups": "False", "psk": "*****************", "observe": "True"}'
Initializing gateway
And it stays initializing, doing nothing further...
Any idea?
Sorry for the late reply! It would appear that you're using the latest beta of domoticz?

I commited a small fix to the development-branch of the plugin a couple of days ago, that should address this issue. If it still fails, feel free to open a issue on github or let me know here in the forum.

Regards,
M
Thanks, that would explain a lot. I am running the latest Beta, started this week building my years old domoticz from scratch.
Now if I just knew how to pull the development-branch from Git.... but I found that out.

It seems to work now. Thanks.
RasPi2/KaKu/HUE/Xiaomi/Z-Wave/Nuki/Daikin 3,5kw Ururu Sarara/IR Heating Panels all working together with domoticz

dzjr
Posts: 11
Joined: Monday 02 July 2018 23:35
Target OS: Raspberry Pi
Domoticz version: 4.9942B
Location: Alkmaar, The Netherlands
Contact:

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

Post by dzjr » Friday 24 August 2018 23:47

Hello everyone,

I have made a new attempt, a completely new installation (read that there was an update).

now I'm a little further .. it just does not work ...

when I reboot the PI I get the following message in the log of domoticz:

Code: Select all



2018-08-24 23:46:27.012 (IKEA Tradfri) Connected successfully to: 192.168.0.19
2018-08-24 23:46:27.013 Error: (IKEA Tradfri) 'onMessage' failed 'TypeError':'byte indices must be integers or slices, not str'.
2018-08-24 23:46:27.013 Error: (IKEA Tradfri) ----> Line 282 in /home/pi/domoticz/plugins/IKEA-Tradfri/plugin.py, function onMessage
2018-08-24 23:46:27.013 Error: (IKEA Tradfri) ----> Line 195 in /home/pi/domoticz/plugins/IKEA-Tradfri/plugin.py, function onMessage
2018-08-24 23:46:38.088 PluginSystem: Restarting I/O service thread.
2018-08-24 23:46:38.089 (IKEA Tradfri) Device has disconnected



What did I do wrong?

maybe done too much?

I hope someone could help!
Raspberry Pi-3 Domoticz Beta
Tradfri Pluging by Moroen, Home made MySensors, Luftdaten, Home & Garden automatisation

moroen
Posts: 177
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 » Saturday 25 August 2018 18:51

dzjr wrote:
Friday 24 August 2018 23:47
Hello everyone,

I have made a new attempt, a completely new installation (read that there was an update).

now I'm a little further .. it just does not work ...

when I reboot the PI I get the following message in the log of domoticz:

Code: Select all



2018-08-24 23:46:27.012 (IKEA Tradfri) Connected successfully to: 192.168.0.19
2018-08-24 23:46:27.013 Error: (IKEA Tradfri) 'onMessage' failed 'TypeError':'byte indices must be integers or slices, not str'.
2018-08-24 23:46:27.013 Error: (IKEA Tradfri) ----> Line 282 in /home/pi/domoticz/plugins/IKEA-Tradfri/plugin.py, function onMessage
2018-08-24 23:46:27.013 Error: (IKEA Tradfri) ----> Line 195 in /home/pi/domoticz/plugins/IKEA-Tradfri/plugin.py, function onMessage
2018-08-24 23:46:38.088 PluginSystem: Restarting I/O service thread.
2018-08-24 23:46:38.089 (IKEA Tradfri) Device has disconnected



What did I do wrong?

maybe done too much?

I hope someone could help!
Hi!

Which version of domoticz and which branch of the plugin are you using?

[edit]
I managed to recreate this error by using the domoticz stable with the development-branch of the plugin. If you try using the plugin's master branch with domoticz stable, it should work.
[/edit]

Regards,
M

dzjr
Posts: 11
Joined: Monday 02 July 2018 23:35
Target OS: Raspberry Pi
Domoticz version: 4.9942B
Location: Alkmaar, The Netherlands
Contact:

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

Post by dzjr » Saturday 25 August 2018 19:37

moroen wrote:
Saturday 25 August 2018 18:51


Good evening M,

Yesterday i used the latest stable final version of Domoticz, and in used the plugin from your github, i downloaded both yesterday.

Today i have tried to upgrade tot Domoticz Beta (now Version: 4.9942 Build Hash: 5524d792)

Now i have this message on the Domoticz Log:

Code: Select all

 2018-08-25 19:24:17.133 (IKEA Tradfri) Connected successfully to: 192.168.0.19
2018-08-25 19:24:28.107 (IKEA Tradfri) Device has disconnected 
When i start " python3 tradfri.tac " i get the following message;

Code: Select all


IKEA-tradfri COAP-adaptor version 0.6 started (command line)!
Couldn't listen on any:1234: [Errno 98] Address already in use.

Whit twistd -n -y tradfri.tac i get the message:

Code: Select all

Another twistd server is running, PID 267

This could either be a previously started instance of your application or a
different application entirely. To start a new one, either run it in some other
directory, or use the --pidfile and --logfile parameters to avoid clashes.
The content of ikea-tradfri.service is:

Code: Select all

[Unit]
Description=IKEA Tradfri COAP-adapter

[Service]
Type=simple
Environment=IKEA_HOME=/home/pi/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
What do i wrong?

as far as I can see, the coap client just works.


I hope you can help me

dzjr
Raspberry Pi-3 Domoticz Beta
Tradfri Pluging by Moroen, Home made MySensors, Luftdaten, Home & Garden automatisation

moroen
Posts: 177
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 26 August 2018 2:37

dzjr wrote:
Saturday 25 August 2018 19:37
moroen wrote:
Saturday 25 August 2018 18:51


Good evening M,

Yesterday i used the latest stable final version of Domoticz, and in used the plugin from your github, i downloaded both yesterday.

Today i have tried to upgrade tot Domoticz Beta (now Version: 4.9942 Build Hash: 5524d792)

Now i have this message on the Domoticz Log:

Code: Select all

 2018-08-25 19:24:17.133 (IKEA Tradfri) Connected successfully to: 192.168.0.19
2018-08-25 19:24:28.107 (IKEA Tradfri) Device has disconnected 
When i start " python3 tradfri.tac " i get the following message;

Code: Select all


IKEA-tradfri COAP-adaptor version 0.6 started (command line)!
Couldn't listen on any:1234: [Errno 98] Address already in use.

Whit twistd -n -y tradfri.tac i get the message:

Code: Select all

Another twistd server is running, PID 267

This could either be a previously started instance of your application or a
different application entirely. To start a new one, either run it in some other
directory, or use the --pidfile and --logfile parameters to avoid clashes.
The content of ikea-tradfri.service is:

Code: Select all

[Unit]
Description=IKEA Tradfri COAP-adapter

[Service]
Type=simple
Environment=IKEA_HOME=/home/pi/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
What do i wrong?

as far as I can see, the coap client just works.


I hope you can help me

dzjr
It looks like you already have the adapter running. If you're using latest beta of domoticz with the plugin version from the developmen-branch, a reboot of the Pi should do the trick...

Regards,
M

dzjr
Posts: 11
Joined: Monday 02 July 2018 23:35
Target OS: Raspberry Pi
Domoticz version: 4.9942B
Location: Alkmaar, The Netherlands
Contact:

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

Post by dzjr » Sunday 26 August 2018 17:15

moroen wrote:
Saturday 25 August 2018 18:51

It looks like you already have the adapter running. If you're using latest beta of domoticz with the plugin version from the developmen-branch, a reboot of the Pi should do the trick...

Regards,
M

Hello M,

I have tried a reboot several times, and still the same "error"

I made a clean install with Domoticz Beta 4.9948 & IKEA-Tradfri development branche, and again the same problem.....


Coaps is working..., only the script of ggravelingen din't work right i think (try it yourself).

i don't know what i can try next....


dzjr
Raspberry Pi-3 Domoticz Beta
Tradfri Pluging by Moroen, Home made MySensors, Luftdaten, Home & Garden automatisation

moroen
Posts: 177
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 26 August 2018 19:52

dzjr wrote:
Sunday 26 August 2018 17:15
moroen wrote:
Saturday 25 August 2018 18:51

It looks like you already have the adapter running. If you're using latest beta of domoticz with the plugin version from the developmen-branch, a reboot of the Pi should do the trick...

Regards,
M

Hello M,

I have tried a reboot several times, and still the same "error"

I made a clean install with Domoticz Beta 4.9948 & IKEA-Tradfri development branche, and again the same problem.....


Coaps is working..., only the script of ggravelingen din't work right i think (try it yourself).

i don't know what i can try next....


dzjr
Ok, please try: Go to the plugin-directory (/home/pi/domoticz/plugins/IKEA-Tradfri) look for and remove the twistd.pid file if it exists, then try to run the adapter from the command line.

Regards,
M

dzjr
Posts: 11
Joined: Monday 02 July 2018 23:35
Target OS: Raspberry Pi
Domoticz version: 4.9942B
Location: Alkmaar, The Netherlands
Contact:

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

Post by dzjr » Sunday 26 August 2018 20:55

moroen wrote:
Saturday 25 August 2018 18:51



Ok, please try: Go to the plugin-directory (/home/pi/domoticz/plugins/IKEA-Tradfri) look for and remove the twistd.pid file if it exists, then try to run the adapter from the command line.

Regards,
M
i have removed twistd.pid and run twistd -n -y tradfri.tac and the output is:

Code: Select all

pi@raspberrypi:~/domoticz/plugins/IKEA-Tradfri $ twistd -n -y tradfri.tac
2018-08-26T20:51:11+0200 [-] Loading tradfri.tac...
2018-08-26T20:51:13+0200 [-] Loaded.
2018-08-26T20:51:13+0200 [twisted.scripts._twistd_unix.UnixAppLogger#info] twistd 18.7.0 (/usr/bin/python3 3.5.3) starting up.
2018-08-26T20:51:13+0200 [twisted.scripts._twistd_unix.UnixAppLogger#info] reactor class: twisted.internet.epollreactor.EPollReactor.
2018-08-26T20:51:13+0200 [stderr#error] Traceback (most recent call last):
2018-08-26T20:51:13+0200 [stderr#error]   File "/usr/local/lib/python3.5/dist-packages/twisted/internet/tcp.py", line 1361, in startListening
2018-08-26T20:51:13+0200 [stderr#error]     skt.bind(addr)
2018-08-26T20:51:13+0200 [stderr#error] OSError: [Errno 98] Address already in use
2018-08-26T20:51:13+0200 [stderr#error] During handling of the above exception, another exception occurred:
2018-08-26T20:51:13+0200 [stderr#error] Traceback (most recent call last):
2018-08-26T20:51:13+0200 [stderr#error]   File "/usr/local/bin/twistd", line 11, in <module>
2018-08-26T20:51:13+0200 [stderr#error]     sys.exit(run())
2018-08-26T20:51:13+0200 [stderr#error]   File "/usr/local/lib/python3.5/dist-packages/twisted/scripts/twistd.py", line 31, in run
2018-08-26T20:51:13+0200 [stderr#error]     app.run(runApp, ServerOptions)
2018-08-26T20:51:13+0200 [stderr#error]   File "/usr/local/lib/python3.5/dist-packages/twisted/application/app.py", line 674, in run
2018-08-26T20:51:13+0200 [stderr#error]     runApp(config)
2018-08-26T20:51:13+0200 [stderr#error]   File "/usr/local/lib/python3.5/dist-packages/twisted/scripts/twistd.py", line 25, in runApp
2018-08-26T20:51:13+0200 [stderr#error]     runner.run()
2018-08-26T20:51:13+0200 [stderr#error]   File "/usr/local/lib/python3.5/dist-packages/twisted/application/app.py", line 385, in run
2018-08-26T20:51:13+0200 [stderr#error]     self.postApplication()
2018-08-26T20:51:13+0200 [stderr#error]   File "/usr/local/lib/python3.5/dist-packages/twisted/scripts/_twistd_unix.py", line 254, in postApplication
2018-08-26T20:51:13+0200 [stderr#error]     self.startApplication(self.application)
2018-08-26T20:51:13+0200 [stderr#error]   File "/usr/local/lib/python3.5/dist-packages/twisted/scripts/_twistd_unix.py", line 442, in startApplication
2018-08-26T20:51:13+0200 [stderr#error]     service.IService(application).privilegedStartService()
2018-08-26T20:51:13+0200 [stderr#error]   File "/usr/local/lib/python3.5/dist-packages/twisted/application/service.py", line 283, in privilegedStartService
2018-08-26T20:51:13+0200 [stderr#error]     service.privilegedStartService()
2018-08-26T20:51:13+0200 [stderr#error]   File "/usr/local/lib/python3.5/dist-packages/twisted/application/internet.py", line 114, in privilegedStartService
2018-08-26T20:51:13+0200 [stderr#error]     self._port = self._getPort()
2018-08-26T20:51:13+0200 [stderr#error]   File "/usr/local/lib/python3.5/dist-packages/twisted/application/internet.py", line 142, in _getPort
2018-08-26T20:51:13+0200 [stderr#error]     'listen%s' % (self.method,))(*self.args, **self.kwargs)
2018-08-26T20:51:13+0200 [stderr#error]   File "/usr/local/lib/python3.5/dist-packages/twisted/internet/posixbase.py", line 495, in listenTCP
2018-08-26T20:51:13+0200 [stderr#error]     p.startListening()
2018-08-26T20:51:13+0200 [stderr#error]   File "/usr/local/lib/python3.5/dist-packages/twisted/internet/tcp.py", line 1363, in startListening
2018-08-26T20:51:13+0200 [stderr#error]     raise CannotListenError(self.interface, self.port, le)
2018-08-26T20:51:13+0200 [stderr#error] twisted.internet.error.CannotListenError: Couldn't listen on any:1234: [Errno 98] Address already in use.

output of python3 tradfri.tac is:

Code: Select all

pi@raspberrypi:~/domoticz/plugins/IKEA-Tradfri $ python3 tradfri.tac
IKEA-tradfri COAP-adaptor version 0.6 started (command line)!
Couldn't listen on any:1234: [Errno 98] Address already in use.
Raspberry Pi-3 Domoticz Beta
Tradfri Pluging by Moroen, Home made MySensors, Luftdaten, Home & Garden automatisation

moroen
Posts: 177
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 27 August 2018 18:09

dzjr wrote:
Sunday 26 August 2018 20:55

output of python3 tradfri.tac is:

Code: Select all

pi@raspberrypi:~/domoticz/plugins/IKEA-Tradfri $ python3 tradfri.tac
IKEA-tradfri COAP-adaptor version 0.6 started (command line)!
Couldn't listen on any:1234: [Errno 98] Address already in use.
The network port is already taken. Either you have the adapter running in the background (started via systemd?) or another service is using the same port-number (1234). It could also be that the port is being blocked by a firewall or something. I would guess the adapter already running is the most probable reason.

If you try:

Code: Select all

$ sudo systemctl stop ikea-tradfri.service
$ python3 tradfri.tac
and let me know the output...

Regards,
M

dzjr
Posts: 11
Joined: Monday 02 July 2018 23:35
Target OS: Raspberry Pi
Domoticz version: 4.9942B
Location: Alkmaar, The Netherlands
Contact:

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

Post by dzjr » Monday 27 August 2018 19:02

moroen wrote:
Monday 27 August 2018 18:09
dzjr wrote:
Sunday 26 August 2018 20:55

output of python3 tradfri.tac is:

Code: Select all

pi@raspberrypi:~/domoticz/plugins/IKEA-Tradfri $ python3 tradfri.tac
IKEA-tradfri COAP-adaptor version 0.6 started (command line)!
Couldn't listen on any:1234: [Errno 98] Address already in use.
The network port is already taken. Either you have the adapter running in the background (started via systemd?) or another service is using the same port-number (1234). It could also be that the port is being blocked by a firewall or something. I would guess the adapter already running is the most probable reason.

If you try:

Code: Select all

$ sudo systemctl stop ikea-tradfri.service
$ python3 tradfri.tac
and let me know the output...

Regards,
M
the output of python3 tradfri.tac is:

Code: Select all

pi@raspberrypi:~/domoticz/plugins/IKEA-Tradfri $ python3 tradfri.tac
IKEA-tradfri COAP-adaptor version 0.6 started (command line)!
Connected from IPv4Address(type='TCP', host='127.0.0.1', port=45418)
Data received: b'{"groups": "True", "gateway": "192.168.0.19", "identity": "*****", "pollinterval": "30", "observe": "True", "action": "setConfig", "psk": "{\\"9091\\":\\"123456789\\",\\"9029\\":\\"1.4.0015\\"}"}'
Initializing gateway
Unhandled Error
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/twisted/python/log.py", line 103, in callWithLogger
    return callWithContext({"system": lp}, func, *args, **kw)
  File "/usr/local/lib/python3.5/dist-packages/twisted/python/log.py", line 86, in callWithContext
    return context.call({ILogContext: newCtx}, func, *args, **kw)
  File "/usr/local/lib/python3.5/dist-packages/twisted/python/context.py", line 122, in callWithContext
    return self.currentContext().callWithContext(ctx, func, *args, **kw)
  File "/usr/local/lib/python3.5/dist-packages/twisted/python/context.py", line 85, in callWithContext
    return func(*args,**kw)
--- <exception caught here> ---
  File "/usr/local/lib/python3.5/dist-packages/twisted/internet/posixbase.py", line 614, in _doReadOrWrite
    why = selectable.doRead()
  File "/usr/local/lib/python3.5/dist-packages/twisted/internet/tcp.py", line 243, in doRead
    return self._dataReceived(data)
  File "/usr/local/lib/python3.5/dist-packages/twisted/internet/tcp.py", line 249, 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/api/libcoap_api.py", line 96, in request
    return self._execute(api_commands, timeout=timeout)
  File "/usr/local/lib/python3.5/dist-packages/pytradfri/api/libcoap_api.py", line 85, in _execute
    raise RequestTimeout() from None
pytradfri.error.RequestTimeout: 

Disconnected
Regards
dzjr
Raspberry Pi-3 Domoticz Beta
Tradfri Pluging by Moroen, Home made MySensors, Luftdaten, Home & Garden automatisation

moroen
Posts: 177
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 29 August 2018 19:26

dzjr wrote:
Monday 27 August 2018 19:02

the output of python3 tradfri.tac is:

Code: Select all

pi@raspberrypi:~/domoticz/plugins/IKEA-Tradfri $ python3 tradfri.tac
IKEA-tradfri COAP-adaptor version 0.6 started (command line)!
Connected from IPv4Address(type='TCP', host='127.0.0.1', port=45418)
Data received: b'{"groups": "True", "gateway": "192.168.0.19", "identity": "*****", "pollinterval": "30", "observe": "True", "action": "setConfig", "psk": "{\\"9091\\":\\"123456789\\",\\"9029\\":\\"1.4.0015\\"}"}'
Initializing gateway
Unhandled Error
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/twisted/python/log.py", line 103, in callWithLogger
    return callWithContext({"system": lp}, func, *args, **kw)
  File "/usr/local/lib/python3.5/dist-packages/twisted/python/log.py", line 86, in callWithContext
    return context.call({ILogContext: newCtx}, func, *args, **kw)
  File "/usr/local/lib/python3.5/dist-packages/twisted/python/context.py", line 122, in callWithContext
    return self.currentContext().callWithContext(ctx, func, *args, **kw)
  File "/usr/local/lib/python3.5/dist-packages/twisted/python/context.py", line 85, in callWithContext
    return func(*args,**kw)
--- <exception caught here> ---
  File "/usr/local/lib/python3.5/dist-packages/twisted/internet/posixbase.py", line 614, in _doReadOrWrite
    why = selectable.doRead()
  File "/usr/local/lib/python3.5/dist-packages/twisted/internet/tcp.py", line 243, in doRead
    return self._dataReceived(data)
  File "/usr/local/lib/python3.5/dist-packages/twisted/internet/tcp.py", line 249, 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/api/libcoap_api.py", line 96, in request
    return self._execute(api_commands, timeout=timeout)
  File "/usr/local/lib/python3.5/dist-packages/pytradfri/api/libcoap_api.py", line 85, in _execute
    raise RequestTimeout() from None
pytradfri.error.RequestTimeout: 

Disconnected

Ok, so the adapter times out when trying to use coap-client to communicate with the gateway. Are you sure you're using the correct ident/pks? Correct IP-adress? Can you use the coap-client directly to communicate with the gateway?

Regards,
M

dzjr
Posts: 11
Joined: Monday 02 July 2018 23:35
Target OS: Raspberry Pi
Domoticz version: 4.9942B
Location: Alkmaar, The Netherlands
Contact:

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

Post by dzjr » Wednesday 29 August 2018 19:43

moroen wrote:
Wednesday 29 August 2018 19:26



Ok, so the adapter times out when trying to use coap-client to communicate with the gateway. Are you sure you're using the correct ident/pks? Correct IP-adress? Can you use the coap-client directly to communicate with the gateway?

Regards,
M
i get this

Code: Select all


pi@raspberrypi:~/domoticz/plugins/IKEA-Tradfri $ coap-client -k "***************" coaps://192.168.0.19/.well-known/core
v:1 t:CON c:GET i:77ff {} [ ]
<//15006>;ct=0;obs,<//15001>;ct=0;obs,<//15004>;ct=0;obs,<//15004/add>;ct=0,<//15004/remove>;ct=0,<//15010>;ct=0;obs,<//15005>;ct=0;obs,<//15011/15012>;ct=0;obs,<//15011/9034>;ct=0,<//15011/9030>;ct=0,<//15011/9031>;ct=0,<//15011/9102>;ct=0,<//15011/9094>;ct=0;obs,<//15011/9095>;ct=0;obs,<//15011/9104>;ct=0;obs,<//15010/317446>;ct=0;obs,<//15010/289670>;ct=0;obs,<//15005/169498/200393>;ct=0;obs,<//15005/169498/220984>;ct=0;obs,<//15005/169498/205165>;ct=0;obs,<//15004/169498>;ct=0;obs,<//15005/169498>;ct=0;obs,<//15004/138625>;ct=0;obs,<//15005/138625>;ct=0;obs,<//15001/65537>;ct=0;obs,<//15001/65540>;ct=0;obs,<//15001/65536>;ct=0;obs,<//15001/65538>;ct=0;obs,<//15001/65542>;ct=0;obs,<//15001/65541>;ct=0;obs,<//15005/160748/212648>;ct=0;obs,<//15005/160748/217145>;ct=0;obs,<//15005/160748/197623>;ct=0;obs,<//15004/160748>;ct=0;obs,<//15005/160748>;ct=0;obs,<//15001/65543>;ct=0;obs,<//15005/138625/222168>;ct=0;obs,<//15005/138625/203559>;ct=0;obs,<//15005/138625/224462>;ct=0;obs,<//15011/9063>;ct=0,<//15001/65544>;ct=0;obs,<//15010/285904>;ct=0;obs


Raspberry Pi-3 Domoticz Beta
Tradfri Pluging by Moroen, Home made MySensors, Luftdaten, Home & Garden automatisation

dzjr
Posts: 11
Joined: Monday 02 July 2018 23:35
Target OS: Raspberry Pi
Domoticz version: 4.9942B
Location: Alkmaar, The Netherlands
Contact:

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

Post by dzjr » Thursday 30 August 2018 18:15

moroen wrote:
Wednesday 29 August 2018 19:26



Ok, so the adapter times out when trying to use coap-client to communicate with the gateway. Are you sure you're using the correct ident/pks? Correct IP-adress? Can you use the coap-client directly to communicate with the gateway?

Regards,
M

:oops: i did something stupit, i used the complete ouput of the coap call into Domoticz...

i placed only the PSK :idea: , and now it is working....

thank you for the helping, and offcourse for the plugin!


regeards
dzjr
Raspberry Pi-3 Domoticz Beta
Tradfri Pluging by Moroen, Home made MySensors, Luftdaten, Home & Garden automatisation

moroen
Posts: 177
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 31 August 2018 14:17

dzjr wrote:
Thursday 30 August 2018 18:15

:oops: i did something stupit, i used the complete ouput of the coap call into Domoticz...

i placed only the PSK :idea: , and now it is working....

thank you for the helping, and offcourse for the plugin!


regeards
dzjr

Glad it worked out for you!

I've been toying with an idea to handle the whole IDENT/PSK-thing differently, I'll use your experience as motivation to finally getting it implemented...

Regards,
M

moroen
Posts: 177
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 » Tuesday 04 September 2018 22:38

The latest version of the plugin's development branch now has a rather major change, a change that will break a current installation of the plugin, though rather easy to fix.

Instead of generating a (or using a known) IDENT/PSK pair, and then entering this information on the plugin setup page, the IDENT/PSK is handled by the adaptor, and generated using a configure.py python scipt, which need to be executed once before the adapter starts.

Anyone updating to the newest version are encouraged to the check out the readme for instructions, and report errors, problems or suggestions in this thread. Hopefully this change will alleviate a rather common problem getting the adapter to run, as you only need to supply the gateway IP and master-key on setup, no more manually using the coap-client directly to generate the IDENT/PSK-pair.

Regards,
M

MichaelvK
Posts: 5
Joined: Tuesday 02 January 2018 20:43
Target OS: NAS (Synology & others)
Domoticz version: 4.9992
Location: Harderwijk, the Netherlands
Contact:

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

Post by MichaelvK » Sunday 09 September 2018 11:02

Hi M,

I am running the plugin on development, and Domoticz on 4.9700.
When running the tradfri.tac, it is quiet.
After starting the plugin from Domoticz, I get the following result.
It is in a reboot loop after that, so the plugin re-initializes, and all lines re-occur.
It must be a very small issue, as I came this far finally (getting the right python3, pip3, twisted and coap-client setups without ipkg or so within the Synology linux variant..)

I have received the psk and marked it as x.x.xxxx below, it is a numeric value ofcourse.

Me@Diskstation216:/usr/local/domoticz/var/plugins/IKEA-Tradfri$ python3 tradfri.tac
IKEA-tradfri COAP-adaptor version 0.6 started (command line)!
Connected from IPv4Address(type='TCP', host='127.0.0.1', port=55273)
Data received: b'{"pollinterval": "30", "gateway": "192.168.1.167", "identity": "Client_identity", "groups": "False", "observe": "True", "psk": "x.x.xxxx", "action": "setConfig"}'
Initializing gateway
Unhandled Error
Traceback (most recent call last):
File "/opt/lib/python3.6/site-packages/twisted/python/log.py", line 103, in callWithLogger
return callWithContext({"system": lp}, func, *args, **kw)
File "/opt/lib/python3.6/site-packages/twisted/python/log.py", line 86, in callWithContext
return context.call({ILogContext: newCtx}, func, *args, **kw)
File "/opt/lib/python3.6/site-packages/twisted/python/context.py", line 122, in callWithContext
return self.currentContext().callWithContext(ctx, func, *args, **kw)
File "/opt/lib/python3.6/site-packages/twisted/python/context.py", line 85, in callWithContext
return func(*args,**kw)
--- <exception caught here> ---
File "/opt/lib/python3.6/site-packages/twisted/internet/posixbase.py", line 614, in _doReadOrWrite
why = selectable.doRead()
File "/opt/lib/python3.6/site-packages/twisted/internet/tcp.py", line 243, in doRead
return self._dataReceived(data)
File "/opt/lib/python3.6/site-packages/twisted/internet/tcp.py", line 249, 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 "/opt/lib/python3.6/site-packages/pytradfri-5.5.1-py3.6.egg/pytradfri/api/libcoap_api.py", line 96, in request

File "/opt/lib/python3.6/site-packages/pytradfri-5.5.1-py3.6.egg/pytradfri/api/libcoap_api.py", line 85, in _execute

pytradfri.error.RequestTimeout:

Disconnected


My Domoticz config:
Image

My Domoticz log:
Image
Synology DS216+ & Domoticz as a Package (Jadahl)
connected:
Denon AVR2200W
Panasonic TX-L47ET60B
Doorbell Action
Several KAKU Action Flamingo's
Ali-Express WiFi cam
Ali-Express WiFi PTZ cam (soon)
Ali-Express PIR's
IKEA Trådfri

User avatar
Dnpwwo
Posts: 736
Joined: Sunday 23 March 2014 10:00
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Melbourne, Australia
Contact:

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

Post by Dnpwwo » Sunday 09 September 2018 15:05

I assume you have upgraded Domoticz recently because the plugin framework changed JSON handling a few months ago and I believe that is your problem.

This code at around line 188 in plugin.py:

Code: Select all

def onMessage(self, Connection, Data):
        #Domoticz.Debug("Received: " + str(Data))
command = json.loads(Data.decode("utf-8"))
is out of date because the framework now returns structured JSON rather than a simple string as it did previously.

It needs to be changed to be something like:

Code: Select all

def onMessage(self, Connection, Data):
        #Domoticz.Debug("Received: " + str(Data))
command = Data
The reasonable man adapts himself to the world; the unreasonable one persists to adapt the world to himself. Therefore all progress depends on the unreasonable man. George Bernard Shaw

MichaelvK
Posts: 5
Joined: Tuesday 02 January 2018 20:43
Target OS: NAS (Synology & others)
Domoticz version: 4.9992
Location: Harderwijk, the Netherlands
Contact:

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

Post by MichaelvK » Sunday 09 September 2018 19:54

Thanks!


Got it working indeed , missed an update of Domoticz, but as this is handled as a package, had to pick a beta from Jadahl.
Great!
All I now have to figure out is to have the "python3 tradfri.tac" as a daemon / service on Synology.
Not as easy as it sounds..

Great stuff this plugin!!
Synology DS216+ & Domoticz as a Package (Jadahl)
connected:
Denon AVR2200W
Panasonic TX-L47ET60B
Doorbell Action
Several KAKU Action Flamingo's
Ali-Express WiFi cam
Ali-Express WiFi PTZ cam (soon)
Ali-Express PIR's
IKEA Trådfri

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest