Skip to content

dgomes/dali2mqtt

Repository files navigation

pytest workflow

dali2mqtt

DALI <-> MQTT bridge

About

This daemon is inspired in zigbee2mqtt and provides the means to integrate a DALI light controller into your Home Assistant setup.

Previously I developed a Home Assistant custom component (https://github.com/dgomes/home-assistant-custom-components/tree/master/light) but I've since decided to run Home Assistant in another device, away from the physical DALI Bus.

Supported Devices

This daemon relies in python-dali so all devices supported by this library should also be supported by dali2mqtt.

How to use

Install Operating System Dependencies

Python3 library

This package depends on https://github.com/trezor/cython-hidapi

Create a Virtual Environment (recommended) and install the requirements

python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

Create a configuration file

You can create a configuration file when you call the daemon the first time

venv/bin/python3 -m dali2mqtt.dali2mqtt

Then just edit the file accordingly. You can also create the file with the right values, by using the arguments of dali_mqtt_daemon.py:

  --config CONFIG       configuration file
  --mqtt-server MQTT_SERVER
                        MQTT server
  --mqtt-port MQTT_PORT
                        MQTT port
  --mqtt-username MQTT_USERNAME
                        MQTT user name
  --mqtt-password MQTT_PASSWORD
                        MQTT password
  --mqtt-base-topic MQTT_BASE_TOPIC
                        MQTT base topic
  --dali-driver {hasseb,tridonic,dali_server}
                        DALI device driver
  --dali-lamps DALI_LAMPS
                        Number of lamps to scan
  --ha-discover-prefix HA_DISCOVER_PREFIX
                        HA discover mqtt prefix
  --log-level {critical,error,warning,info,debug}  
                        Log level  
  --log-color Coloring output

Devices friendly names

Default all lamps will be displayed in Home Assistant by short address, numbers from 0 to 63 You can give lamps special names to help you identify lamps by name. On the first execution, devices.yaml file will be create with all lamps available. Example devices.yaml:

0: 
  "friendly_name": "Lamp in kitchen"
8:
  "friendly_name": "Lamp in bathroom"

Please note that MQTT topics support a minimum set of characters, therefore friendly names are converted to slug strings, so a lamp with address 0 (as an example) in MQTT will be named "lamp-in-kitchen"

Setup systemd

edit dali2mqtt.service and change the path of python3 to the path of your venv, after:

sudo cp dali2mqtt.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable dali2mqtt.service 

Give your user permissions to access the USB device

sudo adduser homeassistant plugdev 
cp 50-hasseb.rules /etc/udev/rules.d/

You might need to reboot your device after the last change.

In this example the user is homeassistant

Check everything is OK

sudo systemctl start dali2mqtt.service 
sudo systemctl status dali2mqtt.service 

Command line arguments and configuration file

When the daemon first runs, it creates a default config.yaml file. You can edit the file to customize your setup.