css811 co2 and tvoc on esp32 HydraFerret / xymon

Enfield Cat's Blog: Arduino and other projects.


This device measures Carbon Dioxide (CO2) and Total Volatile Organic Compounds (TVOC) in the atmosphere.

Note:The serial device mh-z19c is preferred over css811 for carbon dioxide measurement.


Adding one or more css811 to either i2c busses will allow the css811(s) to be autodetected and configured on reboot. The minimum configuration is to simply added the sensor and restart the esp32. The configuration of the I2C bus is discussed elsewhere on this page. Each css811 should have unique address on the bus on which it is located. The css811 devices are numbered 0 to 3, starting with units on bus 0 then bus one. On each bus the number allocation is in device address sequence.

This numbering is important if for example there is one css811 on bus 1, and then later another is added to bus 0. After the addition the new device will be unit 0, and the old one unit 1. Conversely if the existing device were on bus 0, and a new one added to bus 2, the old device remains unit 0, and the new one becomes unit 1.

Configuration commands are:

critical|extreme|warning <devicetype> <0-3> [co2|tvoc] disable
critical|extreme|warning css811 <0-3> [co2|tvoc] <rpn-expression>
    enable or disable alerting thresholds on sensors

devicename css811 <0-3> <device-name>
    Name a sensor device

i2c [<0-1> <sda> <scl> [speed]]
    Set i2c pins, eg: 21 and 22 for bus-0, and 5 and 4 for bus-1

interval css811 <1-300>
    Set the interval between measurements taken by the sensor.

rpn variables:
    css811.dev  - Count of css811 sensors (DEVice count)
    css811.co2  - 5 minute average of carbon dioxide (co2) readings
    css811.lasc - last (most recent) co2 reading
    css811.tvoc - 5 minute average of total volatile organic compounds (tvoc) reading
    css811.last - last (most recent) tvoc reading
    css811.csta - co2 status: 0=Ok, 1=warn, 2=critical or 3=extreme
    css811.tsta - tvoc status: 0=Ok, 1=warn, 2=critical or 3=extreme

Thank you for visiting camelthorn.cloudHome