Automating Trådfri or Hue lights with Home Assistant and Conbee

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
  • Conbee
  • IKEA Trådfri E27 1000 lm bulb

Software

  • 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

Ref: https://medium.freecodecamp.org/the-easy-way-to-set-up-docker-on-a-raspberry-pi-7d24ced073ef

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

Ref: https://www.home-assistant.io/docs/installation/docker/

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

  1. Now point your web browser to http://localhost:8080
  2. Set a password
  3. For me, some bug in deCONZ wouldn’t let me log in. Google eventually led me to http://localhost:8080/edit_system.html
  4. Now logging in works..!
  5. Power on your light bulb close to the Conbee
  6. Menu -> Devices -> Lights -> Add new light
  7. Set a useful name, such as “Kitchen window”

deCONZ login trouble

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

  1. Log onto Home assistant http://pi:8123
  2. Menu -> Configuration -> Integration -> Set up a new integration -> deCONZ Zigbee gateway -> Configure
  3. Go back to deCONZ PWA
  4. Menu -> Gateway -> Advanced
  5. “Authenticate app”
  6. 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

Automating lights

# /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

Conclusion

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.

Home assistant

Credits

https://snillevilla.se/styr-ikea-tradfri-lampor-i-home-assistant-med-conbee/


Add a comment