Home Assistant Docker Conbee 2 and Zigbee2MQTT / deCONZ

Diese Seite gibt es auch in Deutsch

Thanks to numerous integration options, Home Assistantis a simple platform for controlling a wide range of smart home devices. Compared to ioBroker, I found it much easier to get started with Home Assistant. While for ioBroker I was still looking for which frontend I could use for my dashboards, with Home-Assistant I had a ready-made system out of the box. Home Assistant's Lovelance dashboards can be easily clicked together in the GUI and adapted almost at will for special customizations in the code editor and with additional frontend packages. 

I use Home-Assistant primarily for controlling certain lamps or the awning via the smartphone. I also use it to monitor the temperature and humidity of certain rooms, my heating, the front door, a NAS and a web server. In addition, I have hung something like a weather station on the wall on the basis of an old smartphone. Now I can see the temperature, the weather or other values in passing or start certain actions on it.

Home-Assistant - Docker startup

Docker Basics

Docker allows applications to be launched by command in a so-called container.
A container is an isolated environment independent of the operating system (OS):
So the OS does not matter, provided Docker can be installed.
When a container is first launched, Docker independently loads all the necessary sources
aus dem Internet.
Docker can be installed on Windows, macOS or an Linux Distribution
To start Home-Assistant in Docker, a Docker setup is of course required, see: Docker. Those who already have Docker set up can use it to start Home-Assistant with the following command:

docker run -d --name="home-assistant" \
-v ./:/config \
-v /etc/localtime:/etc/localtime:ro \
--net=host \
--restart=always \
homeassistant/home-assistant:stable

The network for Home-Assistant must be set to "--net=host" according to the manufacturer, but the ports used can also be defined: as an example when using a reverse proxy for access from the Internet, see: Access from the Internet - SSL Let's Encrypt.

First start: Initial configuration

After starting the container, Home-Assistantis accessible via port 8123 by default:

Devices and sensors can be added to HomeAssistant via so-called integrations:

Integrations

ZigBee integration with the ConBee 2 USB stick: 3 possible installation variants:

To enable me to control my ZigBee devices via Home-Assistant, I use a ConBee II USB stick. Information about the setup, see: Conbee 2: Phoscon deCONZ - Docker Startup | Review. Originally I used the manufacturer software of the ConBee 2 stick: deCONZ with the graphical user interface Phoscon. But alternatively ConBee 2 can be integrated directly into Home Assistant and as a third option via Zigbee2MQTT. With the last two variants, a cheaper ZigBee adapter can also be used, as an example: CC2652 or CC1352. When switching from one variant to the other, the end devices must be reconnected. I used deCONZ for about one year and then changed the setup to Zigbee2MQTT, which is also my recommendation from the current point of view.

1) ConBee 2 Manufacturer Software: deCONZ / Phoscon

If you already have ConBee and Phoscon in use, you have to set the Phoscon-GW to "Authenticate app" as preparation for the connection of Home Assistant:

Home Assistant already reports the detected deCONZ setup via the notification:

Alternatively, the integration can also be added in the Configuration menu item :

Details see, https://www.home-assistant.io/integrations/deconz/

2) Access to ConBee2, directly from HomeAssistant (Zigbee Home Automation: ZHA)

Alternatively to the connection of the ConBee stick via the deCONZ Zigbee gateway, the stick can also be integrated directly in Home Assistant. For this, Home Assistant, as well as the deCONZ container, must be started with the parameter "--device":

docker run -d --name="home-assistant" -v /docker/home-assistant-zigbee:/config -v /etc/localtime:/etc/localtime:ro --net=host --device=/dev/ttyACM0 homeassistant/home-assistant:stable

 

  

Devices that were previously connected to deCONZ cannot be used at this point, they have to be connected again:

Zigbee2MQTT is another alternative to deCONZ and ZHA:

3) Independent solution: Zigbee2MQTT

Zigbee2MQTT is a Zigbee bridge for communication between Zigbee and a MQTT broker. The setup with HomeAssistant consists of three components:

In Home-Assistant MQTT can be added to the integrations:

see: MQTT - Broker : Docker Setup, or my complete Docker Compose setup: Zigbee2MQTT- docker-compose.yml.

Compared to Phoscon, see: Zigbee2MQTT vs deCONZ and Phoscon.

System Monitor

To monitor the operating system - on which Home Assistant runs - in a rudimentary way, additional sensors can be added in configuration.yaml, as an example Disk and Memory:

configuraton.yaml:

sensor:
  - platform: systemmonitor
    resources:
      - type: disk_use_percent
        arg: /
      - type: disk_use_percent
        arg: /daten
      - type: memory_free    

Monitor server or Linux systems

If you want to monitor the status of other Linux systems, you can use the integration "Glances". Glances collects data about CPU, memory or the free space of a hard disk and much more. As a prerequisite, Glances must first be installed on the systems to be monitored, see also: Glances - Monitor Linux Server

Template sensor

A template sensor can be used to create sensors based on certain values, e.g. for sunrise and sunset:

configuraton.yaml

sensor:
  - platform: template
    sensors:
      nextsunrise:
        friendly_name: 'Sonnenaufgang'
        value_template: >
          {{ as_timestamp(states.sun.sun.attributes.next_rising) | timestamp_custom(' %H:%M') | replace(" 0", "") }}
        icon_template: mdi:weather-sunset-up
      nextsunset:
        friendly_name: 'Sonnenuntergang'
        value_template: >
          {{ as_timestamp(states.sun.sun.attributes.next_setting) | timestamp_custom(' %H:%M') | replace(" 0", "") }}
        icon_template: mdi:weather-sunset-down
      nextsunsetsunrise:
        friendly_name: 'Sonne'
        value_template: >
          {{ as_timestamp(states.sun.sun.attributes.next_rising) | timestamp_custom(' %H:%M') | replace(" 0", "") }} - {{ as_timestamp(states.sun.sun.attributes.next_setting) | timestamp_custom(' %H:%M') | replace(" 0", "") }}
        icon_template: mdi:weather-sunset-up   

Platform Integration

To determine the consumption from an instantaneous value, a so-called platform integration can be used. As an example, from certain consumption values: Watt the complete consumption can be summed up:

sensor:
  - platform: integration
    source: sensor.waschmaschine_power
    name: waschmaschine_energy_sum
    unit_prefix: k
    unit_time: h
    round: 2  

The consumption is summed up:

To relate the summed consumption back to a specific time period, Platform Integration can be used as "utility_meter":

Utility_meter

The utility meter uses the total consumption and divides it into specific time periods: e.g. hourly or (daily) daily:

utility_meter:
  waschmaschine_hour:
    source: sensor.trockner_energy_sum
    name: Waschmaschine hour
    cycle: hourly  
  waschmaschine_daily:
    source: sensor.trockner_energy_sum
    name: Waschmaschine hour
    cycle: daily

Shelly

Since it is easy to connect different systems with Home Assistant, I also use a WLAN switch in addition to ZigBee. Shelly is a small flush-mounted WLAN switch for controlling e.g. a power socket.

After setup, the device is automatically assigned to the default home dashboard:

Device Tracker OpenWRT

If you want to track the presence of devices via OpenWRT, you can do this with the device_tracker entry in the configuration.yaml file:

device_tracker:
  - platform: luci
    host: 192.168.1.2
    username: root
    password: xxx
    interval_seconds: 30
    consider_home: 360
    new_device_defaults:
       track_new_devices: true

For OpenWRT, the package luci-mod-rpc is required for this. For information on OpenWRT, see: Alternative Router Firmware: OpenWrt and no longer DD-WRT.

Connect MQTT devices as sensor

After adding the MQTT integration, a new sensor can be created in the configuration.yaml file:

MQTT requires an MQTT broker server, see MQTT - Broker : Docker Setup.

Adding individual sensors in theconfiguration.yaml file:

sensor:
  - platform: mqtt
    state_topic: "flowmeter/flow"   
    name: "flowmeter"
    unit_of_measurement: "m³/h"

Home-Dashboard

All connected devices are automatically displayed in the home dashboard.

Of course, the dashboards can also be created and customized by yourself.

History

In the history, the historical data of the individual devices are automatically prepared:

The default history settings are 10 days, after which historical values are deleted from the database:

Setting: purge_keep_days integer (optional, default: 10) in the configuration.yaml file:

recorder:
  purge_keep_days: 10

see, www.home-assistant.io/integrations/recorder/, or to use a database other than SQLite: Home Assistant database MySQL vs. SQLite and for connecting an InfluxDB, see: InfluxDB: Time series database - Docker and for visualizing: Grafana: Docker - Visualize data and define alarms.

HACS - Installation

Actually I just wanted to add a RGB light to the dashboard, works but without the possibility to change the color: At this point I would have expected more. The research and installation of an integration for controlling colors took me much more time than the actual Home Assistant installation. But in return, HACS gave me the foundation for further customization. HACS is an integration to download GitHub repositories via a kind of software catalog.

I installed HACS via a command in the Docker container:

user@rechner:~$ docker exec -it home-assistant bash
bash-5.0# wget -q -O - https://install.hacs.xyz | bash -

then on settings, integration

and then the installation has to be registered on GitHub, see: hacs.xyz/docs/configuration/basic

Once HACS is installed, adding additional repositories is relatively easy:

Must-have frontend packages: HACS

Adding resources - RGB Light Card

If you have RGB lights in use, you can use the RGB Light Card to change the colors:

apexcharts-card

Besides the RGB Light Card, I also installed apexcharts-card. With this package you can create much more appealing graph cards:

Notification to cell phone - Alarm

The Android app "Home Assistant" offers besides numerous cell phone sensor values in Home Assistant also a very simple way to receive notifications from Home Assistant: https://play.google.com/store/apps/details?id=io.homeassistant.companion.android&hl=de_AT&gl=US.

If you install the app, you will notice that Home Assistant regularly notifies you about updating the cell phone sensors to HomeAssistant:

Refresh Sensors.

By default, a notification with "Update sensors" is displayed every 15 minutes:

The notice can be easily removed by long pressing on the notification and disabling the "SensorWorker":

Deactivating the SensorWorker does not affect the notifications stored in the automations, they still remain active. To receive a notification when an event occurs, an automation can be created for this purpose by clicking on "Configuration" and "Automation":

Notification when a certain value is reached

As an example, I created a notification for monitoring the humidity:

I created a new automation for this notification in Configuration / Automation:

The notification can be tested later with "RUN ACTIONS", but first to the settings of this automation:

 

service: notify.mobile_app_sm_a405fn
data:
  title: Luftfeuchtigkeit Bad
  message: >-
    Luftfeuchtigkeit: {{states('sensor.bad_2')}}%
    Temperatur:{{states('sensor.bad')}}°C

Access via the Internet https-ssl (Let's-Encrypt) and Docker Compose.

Thanks to Let's Encrypt, Home Assistant can very easily be provided with an SSL certificate and thus be operated securely on the Internet. As a prerequisite for this, I have the following setup in use: nginx-LetsEncrypt Reverse Proxy in practice.

For the operation with the Nginx reverse proxy I made the following settings in the configuration:

configuration.yaml:

http:
  server_port: 80
  use_x_forwarded_for: true
  trusted_proxies:
    - 127.0.0.1
    - ::1    
    - 172.18.0.0/16

I use a separate network for my SmartHome containers: "smart-home" and for web containers, which are accessible from the Internet via the Let`s Encrypt reverse proxy, the network "webproxy". Accordingly, I created the following docker-compose file for Home Assistant:

docker-compose.yml

[+]
version: "3"
services:
  hass:
    image: homeassistant/home-assistant:stable
    container_name: home-assistant
    environment:
      VIRTUAL_HOST: 'ha.domain.tld'
      VIRTUAL_PORT: '80'
      LETSENCRYPT_HOST: 'ha.domain.tld'
      LETSENCRYPT_EMAIL: 'email@damain.tld'
    restart: always
    volumes:
      - ./:/config
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro
    expose:
       - "80"
    networks:
            - default
            - backend
networks:
  default:
    external:
      name: webproxy
  backend:
    external:
      name: smart-home

deCONZ and Home-Assistant in a docker-compose.yml-file

So that also the Conbee 2 stick can be addressed, I have added deCONZ

[+]
version: "3"
services:
  hass:
    image: homeassistant/home-assistant:stable
    container_name: home-assistant
    depends_on:
      - deconz
    environment:
      VIRTUAL_HOST: 'ha.domain.tld'
      VIRTUAL_PORT: '80'
      LETSENCRYPT_HOST: 'ha.domain.tld'
      LETSENCRYPT_EMAIL: 'admin@domain.tld'
    restart: always
    volumes:
      - ./ha:/config
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro
    expose:
       - "80"
    ports: 
       - 8123:80
    networks:
            - default
            - backend
  deconz:
    image: marthoc/deconz
    container_name: deconz
    environment:
      DECONZ_DEVICE: '/dev/ttyACM0'
      DECONZ_VNC_MODE: '1'
      DECONZ_VNC_PORT: '5900'
      DECONZ_VNC_PASSWORD: 'password'
    restart: always
    volumes:
      - ./deCONZ/:/root/.local/share/dresden-elektronik/deCONZ
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro
    devices: 
      - /dev/ttyACM0
    ports:
       - 83:80
       - 5983:5900
    networks:
       - backend
networks:
  default:
    external:
      name: webproxy
  backend:
    external:
      name: smart-home

After about a year with deCONZ I switched to Zigbee2MQTT, accordingly I removed deCONZ in the following example and put Zigbee2MQTT and MQTT together with Home-Assistant in a docker-compose file:

Alternatively: Zigbee2MQTT, MQTT and Home-Assistant in a docker-compose.yml file

My complete setup, consisting of HomeAssistant, MQTT and Zigbee2MQTT, assuminga running LetsEncrypt reverse proxy, currently looks likethis:

[+]
version: "3"
services:
  hass:
    image: homeassistant/home-assistant:stable
    container_name: home-assistant
    depends_on:
      - zigbee2mqtt
    environment:
      VIRTUAL_HOST: 'ha.domain.tldt'
      VIRTUAL_PORT: '80'
      LETSENCRYPT_HOST: 'ha.domain.tld'
      LETSENCRYPT_EMAIL: 'admin@domain.tld'
    restart: always
    volumes:
      - ./ha:/config
      - /archiv:/archiv:ro
      - /backup:/backup:ro
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro
    expose:
       - "80"
    ports: 
       - 8123:80
    networks:
            - default
            - backend
  mosquitto:
    image: eclipse-mosquitto
    container_name: mqtt
    restart: always
    volumes:
      - ./mosquitto/config:/mosquitto/config
      - ./mosquitto/data:/mosquitto/data
      - ./mosquitto/log:/mosquitto/log
    ports:
      - "1883:1883"
      - "9001:9001"      
    networks:
       - backend
  zigbee2mqtt:
      container_name: zigbee2mqtt
      restart: always
      image: koenkk/zigbee2mqtt
      volumes:
        - ./zigbee2mqtt-data:/app/data
        - /run/udev:/run/udev:ro
      ports:
        - 83:8080
      environment:
        - TZ=Europe/Vienna
      devices:
        - /dev/ttyACM0
      networks:
        - backend  
networks:
  default:
    external:
      name: webproxy
  backend:
    external:
      name: smart-home

InfluxDB and Grafana

In order to store long-term values for my heating and to be able to visualize them better, I also use an InfluxDB for storing the data and Grafana for evaluating it. The connection of the Influx-DB here is done via the Home-Assistant config file configuration.yml

...
influxdb:
  include:
    entities:
       - sensor.1...
       - sensor.2...
  host: influxdb
  port: 8086
  database: ha
  username: ha
  password: xxx
  max_retries: 3

Version 1 uses a username and password for the connection, version 2: token, organization and bucket.

Since I don't want to evaluate all data in Grafana, I used "include" to store only certain sensors. The complete Docker setup for Home Assistant, MQTT, Zigbee2MQTT, InfluxDB and Grafana looks like this:

[+]
version: "3"
services:
  hass:
    image: homeassistant/home-assistant:stable
    container_name: home-assistant
    depends_on:
      - zigbee2mqtt
    environment:
      VIRTUAL_HOST: 'ha.domain.tld'
      VIRTUAL_PORT: '80'
      LETSENCRYPT_HOST: 'ha.domain.tld'
      LETSENCRYPT_EMAIL: 'admin@domain.tld'
    restart: always
    volumes:
      - ./ha:/config
      - /archiv:/archiv:ro
      - /backup:/backup:ro
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro
    expose:
       - "80"
    ports: 
       - 8123:80
    networks:
            - default
            - backend
  mosquitto:
    image: eclipse-mosquitto
    container_name: mqtt
    restart: always
    volumes:
      - ./mosquitto/config:/mosquitto/config
      - ./mosquitto/data:/mosquitto/data
      - ./mosquitto/log:/mosquitto/log
    ports:
      - "1883:1883"
      - "9001:9001"      
    networks:
       - backend
  zigbee2mqtt:
      container_name: zigbee2mqtt
      restart: always
      image: koenkk/zigbee2mqtt
      volumes:
        - ./zigbee2mqtt-data:/app/data
        - /run/udev:/run/udev:ro
      ports:
        - 83:8080
      environment:
        - TZ=Europe/Vienna
      devices:
        - /dev/ttyACM0
      networks:
        - backend  
  influxdb:
      container_name: influxdb
      restart: always
      image: influxdb
      volumes:
        - ./influxdb:/var/lib/influxdb
      ports:
        - 8086:8086
      networks:
        - backend   
  grafana:
      container_name: grafana
      restart: always
      image: grafana/grafana
      volumes:
        - ./grafana:/var/lib/grafana
      ports:
        - 3000:3000
      networks:
        - backend 
networks:
  default:
    external:
      name: webproxy
  backend:
    external:
      name: smart-home

see also: InfluxDB: Time series database - Docker and Grafana: Docker - visualize data and define alarms

Troubleshooting - deCONZ

EVENTS

In the Developer Tools, the "EVENTS" tab can be used to observe which devices trigger an action, for example when a button is pressed:

deconz_event

The configuration flow could not be loaded

Running deCONZ in Docker can cause the IP address of the deCONZ container to change on restart. Homeassistant does not use the name of the container for the connection, but its IP address, therefore the connection does not work anymore then:

The setting in the .storage/core.config_entries file then points to an incorrect IP address:

Marquee control - grayed out

I initially had the problem that my awning could only be moved in one direction.

According to Phoscon the ZigBee switch is the model FB56+CUR17SB2.2(Heiman).

Advanced mode is needed to adjust certain settings.

Settings: Customization

This allows to change certain attributes in the settings, in my case "assumed_state".

The file customize.yaml is thereby filled as follows:

cover.window_covering_device_10:
  assumed_state: true

In order for the settings to be loaded, the file must still be specified in configuration.yaml:

homeassistant:
  customize: !include customize.yaml

Then restarted the Docker container and lo and behold, now the other direction works as well:

Conclusion

Thanks to the fast startup and easy implementation of new ideas, I am currently more than satisfied with Home Assistant and have replaced my previously created setup consisting of ioBroker, InfluxDB and Grafana with Home Assistant. For most dashboards I use HomeAssistant and only for certain visualizations I have InfluxDB and Grafana in addition. For a comparison with other smart home platforms, see: Smart Home Platform: Systems

positive Bewertung({{pro_count}})
Rate Post:
{{percentage}} % positive
negative Bewertung({{con_count}})

THANK YOU for your review!



Questions / Comments


By continuing to browse the site, you agree to our use of cookies. More Details