What options for CO2 sensor?

Agreed, it’s a bit steep.
Naively I thought as it was zigbee 3.0 that it would just work with Home Assistant and it would be a quick easy way of monitoring.

Sadly, I’m having to learn about Quirks, but it looks hopeful that I should have it up and running very soon.
Just need to find a bit of time to install and test the Quirk that I’ve been helped to create.

With a lot of help. Got this added. Should be in the next home assistant release.

2 Likes

I am new to HASS.io (literally installed it today) and now I want to add a CO2 sensor.

I read this thread, and it helped me already. Thanks for that!

But I have still some questions left before I commit and order the parts:

  1. All MH-Z19 Sensor I can find have the MH-Z19B variant. Can anyone confirm it works now with ESPHome? @FredTheFrog seems to made it work but from the code it was not entirely clear if it was the B-Variant or not.

  2. The installation workflow (connect ESP to HASS.io computer, load code, clip on wires to connect to sensor; no soldering required as long as I order the sensor with the pre-soldered parts for clipon-wires) seems clear, but I can’t find any tutorial describing which pins exactly need to be connected to where on either the sensor or the ESP. I have no experience in this area. Maybe someone can point me into the direction of a tutorial that does cover it?

First, here is my working code/yaml:

esphome:
  name: co2sensor
  platform: ESP8266
  board: d1_mini_pro

wifi:
  fast_connect: true
  domain: .local
  power_save_mode: NONE
  reboot_timeout: 5min
  ssid: "mywifi"
  password: "mypassword"
  use_address: co2sensor.local

# Enable logging
logger:
  level: debug

# Connection to MHZ19
uart:
  rx_pin: D3
  tx_pin: D2
  baud_rate: 9600

sensor:
  - platform: mhz19
    co2:
      name: "MH-Z19 CO2 Value"
    update_interval: 30s
    
# Enable Home Assistant API
api:
  password: "password"

ota:
  password: "password"

Four connections/wires are required, GND/GROUND, 5VDC/POWER, plus those two UART pins, D2 and D3.
5VDC/POWER from ESP8266 connects to VCC/POWER on MHZ19.
GND/GROUND from ESP8266 connects to GND/GROUND on MHZ19.
D2 TX/TRANSMIT DATA from the ESP8266 connects to RX/RXD/RECEIVE DATA on the MHZ19.
D3 RX/RECEIVE DATA from the ESP8266 connects to TX/TXD/TRANSMIT DATA on the MHZ19.

Hope this helps!

3 Likes

Thanks a lot! This helps!

Bey the newer model MH-Z19C of the sensair S8.

Got it working! Thanks for your help @FredTheFrog and @TheMysteryCleanShot 2021-03-31 at 17.45.25

Went with the MH-Z19C, because I found one presoldered for cheap on eBay.

Now I just need to solder the pin headers permanently on the ESP (I hope I don’t short it in the process :grimacing:)

Any of you guys familiar with these multisensors?

There are several stores on Ali that sell these but it’s not really clear whether it would work with ZHA.
They are ZB 3.0 so I suppose it should work?

I have not worked with the devices you point out. However, from what I have read, the lower cost < USD50 CO2 devices use a CO2 estimating sensor that ‘experts’ say is less accurate. I am far from an expert, but I wanted to get a good feel for air exchange in these covid times. So I girded my credit card and got the Aranet4 device based on the reviews. It is Bluetooth not zigbee. I kind of like that fact that I can take it out of the house and see CO2 levels at other places. If you are interested in the ‘state’ accurate CO2 level monitoring and want to waste several hours, google ‘CO2 monitor COVID’ :wink: . After I purchased the Aranet4 unit, I ran across this other device that in addition to CO2 and the standard other sensors monitor Radion as well, if that is an interest. I am happy with the Aranet4 device after using for about 2 month, I have used a Eve Room for about 5 years, prior to adding the Aranet4, it only does particulates. But like Aranet, they seem to have done there homework. Links to both devices below. Good hunting, hope you find something of use :

I’m not quite clear on which Airthings device to buy to get ‘all’ the reading, a bit confusing.

1 Like

How did u get the Aranet4 device into home assistant?

1 Like

Welcome!

This sensor deserves a proper integration to Home Assistant, which I have yet to do. When I got the device, I hacked up a short program using the library and example code from the github project listed below. It’s been running fine, so of course it’s gotten pushed back in the ‘make it better’ queue of ToDos. Perhaps this python code and the Home Assistant sensor configs below will give you some ideas.

This sensor has been running non-stop for months with no issues, the bluetooth range seems a but low, but it could be the BLE adapter on the computer I am using to collect with.

Good breathing!

Aranet4 Python client

testing on hp-600-g1-dm-01
added usb bluetooth dongle and got below running

sudo apt-get install python-pip
sudo apt-get install libglib2.0-dev
sudo pip install bluepy
sudo pip install requests
sudo pip install paho-mqtt

git clone https://github.com/Anrijs/Aranet4-Python.git

sudo pip install aranet4

Make sure that bluetoothd is running with --experimental. On systemd (sigh), try this:
sudo sed -i ‘s#/bluetoothd$#/bluetoothd --experimental#’ /lib/systemd/system/bluetooth.service
sudo systemctl daemon-reload
sudo systemctl restart bluetooth
Pair device:
Open bluetoothctl: sudo bluetoothctl
Enable passcode support: agent KeyboardOnly
Enable adapter: power on
Scan devices: scan on
When found your device, stop scan: scan off
Pair device: pair <DEVICE_ADDRESS>
Disconnect if automatically connected: disconnect <DEVICE_ADDRESS>
Exit from bluetooth ctl: exit

Device FA:70:36:DD:AB:F1 Aranet4 05A24

put this in github in useful_code
ble data access need to run as root
sudo ./aranet_mqtt_publish.py FA:70:36:DD:AB:F1 192.168.2.242 aranet

#!/usr/bin/env python3

# aranet_mqtt_publish.py
# 202111151305
#
# https://github.com/Anrijs/Aranet4-Python.git
#
# read CO2 data from ARANET4 sensor and publish to MQTT
# sudo ./aranet_mqtt_publish.py FA:70:36:DD:AB:F1 192.168.1.13 aranet

PROGRAM_NAME = "aranet_mqtt_publish"
VERSION_MAJOR = "1"
VERSION_MINOR = "2"
WORKING_DIRECTORY = ""

import sys

# check version of python
if not (sys.version_info.major == 3 and sys.version_info.minor >= 8):
    print("This script requires Python 3.8 or higher!")
    print("You are using Python {}.{}.".format(sys.version_info.major, sys.version_info.minor))
    sys.exit(1)
#print("{} {} is using Python {}.{}.".format(PROGRAM_NAME, VERSION_MAJOR + "." + VERSION_MINOR, sys.version_info.major, sys.version_info.minor))

import paho.mqtt.publish as publish
import aranet4
import sys
import time
from datetime import datetime
import json

# reading interval
PUBLISH_INTERVAL = 30
ERROR_INTERVAL = 2

def buildMsgs(readings, topic):
    return [
        (topic + "time", readings["time"]),
        (topic + "temperature", readings["temperature"]),
        (topic + "pressure", readings["pressure"]),
        (topic + "humidity", readings["humidity"]),
        (topic + "co2", readings["co2"]),
        (topic + "battery", readings["battery"])
    ]

def readArg(argv, key, default, error="Invalid value"):
    if key in argv:
        idx = argv.index(key) + 1
        if idx >= len(argv):
            print(error)
            raise Exception(error)
        return argv[idx]
    return default

def main(argv):
    if len(argv) < 3:
        print("Missing device address, topic base and/or hostname.")
        argv[0] = "?"

    if "help" in argv or "?" in argv:
        print("Usage: python publish.py DEVICE_ADDRESS HOSTNAME TOPIC_BASE [OPTIONS]")
        print("  -P  <port>      Broker port")
        print("  -u  <user>      Auth user name")
        print("  -p  <password>  Auth user password")

        print("")
        return

    device_mac = argv[0]
    host = argv[1]
    topic = argv[2]

    port = readArg(argv, "-P", "1883")
    user = readArg(argv, "-u", "")
    pwd =  readArg(argv, "-p", "")

    auth = None
    
    if len(user) > 0:
        auth = {"username":user}
        if len(pwd) > 0: auth["password"] = pwd

    if (topic[-1] != "/"): topic += "/"

    while True :

        now = datetime.now()
        nowts = int(time.time())

        try :
            ar4 = aranet4.Aranet4(device_mac)
            current = ar4.currentReadings()

            current["time"] = nowts
            current["mac-address"] = device_mac

            print("Publishing results : " + now.strftime("%H:%M:%S"))
            print(current)
            dev_topic = topic + device_mac
            publish.single(dev_topic, payload=json.dumps(current), hostname=host, port=int(port), auth=auth)
            # publish.multiple(buildMsgs(current, topic + device_mac + "/"), hostname=host, port=int(port), auth=auth)
            print("Sleeping ....")
            time.sleep( PUBLISH_INTERVAL )
        except KeyboardInterrupt:
            print("Program end : Keyboard Interrupt : " + PROGRAM_NAME + " Version : " + VERSION_MAJOR + "." + VERSION_MINOR)
            sys.exit(0)
        except :
            print("Failed to connect to sensor : " + now.strftime("%H:%M:%S"))

            print("Sleeping ....")
            time.sleep( ERROR_INTERVAL )

if __name__== "__main__":
  main(sys.argv[1:])

# aranet bluetooth low energy co2 sensors

  - platform: mqtt
    name: "ARANET4_01 CO2"
    unique_id: "FA:70:36:DD:AB:F1-CO2"
    expire_after: 3600
    state_topic: "aranet/FA:70:36:DD:AB:F1"
    value_template: "{{ value_json.co2 }}"
    unit_of_measurement: "ppm"
    json_attributes_topic: "aranet/FA:70:36:DD:AB:F1"

  - platform: mqtt
    name: "ARANET4_01 Temperature"
    unique_id: "FA:70:36:DD:AB:F1-temperature"
    expire_after: 3600
    state_topic: "aranet/FA:70:36:DD:AB:F1"
    value_template: "{{ value_json.temperature }}"
    # unit_of_measurement: "°C"
    json_attributes_topic: "aranet/FA:70:36:DD:AB:F1"

  - platform: mqtt
    name: "ARANET4_01 Humidity"
    unique_id: "FA:70:36:DD:AB:F1-humidity"
    expire_after: 3600
    state_topic: "aranet/FA:70:36:DD:AB:F1"
    value_template: "{{ value_json.humidity }}"
    unit_of_measurement: "%"
    json_attributes_topic: "aranet/FA:70:36:DD:AB:F1"

  - platform: mqtt
    name: "ARANET4_01 Pressure"
    unique_id: "FA:70:36:DD:AB:F1-pressure"
    expire_after: 3600
    state_topic: "aranet/FA:70:36:DD:AB:F1"
    value_template: "{{ value_json.pressure }}"
    unit_of_measurement: "hPa"
    json_attributes_topic: "aranet/FA:70:36:DD:AB:F1"

  - platform: mqtt
    name: "ARANET4_01 Battery"
    unique_id: "FA:70:36:DD:AB:F1-battery"
    expire_after: 3600
    state_topic: "aranet/FA:70:36:DD:AB:F1"
    value_template: "{{ value_json.battery }}"
    unit_of_measurement: "%"
    json_attributes_topic: "aranet/FA:70:36:DD:AB:F1"

# midea dehumidifiers

1 Like

Thanks a lot, i will try it!

hi,
it is possible to install it on same raspberry where is running HassioOS (Home Assistant Operating System)?
thank you

Yes possible. I’m not sure this set of libraries will play nice and share with other apps and libraries. So if you are using the bluetooth adapter for other services, there might be conflicts.

Good luck!

I’m using the scd30 Adafruit version. I have problems with ESPHome disconnecting every 30 minutes so I went the Tasmota route. It’s working flawlessly.
On the design note, the scd30 should be shielded from direct air flow. It doesn’t measure accurately if there’s air blowing straight at or across it. So I just CAD case and fit a small 5v fan along with a hole covered by a small piece of air filter to have the some circulation inside the case.