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

Python and python framework

Moderator: leecollings

AxelvanH
Posts: 29
Joined: Sunday 22 November 2015 22:11
Target OS: NAS (Synology & others)
Domoticz version: 2020.01
Location: Netherlands
Contact:

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

Post by AxelvanH »

Hi Moroen,

I just deleted the Plugins/IKEA-Tradfri directory and started over with the instructions.
One thing that comes to my attention is that this command does not work.

cd domoticz/plugins/

Instead i have to manually switch to: /usr/local/domoticz/var/plugins/

Could that have something to do with some issues?

Kr,
Axel
AxelvanH
Posts: 29
Joined: Sunday 22 November 2015 22:11
Target OS: NAS (Synology & others)
Domoticz version: 2020.01
Location: Netherlands
Contact:

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

Post by AxelvanH »

AxelvanH wrote: Friday 02 October 2020 10:59 Hi Moroen,

I just deleted the Plugins/IKEA-Tradfri directory and started over with the instructions.
One thing that comes to my attention is that this command does not work.

cd domoticz/plugins/

Instead i have to manually switch to: /usr/local/domoticz/var/plugins/

Could that have something to do with some issues?

Kr,
Axel
Just to answer my own question, it does not :)
The only 'handicap' is that you need to move to this location yourself.
#problem solved.
AxelvanH
Posts: 29
Joined: Sunday 22 November 2015 22:11
Target OS: NAS (Synology & others)
Domoticz version: 2020.01
Location: Netherlands
Contact:

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

Post by AxelvanH »

moroen wrote: Monday 21 September 2020 0:35
AxelvanH wrote: Saturday 19 September 2020 21:02 Please help!

python3 plugin.py config 1.1.1.1 code
Traceback (most recent call last):
File "plugin.py", line 177, in <module>
create_ident(args.IP, args.KEY, CONFIGFILE)
File "/volume1/@appstore/domoticz/var/plugins/IKEA-Tradfri/tradfricoap/coapcmd_api.py", line 81, in create_ident
result = json.loads(subprocess.run([_coapCMD, "post", "--ident", "Client_identity", "--key", key, uri, payload], stdout=subprocess.PIPE).stdout.decode('utf-8'))
File "/volume1/@appstore/py3k/usr/local/lib/python3.5/subprocess.py", line 696, in run
with Popen(*popenargs, **kwargs) as process:
File "/volume1/@appstore/py3k/usr/local/lib/python3.5/subprocess.py", line 950, in __init__
restore_signals, start_new_session)
File "/volume1/@appstore/py3k/usr/local/lib/python3.5/subprocess.py", line 1544, in _execute_child
raise child_exception_type(errno_num, err_msg)
PermissionError: [Errno 13] Permission denied

Again gives still the same error. chmod 777 on config.json did not make any difference.

My config.json file:

vi config.json
{"Gateway": null, "Identity": null, "Api": "Coapcmd", "Transition_time": 10, "Passkey": null, "Verbosity": 0}


Any suggestion is welcome on how to proceed.

Thanks,
Axel
I'm still pretty sure that the error is a permission error when the plugin tries to run coapcmd, the error seems to occur at

Code: Select all

result = json.loads(subprocess.run([_coapCMD, "post", "--ident", "Client_identity", "--key", key, uri, payload],
Have you tried to set permission on coapcmd?

Code: Select all

chmod gou+rwx bin/coapcmd
Reagards,
M
Hi Moroen,

I deleted the whole TIKEA-Tradfri directory and started over again from scratch reading every line meticulously...
Keeping a log off all the messages in the progress. Now everything (except from chaning to the plugins directory differently) worked fine!
Connection is established and all devices are reported.

My appologies for taking your time, I hope the below will help other users.
Thank you for the great work, answers and patience!

Kr, Axel

On the question, where things went wrong, I guess in the switching between installs.
https://github.com/moroen/IKEA-Tradfri- ... /README.md

Point 1 is easy.
Point 2 can be skipped as explained.

At point 3, I go mistaken by the first paragraph. At the link towards coapcmd, I emidattely clicked that.
But the steps for synology should be:

1. Get Golang envirionment:
Download right version xxx
tar -C /usr/local -xzf go1.15.2.linux-xxxx.tar.gz
export PATH=$PATH:/usr/local/go/bin
go version

2. Goto pugins-dir
cd /volume1/@appstore/domoticz/var/plugins

3. Get Coapcmd
plugins/IKEA-Tradfri# git clone https://github.com/moroen/coapcmd.git
plugins/IKEA-Tradfri# cd coapcmd

4. Execute install
plugins/IKEA-Tradfri# bash install_coapcmd.sh

5. Select coapcmd
/plugins/IKEA-Tradfri# python3 plugin.py api coapcmd

6. Configure coapcmd
plugins/IKEA-Tradfri# python3 plugin.py config 192.168.2.71 Key12345678

step 6 only works with the proper IP address of the gateway, else it will fail with:
{'Result': '', 'Status': 'HandshakeError'}
Connection timed out

7. python3 plugin.py list
Listing all connections.

8. Restarting Domoticz and adding the plugin.
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 »

There is a new version of the plugin available, 0.10.0. Unfortunately this update brings a couple of breaking changes, and I urge everyone planing to update to check out the updated readme.

Tradfricoap (the API for controlling the gateway) has been separated out into it's own module, available on pypi (https://pypi.org/project/tradfricoap/). On well configured systems where the interactive interpreter is the same as the one used by domoticz, the upgrade should be simple:

Code: Select all

$ cd plugins/IKEA-Tradfri
$ git checkout master
$ git pull
$ rm -rf tradfricoap
$ sudo -H pip3 install tradfricoap
On systems where domoticz is unable to find or use system modules, tradfricoap can still be installed into the plugin directory with git:

Code: Select all

$ cd plugins/IKEA-Tradfri
$ git clone https://github.com/moroen/tradfricoap.git
For systems using coapcmd, there is a new version of this as well:

Code: Select all

$ cd plugins/IEKA-Tradfri
$ sh ./install_coapcmd.sh
or download the latest prebuild binaries.

To check installed versions:

Code: Select all

$ python3 plugin.py version
The syntax for configuring the gateway connection and selecting an api for coaps has changes slightly:

Code: Select all

$ python3 plugin.py config gw IP KEY
$ python3 plugin.py config api py3coap # for py3coap
$ python3 plugin.py config api coapcmd # for py3coap
For updating the plugin:

Code: Select all

$ cd plugins/IKEA-Tradfri
$ git pull
$ sudo -H python3 -m pip install -U tradfricoap py3coap
If tradfricoap has been installed into the plugin dirctory, update with git:

Code: Select all

$ cd plugins/IKEA-Tradfri/tradfricoap
$ git pull
Regards,
M
Last edited by moroen on Tuesday 27 October 2020 23:57, edited 1 time in total.
dressie
Posts: 156
Joined: Monday 25 May 2015 22:44
Target OS: Raspberry Pi / ODroid
Domoticz version: V2020.2
Location: Netherlands
Contact:

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

Post by dressie »

First I want to thank you for all your great work Moroen!
I followed your steps, but after a restart of Domoticz it still shows version 0.9.17.

Any thought?

With kind regards,
Andrès
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 »

dressie wrote: Tuesday 27 October 2020 10:01 First I want to thank you for all your great work Moroen!
I followed your steps, but after a restart of Domoticz it still shows version 0.9.17.

Any thought?

With kind regards,
Andrès
There was an error in my instructions, you need to checkout and pull the master branch. The original post has been corrected:

Code: Select all

$ cd plugins/IKEA-Tradfri
$ git checkout master
$ git pull
$ rm -rf tradfricoap
$ sudo -H pip3 install tradfricoap
Sorry! :)

Regards,
M
dressie
Posts: 156
Joined: Monday 25 May 2015 22:44
Target OS: Raspberry Pi / ODroid
Domoticz version: V2020.2
Location: Netherlands
Contact:

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

Post by dressie »

Yes! That seems to work! Thanks!
Jasper79
Posts: 85
Joined: Sunday 26 July 2020 8:37
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Netherlands
Contact:

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

Post by Jasper79 »

when entering checkout master this is the right reply right?

Code: Select all

Already on 'master'
Your branch is up to date with 'origin/master'.
and later on I get this

Code: Select all

WARNING: You are using pip version 20.1.1; however, version 20.2.4 is available.
You should consider upgrading via the '/usr/bin/python3 -m pip install --upgrade pip' command.

pi@raspberrypi:~/domoticz/plugins/IKEA-Tradfri $ /usr/bin/python3 -m pip install --upgrade pip
Defaulting to user installation because normal site-packages is not writeable
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting pip
  Downloading pip-20.2.4-py2.py3-none-any.whl (1.5 MB)
     |################################| 1.5 MB 2.4 MB/s
Installing collected packages: pip
  Attempting uninstall: pip
    Found existing installation: pip 20.2.3
    Uninstalling pip-20.2.3:
      Successfully uninstalled pip-20.2.3
Successfully installed pip-20.2.4

JimmyH1969
Posts: 153
Joined: Tuesday 28 June 2016 16:38
Target OS: Windows
Domoticz version: Beta
Location: Amersfoort NL
Contact:

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

Post by JimmyH1969 »

Hi Moroen,

I thought about updating my windows machine, so i downloaded the latest 32bit wheel (py3coap-0.8.0-cp37-cp37m-win32.whl) and installed it.
pip list shows: py3coap 0.8.0

Is it correct there is no 32bit version of the py3coap 0.9.0 ?
Do i need to go to a 64bit python? I dont think Domoticz works with a 64bit Python... not sure to...

I then updated the plugin to 0.10.0 and tried:
python plugin.py list
The response is: py3coap not found

Is this because i need py3coap 0.9.0? Did i mis something?
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 »

JimmyH1969 wrote: Thursday 29 October 2020 13:23 Hi Moroen,

I thought about updating my windows machine, so i downloaded the latest 32bit wheel (py3coap-0.8.0-cp37-cp37m-win32.whl) and installed it.
pip list shows: py3coap 0.8.0

Is it correct there is no 32bit version of the py3coap 0.9.0 ?
Do i need to go to a 64bit python? I dont think Domoticz works with a 64bit Python... not sure to...

I then updated the plugin to 0.10.0 and tried:
python plugin.py list
The response is: py3coap not found

Is this because i need py3coap 0.9.0? Did i mis something?
The win32 version of py3coap is missing in the latest build on pypi, I'll look into it!

Regards,
M
JimmyH1969
Posts: 153
Joined: Tuesday 28 June 2016 16:38
Target OS: Windows
Domoticz version: Beta
Location: Amersfoort NL
Contact:

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

Post by JimmyH1969 »

I just installed Python 3.7.9 64bit on a Domoticz test virtual machine.
Installed the plugin version 0.10.0
Installed py3coap 0.9.0
Installed tradfricoap 0.0.11

And.... :D
python plugin.py list
Lights:
65537: lamp keuken (State: 0 - Level: 71 - Hex: None)
65538: keuken verlichting (State: 0 - Level: 0 - Hex: None)
65540: buitenverlichting voor (State: 0 - Level: 2 - Hex: None)
65541: Woonkamer (State: 0 - Level: 2 - Hex: efd275)
65544: aanbouw 1 (State: 1 - Level: 91 - Hex: None)
65545: aanbouw 2 (State: 1 - Level: 5 - Hex: None)


Domoticz says: PluginSystem: Failed dynamic library load, install the latest libpython3.x library that is available for your platform.
This is because of the 64bit version of Python ofcourse.

Thanks in advance ;)
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 »

JimmyH1969 wrote: Thursday 29 October 2020 15:42 I just installed Python 3.7.9 64bit on a Domoticz test virtual machine.
Installed the plugin version 0.10.0
Installed py3coap 0.9.0
Installed tradfricoap 0.0.11

And.... :D
python plugin.py list
Lights:
65537: lamp keuken (State: 0 - Level: 71 - Hex: None)
65538: keuken verlichting (State: 0 - Level: 0 - Hex: None)
65540: buitenverlichting voor (State: 0 - Level: 2 - Hex: None)
65541: Woonkamer (State: 0 - Level: 2 - Hex: efd275)
65544: aanbouw 1 (State: 1 - Level: 91 - Hex: None)
65545: aanbouw 2 (State: 1 - Level: 5 - Hex: None)


Domoticz says: PluginSystem: Failed dynamic library load, install the latest libpython3.x library that is available for your platform.
This is because of the 64bit version of Python ofcourse.

Thanks in advance ;)
If you compile domoticz yourself, it's possible to support 64 bits python, but it's probably not worth the hassle... 8-)

py3coap version 0.9.1 just released on pypi. This version is the same as 0.9.0, but with wheels for win32 included, support for python3.5 has been removed.

Regards,
M
JimmyH1969
Posts: 153
Joined: Tuesday 28 June 2016 16:38
Target OS: Windows
Domoticz version: Beta
Location: Amersfoort NL
Contact:

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

Post by JimmyH1969 »

Mhhh.... i installed py3coap version 0.9.1

Pip list:
py3coap 0.9.1

Copied the plugin to the Domoticz plugin folder.

Executed: python.exe plugin.py list
Result: py3coap not found

On my 64bit python machine the same configuration works without problems. Did i miss something? :(
JimmyH1969
Posts: 153
Joined: Tuesday 28 June 2016 16:38
Target OS: Windows
Domoticz version: Beta
Location: Amersfoort NL
Contact:

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

Post by JimmyH1969 »

Removed py3coap-0.9.1 and installed py3coap-0.8.0
Removed plugin 0.10.0 and installed plugin 0.9.1

Everything works again, but there is a pause between switching 2 lights, that's why i wanted to update :D
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 »

JimmyH1969 wrote: Thursday 29 October 2020 23:11 Removed py3coap-0.9.1 and installed py3coap-0.8.0
Removed plugin 0.10.0 and installed plugin 0.9.1

Everything works again, but there is a pause between switching 2 lights, that's why i wanted to update :D
I'll see if I can dig out a copy of Windows and do some testing. If it's any consolation, the 0.9.1 version doesn't solve the delay between switching lights, that's due to a workaround for a recent firmware update...

Regards,
M
JimmyH1969
Posts: 153
Joined: Tuesday 28 June 2016 16:38
Target OS: Windows
Domoticz version: Beta
Location: Amersfoort NL
Contact:

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

Post by JimmyH1969 »

Oke, to solve my problems for now i went back to the stone age .... :D

Removed py3coap completely
Installed pycoap-0.7.0-cp37-cp37m-win32
Installed Plugin 0.7.3

I think thats the last possibe combination of pycoap and the plugin ;)

Everything works fine. No delays in switching lights.
I think i missed the why and when going from pycoap to py3coap...

Anyway, for now it works!
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 »

JimmyH1969 wrote: Friday 30 October 2020 13:34 Oke, to solve my problems for now i went back to the stone age .... :D

Removed py3coap completely
Installed pycoap-0.7.0-cp37-cp37m-win32
Installed Plugin 0.7.3

I think thats the last possibe combination of pycoap and the plugin ;)

Everything works fine. No delays in switching lights.
I think i missed the why and when going from pycoap to py3coap...

Anyway, for now it works!
Hm, that's interresting, what is the firmware version of your IKEA gateway?
JimmyH1969
Posts: 153
Joined: Tuesday 28 June 2016 16:38
Target OS: Windows
Domoticz version: Beta
Location: Amersfoort NL
Contact:

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

Post by JimmyH1969 »

Hi,

The IKEA App says it's on the latest version... not sure ofcourse
The HUB says: version 1.11.51

Is that the latest?
Jasper79
Posts: 85
Joined: Sunday 26 July 2020 8:37
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Netherlands
Contact:

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

Post by Jasper79 »

FYI 1.11.51 also latest version number on my set up.

Don't know if someone already looked at the question I posted earlier?
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 »

Jasper79 wrote: Thursday 29 October 2020 11:26 when entering checkout master this is the right reply right?

Code: Select all

Already on 'master'
Your branch is up to date with 'origin/master'.
and later on I get this

Code: Select all

WARNING: You are using pip version 20.1.1; however, version 20.2.4 is available.
You should consider upgrading via the '/usr/bin/python3 -m pip install --upgrade pip' command.

pi@raspberrypi:~/domoticz/plugins/IKEA-Tradfri $ /usr/bin/python3 -m pip install --upgrade pip
Defaulting to user installation because normal site-packages is not writeable
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting pip
  Downloading pip-20.2.4-py2.py3-none-any.whl (1.5 MB)
     |################################| 1.5 MB 2.4 MB/s
Installing collected packages: pip
  Attempting uninstall: pip
    Found existing installation: pip 20.2.3
    Uninstalling pip-20.2.3:
      Successfully uninstalled pip-20.2.3
Successfully installed pip-20.2.4

You should always do a git pull after checking out a branch, but yes, this looks correct!

Regards,
M
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest