Skip to content

Commit

Permalink
Merge branch 'aiocoap'
Browse files Browse the repository at this point in the history
  • Loading branch information
moroen committed Aug 15, 2019
2 parents 63e5fbf + 4c069b8 commit 007ced4
Show file tree
Hide file tree
Showing 15 changed files with 641 additions and 541 deletions.
9 changes: 9 additions & 0 deletions .bumpversion.cfg
@@ -0,0 +1,9 @@
[bumpversion]
current_version = 2.0.0
commit = False
tag = False

[bumpversion:file:plugin.py]

[bumpversion:file:setup.py]

100 changes: 100 additions & 0 deletions .gitignore
@@ -1,3 +1,4 @@
<<<<<<< HEAD
# Envir
.direnv/
.vscode/
Expand All @@ -9,3 +10,102 @@
__pycache__
.eggs
*.egg-info
=======
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg
.pytest_*/

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
.hypothesis/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# IPython Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# dotenv
.env

# virtualenv
venv/
ENV/
.envrc
.direnv/

# Spyder project settings
.spyderproject

# Rope project settings
.ropeproject

# Visual Studio
.vs/
.vscode/

>>>>>>> aiocoap
2 changes: 0 additions & 2 deletions GW_config

This file was deleted.

135 changes: 58 additions & 77 deletions README.md
Expand Up @@ -2,7 +2,7 @@ A Domoticz plugin for IKEA Trådfri (Tradfri) gateway

# Plugin

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.
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. The adaptor needs to be running at all times, and is intented to be run as a service using systemd.

# What's supported
The plugin supports and is able to controll the following devices:
Expand All @@ -11,55 +11,65 @@ The plugin supports and is able to controll the following devices:
- Floalt LED Panels
- Tradfri LED-drivers

The plugin partly works with:
- Remotes - It's possible to monitor battery levels, but not using a tradfri remote to controll lights through domoticz

The plugin doesn't work with:
- Motion sensors
- Remotes


## Requirements:
1. Python version 3.5.3 or higher
1. Python version 3.5.3 or higher, 3.7.x recommended.
2. Domoticz compiled with support for Python-Plugins.
3. Python library pytradfri by ggravlingen (https://github.com/ggravlingen/pytradfri). Required version: 6.0.1.
4. Twisted (https://twistedmatrix.com/trac/)
5. IKEA-Tradfri-plugin (https://github.com/moroen/IKEA-Tradfri-plugin)
3. IKEA-Tradfri command line utility (https://github.com/moroen/ikea-tradfri)


## Local Installation
### Install required tools and libraries
```shell
$ sudo apt-get install build-essential autoconf automake libtool
### 1. Clone IKEA-tradfri plugin into domoticz plugins-directory
```
$ cd domoticz/plugins/
$ git clone https://github.com/moroen/IKEA-Tradfri-plugin.git IKEA-Tradfri
$ cd IKEA-Tradfri
```

### 2. Install libcoap

The provided install-coap-client script will try to download, compile and install libcoap. Some steps will require root-access via sudo, and as such the scipt will ask for your password.
### 2. Virtual python environment
Using a virtual environment is supported and recommended. Any python virtual environment tool should work, built in is recommended:
```shell
$ bash ./install-coap-client.sh
$ python3 -m venv env
$ source env/bin/activate
```

### 3. Install pytradfri-library
### 3. Update pip and setuptools
```shell
$ pip3 install pytradfri
$ pip3 install --upgrade pip
$ pip3 install --upgrade setuptools
```

### 4. Install twisted
```
$ pip3 install twisted
```
Note: Depending on the setup (i.e raspbian), it might be necessary to install twisted using sudo:
### 4. Install tradfri command line tool and required python packages
```shell
$ python3 setup.py install
```
$ sudo pip3 install twisted
#### Note: For python 3.5.3, install using setup.py fails intermittently. Installing required packages with pip before running setup.py works around this issue:
```shell
$ pip3 install -r requirements.txt
$ python3 setup.py install
```

### 5. 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
### 4. Configure the Tradfri COAP-adapter:
```shell
$ tradfri config gateway IP KEY
```
* IP is the address of the gateway, and KEY is the security-key located on the bottom of the gateway.

### 6. Configure the Tradfri COAP-adapter:
### 5. Check communication with the gateway:
```shell
$ ./configure.py config IP GATEWAY-KEY
$ tradfri list
```
where IP is the address of the gateway, and GATEWAY-KEY is the security-key located on the bottom of the gateway.
For a full set of commands, try:
```shell
$ tradfri --help
```
* Note: The tradfri command line tool is a work in progress, some commands might not work as expected or indeed work at all!

If configure.py fails, try running with the debug option:
```shell
Expand All @@ -69,23 +79,28 @@ If configure.py fails, try running with the debug option:
### 7. Enable COAP-adaptor

#### From prompt (for testing)
```shell
$ tradfri -v server
```
/opt/domoticz/plugins/IKEA-Tradfri$ python3 tradfri.tac

#### From prompt (for debug)
```shell
$ tradfri -vv server
```

#### Using systemd
1. Create a (reasonably sane) systemd-service file:
```shell
$ ./configure.py service create
$ tradfri service create
```

This should be run from the IKEA-Tradfri directoy, and as the user indented to run the adapter. To specify another user or group, use the --user and --group flags:
- This should be run from the IKEA-Tradfri directory. If the tradfri command line tool has been installed in a virtual environment, make sure the virtual environment is activated before creating the service-file.

- By default, the service-file will set the service to run as the user running the tradfri command. To specify another user or group, use the --user and --group flags:

```shell
$ ./configure.py service create --user domoticz --group domogroup
$ tradfri service create --user domoticz --group domogroup
```

Note: If only --user is specified, the group will be set to the same name as the user
* Note: If only --user is specified, the group will be set to the same name as the user

2. 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:
```shell
Expand All @@ -94,65 +109,31 @@ Note: If only --user is specified, the group will be set to the same name as the
$ sudo systemctl start ikea-tradfri.service
```

Optionally use configure.py to install the service-file in the correct location:
3. Using systemd to start the COAP-adaptor on startup
```shell
$ ./configure.py service install
$ sudo systemctl daemon-reload
$ sudo systemctl start ikea-tradfri.service
```

#### Using systemd to start the COAP-adaptor on startup
```
$ sudo systemctl enable ikea-tradfri.service
```

### 7. Restart domoticz and enable IKEA-Tradfri from the hardware page
### 6. Restart domoticz and enable IKEA-Tradfri from the hardware page
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.

### Observing changes
To observe changes to buld or socket when switched using another method than domoticz, enable "Observe changes" and specify a poll interval in seconds. As long an intervall as possible is recommended. The mininum poll intervall is 5, and the intervall should be a multiple of 5.
To observe changes to buld or socket when switched using another method than domoticz, enable "Observe changes" and specify a poll interval in seconds. As long an intervall as possible is recommended. The mininum poll intervall is 5, and the intervall should be a multiple of 5 seconds. Using a too short interval tends to freeze the gateway, requiring cycling the power of the gateway to restore communication. A polling interval of 300 seconds or greater seems to be fine and reduce the occurence of freezes.

### Upgrading from previous version of the plugin and adapter
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".

## Docker Installation
All regular devices (light, sockets, drivers) should upgrade without intervension. The code for color devices (white balance and full color) has been completely rewritten, and on first upgrade the old color devices will be removed and new devices for setting white balanse (WS) and color (CWS) will be created.

Put IKEA gateway IP and preshared key from sticker into GW_config file.
### A note about colors
When using a CWS (color) bulb, a CWS color selector device is created. Due to a known limitation when setting levels in Domoticz scenes, it's only possible to specify the first half of the available colors in a scene. Selecting a color from the last half, gives the color for level 100 (lime) when the scene is activated. A workaround for this is planned, but currently not implemented.

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 -d \
--name ikea-tradfri-plugin \
--restart unless-stopped \
--env-file=GW_config \
-p 1234:1234 \
ikea-tradfri-plugin
```
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
```
## Docker Installation

Restart Domoticz and the plugin should show up. When the plugin is loaded, the adaptor running in the Docker is automatically used.
It's possible to run the adapter as a docker container app. Please refer to IKEA-tradfri (https://github.com/moroen/ikea-tradfri) for instructions.

## Usage
Lights and devices have to be added to the gateway as per IKEA's instructions, using the official IKEA-tradfri app.
6 changes: 0 additions & 6 deletions adapter_start.sh

This file was deleted.

0 comments on commit 007ced4

Please sign in to comment.