Getting started with Home assistant to automate your IKEA Trådfri or Philips Hue lights, using a Raspberry Pi and Conbee, the docker way
Hardware used in this writeup
- Raspberry Pi 3
- IKEA Trådfri E27 1000 lm bulb
- OS: Raspbian Stretch
- Docker 18.06
- Home Assistant 0.80
- deCONZ 2.05.39 / 9/22/2018
Installing Docker, Home Assistant, deCONZ
0 Install Docker if not already installed
curl -fsSL get.docker.com -o get-docker.sh && sh get-docker.sh
1 Install Home assistant
docker run -d \ --name="home-assistant" \ -v /home/pi/homeassistant:/config \ -v /etc/localtime:/etc/localtime:ro \ --net=host \ --restart=always \ homeassistant/raspberrypi3-homeassistant
In a short while you should be able to browse to http://ip-of-your-pi:8123
2 Install deCONZ
deCONZ is the software provided by Dresden Elektronik that controls connected Zigbee devices, such as lights. Make sure your Conbee is plugged in.
docker run -d \ --name=deconz \ --net=host \ --restart=always \ --/etc/localtime:/etc/localtime:ro \ -v /opt/deconz:/root/.local/share/dresden-elektronik/deCONZ \ --device=/dev/ttyUSB0 \ -e DECONZ_WEB_PORT=8080 \ -e DECONZ_WS_PORT=8443 \ marthoc/deconz
Ref: https://github.com/marthoc/docker-deconz Note: deCONZ by default listens on port 80 and 443, which is a problem if you want to run a web server, hence this snippet sets deCONZ to use port 8080 instead
Setting up the lights
I had some trouble adding my Trådfri lights. First of all deconz seem only to accept http connections from 127.0.0.1, so if you’re running your Pi headless you first need to set up an SSH tunnel. ssh -L 8080:localhost:8080 pi@pi
- Now point your web browser to http://localhost:8080
- Set a password
- For me, some bug in deCONZ wouldn’t let me log in. Google eventually led me to http://localhost:8080/edit_system.html
- Now logging in works..!
- Power on your light bulb close to the Conbee
- Menu -> Devices -> Lights -> Add new light
- Set a useful name, such as “Kitchen window”
Experiencing a lot off issues with deCONZ Web GUI.
Pairing the light is also a bit tricky. Using the reset sequence (on-off 6 times), deCONZ eventually found a Trådfri bulb.
Connecting deCONZ to Home assistant
- Log onto Home assistant http://pi:8123
- Menu -> Configuration -> Integration -> Set up a new integration -> deCONZ Zigbee gateway -> Configure
- Go back to deCONZ PWA
- Menu -> Gateway -> Advanced
- “Authenticate app”
- In Home assistant, click “I have pressed the button”
Grouping lights in Home assistant
# /home/pi/homeassistant/groups.yaml kitchen: name: Kitchen view: yes entities: - light.kitchen
# /home/pi/homeassistant/automations.yaml - alias: Lighten up trigger: - platform: sun event: sunset offset: "-00:30:00" - platform: time at: '06:00:00' action: service: light.turn_on entity_id: group.all_lights - alias: Lights out trigger: - platform: sun event: sunrise offset: "00:30:00" - platform: time at: '01:00:00' action: service: light.turn_off entity_id: group.all_lights
If you made it this far, your lights should turn on half an hour before sunset and at 6 AM, they should also go dark a half hour after sunrise, and at 1 AM.