Skip to content

c7h/co2bridge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

This is a CO2 Sensor MQTT Bridge.

It forwards messages from the MH-Z19 Co2 sensor attached via serial to an mqtt topic in regular intervals. It is useful if you want to monitor Co2 concentration in multiple rooms in Homeassistant. My setup looks like this:

   Room 1                Room 2
 BridgeClient          MQTT Broker and HASS.io
   -------               ------- 
  |       |             |       |
  |       |             |       |
  | Raspi | ----------->| Raspi |
  |   1   |    MQTT     |   2   |
  |       |             |       |
  |       |             |       |
   --- ---               --- --- 
      |                     |
      |                     |
    -- --                 -- -- 
   |MZH19|               |MZH19|
   |-----|               |-----|
   |     |               |     |
   |     |               |     |
   |     |               |     |
   |     |               |     |
    -----                 ----- 

On Raspi1, connect the MH-Z19 to the GPIOs:

RPi Pin MH-Z19
Tx Rx
Rx Tx
Gnd Gnd
5v Vin

Hacked toghether by Christoph Gerneth

How to run (on a pi - quick and hacky way):

git clone https://github.com/c7h/co2bridge.git
cd co2bridge
vim co2bridge.py # Edit the parameters (reminder hacky)
sudo pip install -r requirements.txt
sudo cp co2bridge.service /etc/systemd/system
service co2bridge start

if you want to autostart the service on boot, run

sudo service co2bridge enable

Homeassistant Integration

You can monitor the CO2 concentration in Homeassistant. Add the following lines to your configuration.yaml.

  - platform: mqtt
    name: "Meeting Room 1 Co2"
    state_topic: "devices/raspi/co2sensor"
    availability_topic: "devices/raspi/co2sensor/state"
    unit_of_measurement: "ppm"
    value_template: "{{ value_json.ppm }}"
  - platform: mqtt
    name: "Meeting Room 1 Temperature"
    state_topic: "devices/raspi/co2sensor"
    availability_topic: "devices/raspi/co2sensor/state"
    unit_of_measurement: "°C"
    value_template: "{{ value_json.temperature }}"

Releases

No releases published

Packages

No packages published

Languages