Skip to content

irimitenkan/CO2MqttSensor

Repository files navigation

CO2MqttSensor

Installation | Running the MQTT client | Configuration | Adapt UDEV rules | Home Assistant Integration| MQTT Broker Topics

Overview

CO2MqttSensor is a MQTT client to integrate a CO2 sensor into your home automation with Home Assistant discovery support.

A TFA CO2 sensor device with USB support in combination with a Raspberry Pi Zero or Zero 2W, you'll get a cheap and easy to use CO2 sensor with WiFi network access for your home automation like Home Assistant.

Supported CO2 devices are:

  1. TFA CO2-Monitor-Airco2ntrol-Mini, without humidity measurement

  2. TFA CO2-Monitor-Airco2ntrol-Coach, incl. humidity measurement

  3. Support of other available TFA devices with USB port is still unknown

Developement is based on this Hackaday Project . There you'll find other projects derived from that Hackaday project. Some sensor's device communication documentation you'll find here

Installation

Required packages for Raspberry-Pi OS:

sudo apt-get install -y --no-install-recommends python3-paho-mqtt python3-hid

On my Arch Linux / Manjaro system the correct package are:

sudo pacman -S python-paho-mqtt python-hidapi

finally clone the CO2MqttSensor repository:

git clone https://github.com/irimitenkan/CO2MqttSensor.git

Homeassistant OS

You have to install and setup the add-on "Mosquitto broker". Install CO2MqttSensor MQTT client on other device e.g. Rasperry Pi Zero.

Configuration

Example config.json

{
  "LogLevel":"INFO",
  "HW":"AIRCO2NTROL_MINI",  
  "//HW":"AIRCO2NTROL_COACH",
  "VENDOR":"0x04d9",
  "PRODUCT":"0xa052",
  "TFA_MINI_WWW_LINK":"https://www.tfa-dostmann.de/en/product/co2-monitor-airco2ntrol-mini-31-5006/",
  "TFA_COACH_WWW_LINK":"https://www.tfa-dostmann.de/en/product/co2-monitor-airco2ntrol-coach-31-5009/",

  "REFRESH_RATE":60,

    "MQTTBroker":{
    "host":"<ADDRESS OF BROKER>",
    "port": 8883,
    "username":"<USERNAME>",
    "password":"<SECRET>",

    "servercafile":"./ca.crt",
    "clientkeyfile":"./client.key",
    "clientcertfile":"./client.crt"
  }

}

CFG - Option

  • option REFRESH_RATE: value in [s] to poll data from device

  • option loglevel:INFO | WARN | DEBUG

  • option "HW":"AIRCO2NTROL_MINI" or "AIRCO2NTROL_COACH"

  • option: "VENDOR":"0x04d9", "PRODUCT":"0xa052",

    These are the value IDs for AIRCO2NTROL_MINI and AIRCO2NTROL_COACH. For other TFA CO2 devices with USB port try this on your linux machine:

    • connect sensor device with USB port and type
    lsusb
    
    • you will see the vendor and product id at end of output like this:
Bus 001 Device 002: ID 04d9:a052 Holtek Semiconductor, Inc. USB-zyTemp

UDEV-rules

Since you have not adapted your UDEV rules on your CO2MqttSensor host the python scripts runs only with root access. To execute CO2MQttSensor without root access you must define a udev-rule to assign different access rights when the CO2 sensor device is connected:

create a file /etc/udev/rules.d/99-hidraw-permissions.rules and add this line: SUBSYSTEMS=="usb", ATTRS{idVendor}=="04d9", ATTRS{idProduct}=="a052", GROUP="plugdev", MODE="0660"

on e.g.ARCH linux systems you may change it to KERNEL=="hidraw*", ATTRS{idVendor}=="04d9", ATTRS{idProduct}=="a052", GROUP="input", MODE="0660"

then restart udev sudo udevadm control --reload-rules and finally disconnect and reconnect you CO2 device from USB port.

Running

-to start from terminal

cd CO2MqttSensor
python3 co2sensor.py

with option: -c FILE, --cfg=FILE set config file default: ./config.json

-to stop it & started from terminal

enter CTRL-C

-to enable at startup and start service:

loginctl enable-linger
systemctl --user enable --now ~/CO2MqttSensor/co2sensor.service

-to disable running service at startup and stop it:

systemctl --user disable --now co2sensor

-to stop the service again

systemctl --user stop co2sensor

-to start the service

systemctl --user start co2sensor

-check the status of the service

systemctl --user status co2sensor

-check the CO2MqttSensor specific service logs

journalctl --user-unit co2sensor

HASS-Integration

All CO2MqttSensor entities will be detected by Home Assistant automatically by MQTT integration discovery function via configured MQTT broker since CO2MqttSensor has started and connected to broker successfully.

MQTT-Broker

Value topic

  • CO2Sensor/< HOSTNAME >/CO2/{"carbon_dioxide": "[value in ppm]"}
  • CO2Sensor/< HOSTNAME >/Temperature/{"temperature": "[value in °C]"}

Depends on used TFA sensor hardware:

  • CO2Sensor/< HOSTNAME >/Humidity/{"humidity": "[value in %]"}

Online status topic

  • CO2Sensor/< HOSTNAME >/CO2/available=[online|offline]
  • CO2Sensor/< HOSTNAME >/Temperature/available=[online|offline]

Depends on used TFA sensor hardware:

  • CO2Sensor/< HOSTNAME >/Humidity/available=[online|offline]

About

TFA CO2 sensor integration via MQTT and homeassistant discovery support

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages