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

Python and python framework

Moderator: leecollings

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 »

After one of those "why haven't I thought about that before"-moments, the latest commit to github now introduces the following rather major changes:
  1. The version of plugin.py and tradfri.tac now are the same for both stable and beta versions of domoticz. No more matching master branch with stable domoticz and development branch for beta domoticz, the master branch is where it's at (At least until, if ever, the python framework changes it's API again in such a manner that a unified plugin.py is not maintainable).
  2. As a result of this, the default branch for the plugin has changed back to master, which should be suitable for most users.
  3. The handling of ident/psk has changed for stable domoticz. The adapter need to be configured from the command-line

    Code: Select all

    $ ./configure.py GATEWAY_IP GATEWAY_MASTER_KEY 
    and the settings for the IKEA-plugin on the hardware-page needs to be updated, as described in the readme
  4. Stable domoticz now have support for the IKEA-sockets.
As always, I have only tested this on my own system, both for stable and beta, so no guarantees, please report any errors etc, and I'll do my best to fix them...

Regards,
M
Mambobuzzz
Posts: 8
Joined: Saturday 20 October 2018 18:09
Target OS: Windows
Domoticz version:
Contact:

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

Post by Mambobuzzz »

Hi there,

is it worth installing on Windnows Domoticz? Is it stable?
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 »

Mambobuzzz wrote: Saturday 20 October 2018 18:11 Hi there,

is it worth installing on Windnows Domoticz? Is it stable?
I haven't used Windows for years, so I really don't know. I would guess it should work, at least if you create a docker image with the adapter.

Regards,
M
htilly
Posts: 14
Joined: Saturday 09 January 2016 22:05
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Stockholm
Contact:

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

Post by htilly »

Probably stupid question but here it goes.
For the IKEA trådfri lamps.. do I really need to buy an additional remote / dimmer for each lamp? I know it makes sense when you use it as intended =) But when controlling them from domoticz I couldn't care less about the remote.. and the cost..

So I guess the question is:
Is there any way of getting multiple light bulbs in domoticz with just one remote?

BR
Tilly
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 »

htilly wrote: Tuesday 23 October 2018 20:21 Probably stupid question but here it goes.
For the IKEA trådfri lamps.. do I really need to buy an additional remote / dimmer for each lamp? I know it makes sense when you use it as intended =) But when controlling them from domoticz I couldn't care less about the remote.. and the cost..

So I guess the question is:
Is there any way of getting multiple light bulbs in domoticz with just one remote?

BR
Tilly
Yes, there is, you can pair more than one bulb to a remote...

Actually you can use a remote to pair a bulb with the gateway and then forget about the remote until you use it again for pairing another bulb to the gateway, forget it and use it again for another bulb and repeat... Just use "Add device" in the IKEA app, and use whatever remote you have handy to complete the pairing. You can then use the IKEA app to create new groups and move bulbs between them, the groups will be displayed as a device in domoticz if enabled in the plugin.

The only reason (as far as I can see anyway) to actually care about which remote you use, is if you intend to use the remote as an actual remote and control the bulbs as a group. I think there is a limit to how many bulbs that can be paired to one remote, but if you just use a remote to pair a bulb to the gateway, it shouldn't matter...

There is support for initiating pairing without the app using pytradfri, but I haven't figured out how to enable such a function in domoticz, the things that can be done on the hardware setup-page is quite limited... Perhaps I'll try to make a command line utility for it one day I'm bored... :roll:

Regards,
M
jakkes72
Posts: 23
Joined: Sunday 10 January 2016 20:37
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post by jakkes72 »

I tried to install this plugin according this link:
https://github.com/moroen/IKEA-Tradfri-plugin


Everything goes fine till i enter this command:
pi@Domoticz:~/domoticz/plugins/IKEA-Tradfri $ sudo ./configure.py 10.60.y.z code
Traceback (most recent call last):
File "./configure.py", line 3, in <module>
from pytradfri import Gateway
File "/usr/local/lib/python3.4/dist-packages/pytradfri/__init__.py", line 5, in <module>
from .gateway import Gateway
File "/usr/local/lib/python3.4/dist-packages/pytradfri/gateway.py", line 16, in <module>
from .smart_task import SmartTask
File "/usr/local/lib/python3.4/dist-packages/pytradfri/smart_task.py", line 34, in <module>
from .util import BitChoices
File "/usr/local/lib/python3.4/dist-packages/pytradfri/util.py", line 5, in <module>
from typing import Union, List, Dict
ImportError: No module named 'typing'
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 »

jakkes72 wrote: Thursday 25 October 2018 20:47 I tried to install this plugin according this link:
https://github.com/moroen/IKEA-Tradfri-plugin


Everything goes fine till i enter this command:
pi@Domoticz:~/domoticz/plugins/IKEA-Tradfri $ sudo ./configure.py 10.60.y.z code
Traceback (most recent call last):
ImportError: No module named 'typing'
Which version of python are you using? The typing module is part of the standard library from python3.5 and upwards, and you need to use python3.5 or newer...

Regards,
M
jakkes72
Posts: 23
Joined: Sunday 10 January 2016 20:37
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post by jakkes72 »

pi@Domoticz:~ $ python -V
Python 2.7.9

After i did a install in this link:
http://www.ramoonus.nl/2018/06/30/insta ... pberry-pi/

It reports:
pi@Domoticz:~/domoticz/plugins/IKEA-Tradfri $ python -V
Python 3.7.0

pi@Domoticz:~/domoticz/plugins/IKEA-Tradfri $ sudo ./configure.py 10.60.x.x code
Traceback (most recent call last):
File "./configure.py", line 3, in <module>
from pytradfri import Gateway
File "/usr/local/lib/python3.4/dist-packages/pytradfri/__init__.py", line 5, in <module>
from .gateway import Gateway
File "/usr/local/lib/python3.4/dist-packages/pytradfri/gateway.py", line 16, in <module>
from .smart_task import SmartTask
File "/usr/local/lib/python3.4/dist-packages/pytradfri/smart_task.py", line 34, in <module>
from .util import BitChoices
File "/usr/local/lib/python3.4/dist-packages/pytradfri/util.py", line 5, in <module>
from typing import Union, List, Dict
ImportError: No module named 'typing'

So i did a restart of the system, and again:
pi@Domoticz:~ $ python -V
Python 2.7.9

I Think i will start again with a fresh install of Raspbian/Domoticz...
jakkes72
Posts: 23
Joined: Sunday 10 January 2016 20:37
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post by jakkes72 »

Did a fresh install, installen python 3.5, but get this error..
./configure.py IP CODE
Traceback (most recent call last):
File "./configure.py", line 3, in <module>
from pytradfri import Gateway
ImportError: No module named 'pytradfri'

pyttradfi is installed:
sudo pip3 install pytradfri
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already satisfied: pytradfri in /usr/local/lib/python3.5/dist-packages (6.0.1)
User avatar
heggink
Posts: 972
Joined: Tuesday 08 September 2015 21:44
Target OS: Raspberry Pi / ODroid
Domoticz version: 12451
Location: NL
Contact:

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

Post by heggink »

Sounds like a familiar problem using python on pi3. At some point I had multiple subfolders (python3, python 3.4, 3.5 and 3.6) with libraries spread over most of then. Domoticz only had a few in it's path do no dice. 3 options: 1) fix and revert to one release but no idea how, 2) add path using PYTHONPATH in domoticz startup script or 3) append the path in the python file itself but then everyone would need to do that for themselves...
Docker in Truenas scale, close to latest beta
DASHTICZ 🙃
RFXCOM, zwavejs2mqtt, zigbee2mqtt,
P1 meter & solar panel
Google home, Wifi Cams motion detection
Geofence iCloud, Bluetooth & Wifi ping
Harmony hub, Nest, lots more :-)
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 »

heggink wrote: Monday 29 October 2018 19:57 Sounds like a familiar problem using python on pi3. At some point I had multiple subfolders (python3, python 3.4, 3.5 and 3.6) with libraries spread over most of then. Domoticz only had a few in it's path do no dice. 3 options: 1) fix and revert to one release but no idea how, 2) add path using PYTHONPATH in domoticz startup script or 3) append the path in the python file itself but then everyone would need to do that for themselves...
The configure.py and tradfri.tac files both use the default python3 interpreter. The version of python used by domoticz (as long as it's 3.5 or higher) really don't matter, it's only tradfri.tac (and configure.py) that needs pytradfri. To make sure that pip installs the library for the default interpreter (which usually, but not always, is the one found first in the path):

First make sure that the default python3 is version 3.5 or higher:

Code: Select all

$ python3 --version
Then force pip to install libraries for the default interpreter:

Code: Select all

python3 -m pip install pytradfri
Regards,
M
jakkes72
Posts: 23
Joined: Sunday 10 January 2016 20:37
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post by jakkes72 »

Quick answers! great!

Now i get this:
pi@Domoticz:~ $ python3 --version
Python 3.5.2
pi@Domoticz:~ $ python3 -m pip install pytradfri
/usr/local/bin/python3: No module named pip
pi@Domoticz:~ $

pi@Domoticz:~ $ sudo apt-get install python3-pip
Reading package lists... Done
Building dependency tree
Reading state information... Done
python3-pip is already the newest version (9.0.1-2+rpt2).
0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.
pi@Domoticz:~ $ pip3 --version
pip 18.1 from /usr/local/lib/python3.5/dist-packages/pip (python 3.5)
User avatar
heggink
Posts: 972
Joined: Tuesday 08 September 2015 21:44
Target OS: Raspberry Pi / ODroid
Domoticz version: 12451
Location: NL
Contact:

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

Post by heggink »

moroen wrote: Monday 29 October 2018 20:44
heggink wrote: Monday 29 October 2018 19:57 Sounds like a familiar problem using python on pi3. At some point I had multiple subfolders (python3, python 3.4, 3.5 and 3.6) with libraries spread over most of then. Domoticz only had a few in it's path do no dice. 3 options: 1) fix and revert to one release but no idea how, 2) add path using PYTHONPATH in domoticz startup script or 3) append the path in the python file itself but then everyone would need to do that for themselves...
The configure.py and tradfri.tac files both use the default python3 interpreter. The version of python used by domoticz (as long as it's 3.5 or higher) really don't matter, it's only tradfri.tac (and configure.py) that needs pytradfri. To make sure that pip installs the library for the default interpreter (which usually, but not always, is the one found first in the path):

First make sure that the default python3 is version 3.5 or higher:

Code: Select all

$ python3 --version
Then force pip to install libraries for the default interpreter:

Code: Select all

python3 -m pip install pytradfri
Regards,
M
so how di I force python stuff to be reinstalled on the newer python releases if it e.g. was installed on 3.4 before where python was upgraded later? I have all of these python 3.4/3.5 remnants and can't possibly believe that you need to reinstall all these packages again just to be found in the latest path so domoticz can use them...
Docker in Truenas scale, close to latest beta
DASHTICZ 🙃
RFXCOM, zwavejs2mqtt, zigbee2mqtt,
P1 meter & solar panel
Google home, Wifi Cams motion detection
Geofence iCloud, Bluetooth & Wifi ping
Harmony hub, Nest, lots more :-)
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 »

jakkes72 wrote: Monday 29 October 2018 21:20 Quick answers! great!

Now i get this:
pi@Domoticz:~ $ python3 --version
Python 3.5.2
pi@Domoticz:~ $ python3 -m pip install pytradfri
/usr/local/bin/python3: No module named pip
pi@Domoticz:~ $

pi@Domoticz:~ $ sudo apt-get install python3-pip
Reading package lists... Done
Building dependency tree
Reading state information... Done
python3-pip is already the newest version (9.0.1-2+rpt2).
0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.
pi@Domoticz:~ $ pip3 --version
pip 18.1 from /usr/local/lib/python3.5/dist-packages/pip (python 3.5)
This is strange. Can you import pytradfri from interactive python?

Code: Select all

$ python3
Python 3.7.0 (default, Oct  2 2018, 09:18:58)
[Clang 10.0.0 (clang-1000.11.45.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pytradfri
That last line should give no error or any messages of any kind...

Regards,
M
jakkes72
Posts: 23
Joined: Sunday 10 January 2016 20:37
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post by jakkes72 »

Correct:
pi@Domoticz:~ $ python3
Python 3.5.2 (default, Oct 29 2018, 18:04:21)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pytradfri
>>>

But running the same command in the domoticz/plugins/IKEA folder fails:


pi@Domoticz:~/domoticz/plugins/IKEA-Tradfri $ python3
Python 3.5.2 (default, Oct 29 2018, 18:04:21)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pytradfri
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'pytradfri'
>>>

Some path error...?
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 »

jakkes72 wrote: Tuesday 30 October 2018 7:58 Correct:
pi@Domoticz:~ $ python3
Python 3.5.2 (default, Oct 29 2018, 18:04:21)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pytradfri
>>>

But running the same command in the domoticz/plugins/IKEA folder fails:


pi@Domoticz:~/domoticz/plugins/IKEA-Tradfri $ python3
Python 3.5.2 (default, Oct 29 2018, 18:04:21)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pytradfri
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'pytradfri'
>>>

Some path error...?
Do you by any chance have a directory named pytradfri in the plugin-folder?

Regards,
M
jakkes72
Posts: 23
Joined: Sunday 10 January 2016 20:37
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post by jakkes72 »

I did not have a folder name pytradfri in /home/pi/domoticz/plugins. I copied a folder with the files from pytradfri in that directory, but no luck..
I have folders with that name in:
pi@Domoticz:/ $ sudo find -name pytradfri
./usr/local/lib/python3.5/dist-packages/pytradfri
./usr/lib/python3.5/pytradfri
./home/pi/pytradfri/pytradfri
./home/pi/domoticz/plugins/pytrafri/pytradfri (I copied the contents of /home/pi/pytradfri/pytradfri to this directory)
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 »

jakkes72 wrote: Wednesday 31 October 2018 20:50 I did not have a folder name pytradfri in /home/pi/domoticz/plugins. I copied a folder with the files from pytradfri in that directory, but no luck..
I have folders with that name in:
pi@Domoticz:/ $ sudo find -name pytradfri
./usr/local/lib/python3.5/dist-packages/pytradfri
./usr/lib/python3.5/pytradfri
./home/pi/pytradfri/pytradfri
./home/pi/domoticz/plugins/pytrafri/pytradfri (I copied the contents of /home/pi/pytradfri/pytradfri to this directory)
This is somewhat baffling, I really don't understand why the same python interpreter finds a module when started in one directory and fails to find the same module when started in another... I've been unable to reproduce this in any form... One more thing I would try, make sure to completely remove pytradfri before trying to reinstall it only once.

To remove all versions of the module first run:

Code: Select all

$ pip uninstall pytradfri
repetedly until pip reports that the module can't be found, then do the same using sudo:

Code: Select all

$ sudo pip uninstall pytradfri
Then remove ALL directories containing pytradfri (i.e find -name pytradfri), and then installing pytradfri using sudo. Just to make sure, find -name pytradfri again, and make sure that it's only found in ONE location...

Regards,
M
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 »

moroen wrote: Thursday 01 November 2018 13:43 Then remove ALL directories containing pytradfri (i.e find -name pytradfri), and then installing pytradfri using sudo. Just to make sure, find -name pytradfri again, and make sure that it's only found in ONE location...
And as a shoot in the dark, make sure that it's really the same interpreter (why it wouldn't be is beyond me, but just to make sure):

Code: Select all

mak@zwave:~$ which python3
/usr/bin/python3
mak@zwave:~$ cd /opt/domoticz/plugins/IKEA-Tradfri
mak@zwave:/opt/domoticz/plugins/IKEA-Tradfri$ which python3
/usr/bin/python3
Regards,
M
jakkes72
Posts: 23
Joined: Sunday 10 January 2016 20:37
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post by jakkes72 »

I did an uninstall of pytradfri, and removed all the directies.

pi@Domoticz:/ $ which python3
/usr/local/bin/python3
pi@Domoticz:/ $ cd /home/pi/domoticz/plugins/IKEA-Tradfri/
pi@Domoticz:~/domoticz/plugins/IKEA-Tradfri $ which python3
/usr/local/bin/python3

Installed pytradfri again:
sudo pip install pytradfri
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting pytradfri
Using cached https://www.piwheels.org/simple/pytradf ... ne-any.whl
Installing collected packages: pytradfri
Successfully installed pytradfri-6.0.1

pi@Domoticz:/ $ sudo find -name pytradfri
./usr/local/lib/python3.5/dist-packages/pytradfri

pi@Domoticz:~/domoticz/plugins/IKEA-Tradfri $ ./configure.py IP KEY
Traceback (most recent call last):
File "./configure.py", line 3, in <module>
from pytradfri import Gateway
ImportError: No module named 'pytradfri'

still no go...
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest