Skip to content

mtdcr/comfoair-mqtt-bridge

Repository files navigation

A bridge between Zehnder ComfoAir ventilation units and MQTT with support for Home Assistant

This program receives events from a ComfoAir connected to a serial port and publishes contained data on MQTT. It also subscribes to commands from MQTT and relays them to the ventilation unit.

Currently it assumes presence of a CC-Ease control unit. It's able to switch between CC-Ease- and PC-Modes quite reliably on demand.

Tested devices:

Home Assistant, when configured for MQTT discovery, can auto-detect fans and sensors published by this program.

Dependencies

How to use

  • Using a real serial port:
comfoair-mqtt-bridge.py --broker mqtt://broker.local --port /dev/ttyUSB0
  • With a serial port reachable over tcp, e.g. using ser2net:
comfoair-mqtt-bridge.py --broker mqtt://broker.local --port socket://sbc.local:51765

When used in combination with Home Assistant, add the --hass option.

To see debug messages, add --debug.

Instead of specifying broker and port on the command-line, you can store them in a configuration file (option --config, default path: /var/lib/comfoair-mqtt-bridge/config.json).

A /etc/ser2net.conf should look similar to this one:

192.168.3.50,51765:raw:0:/dev/serial/by-id/usb-067b_2303-if00-port0:9600 8DATABITS NONE 1STOPBIT -XONXOFF -RTSCTS -HANGUP_WHEN_DONE

Running the bridge as a systemd service

Save this file as /etc/systemd/system/comfoair-mqtt-bridge.service:

[Unit]
Description=ComfoAir-MQTT-Bridge
After=network-online.target

[Service]
Type=simple
ExecStart=/srv/homeassistant/bin/python /usr/local/bin/comfoair-mqtt-bridge.py --broker mqtt://broker.local --port /dev/ttyUSB0 --hass
Restart=on-failure
RestartSec=5s
DynamicUser=yes
StateDirectory=comfoair-mqtt-bridge
DevicePolicy=closed
DeviceAllow=char-ttyUSB
SupplementaryGroups=dialout

[Install]
WantedBy=multi-user.target

Edit paths and URLs to match your setup. In this example, /srv/homeassistant is a Python venv, into which the dependencies were installed using pip.

Then enable and start the service:

systemctl enable comfoair-mqtt-bridge.service
systemctl start comfoair-mqtt-bridge.service

Notes regarding MQTT

  • username/password are passed as part of the --broker parameter, e.g. --broker mqtt://username:password@broker.local

Notes regarding Home Assistant

  • Home Assistant will auto-detect a device with multiple entities (currently fan.comfoair and some sensors).
  • All entities get marked as unavailable if the bridge gets shutdown cleanly (SIGINT, SIGTERM) or if there's no data on the serial line.
  • You can emulate a pressed button on the CC-Ease.
    • Each key resembles one bit: 1=fan, 2=mode, 4=clock, 8=temp, 16=plus, 32=minus
    • To press multiple keys at the same time, sum up their values. Example: fan + mode = 3
    • You can either send a short key press by publishing the keys_short attribute, or a long key press by publishing the keys_long attribute on MQTT.
    • Pressing the mode key toggles between three operating modes:
      • Supply + Exhaust
      • Exhaust only
      • Supply only
    • What follows is an example for a tap_action in Lovelace to send a short mode key press event to your ventilation unit. The topic gets derived from your command-line parameters. To find it in Home Assistant, open Configuration -> Devices -> ComfoAir -> MQTT INFO and look for Subscribed Topics. Then replace e.g. availability with keys_short.
"tap_action": {
  "action": "call-service",
  "service": "mqtt.publish",
  "service_data": {
    "payload": 2,
    "retain": false,
    "topic": "ComfoAir/sbc.local:51765/keys_short"
  }
}

About

A bridge between Zehnder ComfoAir ventilation units and MQTT with support for Home Assistant

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages