A Domoticz plugin for IKEA Trådfri (Tradfri) gateway
Since domoticz plugins doesn't support COAP and also doesn't allow threads or async calls, the IKEA-tradfri plugin contains two parts, the domoticz plugin and a python3 IKEA-tradfri adaptor written with the twisted framework. The adaptor needs to be running at all times, and is intented to be run as a service using systemd.
The plugin supports and is able to controll the following devices:
- All bulbs, with dimming for bulbs that are dimmable and setting white temperature/color for CW and CWS bulbs.
- Outlets / sockets
- Floalt LED Panels
The plugin doesn't work with:
- Motion sensors
- Remotes
Untested devices:
- Tradfri LED-drivers
- Domoticz compiled with support for Python-Plugins.
- Python library pytradfri by ggravlingen (https://github.com/ggravlingen/pytradfri). Required version: 6.0.1 or greater.
- Twisted (https://twistedmatrix.com/trac/)
- IKEA-Tradfri-plugin (https://github.com/moroen/IKEA-Tradfri-plugin)
The provided install-coap-client script will try to compile and install libcoap. Some steps will require root-access via sudo, and as such the scipt will ask for your password.
$ bash ./install-coap-client.sh
$ pip3 install pytradfri
$ pip3 install twisted
Note: Depending on the setup, it might be necessary to install twisted using sudo:
$ sudo pip3 install twisted
~/$ cd /opt/domoticz/plugins/
/opt/domoticz/plugins$ git clone https://github.com/moroen/IKEA-Tradfri-plugin.git IKEA-Tradfri
$ ./configure.py IP GATEWAY-KEY
where IP is the address of the gateway, and GATEWAY-KEY is the security-key located on the bottom of the gateway.
/opt/domoticz/plugins/IKEA-Tradfri$ python3 tradfri.tac
- Create a (reasonably sane) systemd-service file:
$ ./configure.py --skip-config --create-service
This should be run from the IKEA-Tradfri directoy, and as the user indented to run the adapter.
- Verify that the generated ikea-tradfri.service-file has the correct paths and user, then copy the service-file to systemd-service directory, reload systemd-daemon and start the IKEA-tradfri service:
/opt/domoticz/plugins/IKEA-Tradfri$ sudo cp ikea-tradfri.service /etc/systemd/system
/opt/domoticz/plugins/IKEA-Tradfri$ sudo systemctl daemon-reload
/opt/domoticz/plugins/IKEA-Tradfri$ sudo systemctl start ikea-tradfri.service
$ sudo systemctl enable ikea-tradfri.service
Input the IP of the host where the adapter is running. NOTE: This is NOT the IP of the IKEA-Tradfri gateway. When running domoticz and the adapter on the same machine, the default IP (localhost / 127.0.0.1) should work.
To get domoticz to recognize changed states (using IKEA-remote, app or any other way of switching lights), observe changes must be enabled in the plugin-settings page and a reasonable polling intervall specified.
After upgrading to the lastest version, make sure to configure the adapter as described above.
Then restart domoticz and on the hardware-page, select the IKEA-Plugin, change the IP from the previous address (IKEA-Gateway) to the host running the adapter, and press "Update".
Put IKEA gateway IP and preshared key from sticker into GW_config file.
To run the plugin in a Docker (for example to on a Synology NAS), package the adapter using the provided Docker build file:
docker build -t ikea-tradfri-plugin:latest .
RPI docker build:
docker build -t ikea-tradfri-plugin:latest . -f DockerfileRPI
Copy the docker image to the system running Domoticz and start the Docker instance:
docker run --env-file=GW_config -t -p 127.0.0.1:1234:1234 ikea-tradfri-plugin:1234
config.json file will be created automaticaly.
Now the IKEA Tradfri to Domoticz adaptor is available on the localhost.
Clone IKEA-tradfri plugin into Domoticz plugins-directory
~/$ cd /opt/domoticz/plugins/
/opt/domoticz/plugins$ git clone https://github.com/moroen/IKEA-Tradfri-plugin.git IKEA-Tradfri
Restart Domoticz and the plugin should show up. When the plugin is loaded, the adaptor running in the Docker is automatically used.
Lights and devices have to be added to the gateway as per IKEA's instructions, using the official IKEA-tradfri app.