vd Brink Home Automations

Home automations: Home Assistant, ESPHome, Node-RED and more.

Follow me on GitHub

ESPHome Co2 sensor

Based on the SenseAir S8 sensor

Introduction

zigbee

There are not so many affordable out-of-the-box Co2 sensors available, but it’s easy to create one yourself. With only an ESP, a C02 sensor, power cable and box, it’s a small and easy project with a lot of benefits!

If your in a space with a too high ppm level, you can feel tired, your start yawning, get red cheeks and can get a headache. Without knowing, this happens because it goes very gradually. To prevent this, use your smart home automations and take action if the levels are too high.
This keeps you and your family healthy!

Co2 stands for Carbon dioxide and is measured in Parts per million (ppm).

The average value outside is around 400 ppm, which is a base value. That’s also why you need to open a window when the value is too high, get some fresh air from outside.

ppm condition action
400 - 800 good no action is required
800 - 1200 medium open a window
1200+ bad limit has reached, open all windows

My final result

A small box with a tail.
Inside a Co2 sensor and an ESP mini.

final box


Table of Contents


Required hardware

These hardware components did I use for this project:

SenseAir S8 Co2 sensor
  • ESP 12S Wemos D1 mini (no pro or V3) link 1
    • You can use any ESP chip, but I like this one because of its small size
ESP D1 mini
  • Dupont male to male wires link 1 link 2
    • If you order these, you can better order all three types at ones, also for any further projects
Dupont male to male wires DIY cases
  • Micro USB cable to power the ESP board link 1

Micro USB cable

5V USB power adapter
  • Soldering iron. I suggest this based on the reviews. I already had one. Please let me know if you advise this one or not? link 1
soldering iron soldering tin wire

Affiliate links are used here, so you sponsor my blog also with it, without paying extra for it.

Found a dead link? Please inform me

See ESPHome DIY sensors best buy tips for more DIY hardware buy tips.


Required software

For this project, you only need the software to flash the ESP chip with the configuration file.


Connect the hardware

I’ve made a scheme how to connect the SenseAir S8 to the ESP.

The ESP and sensor don’t come with pins, so you need to solder a bit to connect the male-to-male dupont cables between the sensor and the ESP.

Connect the SenseAir S8 to the ESP

Use control + click to see the full photos of the connected wires.

Connected pins ESP8266 Wemos
D1 mini pins
SenseAir S8 pins
Connect schema ESPHome SenseAir S8 Pins on a ESP8266 Wemos di mini Pins on a SenseAir S8
This image is 180 degrees rotated compared with the first image.

This table show how the ESP is connected with the SenseAir.

Wemos pin GPIO Wemos pin* SenseAir pin
D7 GPIO13 UART_TxD
D8 GPIO15 UART_RxD
G GND G0
5V 5 V G+

* The GPIO Wemos pin is the port which is used in the ESPHome yaml.

If you place the sensor on top of the ESP mini, it fits perfect in the DIY box.

You need to drill a hole in the edge of the box so the USB power cable can go through it. perfect fit in case

I drilled some holes in the case. Now the air can reach the Co2 sensor inside the box.

holes in case


ESPHome

ESPHome

ESPHome SenseAir page

Flash the ESP

Connect the ESP via USB with the computer.

Install ESPHome and compile the configuration code after you configured your own wi-fi. And configure (or remove) the MQTT section. This is not needed if you integrate it direct in Home Assistant.

For more information about installing and flashing your ESP with ESPHome see the ESPHome website or Peyanski ESPHome Installation Guide.

The script:

# Sourcecode by vdbrink.github.io
esphome:
  name: esp_co2
  comment: Room Co2 sensor
  platform: ESP8266
  board: d1_mini
  arduino_version: latest

wi-fi:
  ssid: "xxx"
  password: "xxx"
  fast_connect: true # only needed for hidden SSID
  
mqtt:
  broker: xxx.xxx.xxx.xxx
  port: 1883
  username: "xxx"
  password: "xxx"
  
uart:
  rx_pin: GPIO13
  tx_pin: GPIO15
  baud_rate: 9600
  
sensor:
  - platform: senseair
    co2:
      id: senseair_co2
      name: "SenseAir Co2 Value"
    update_interval: 30s

Home Assistant

Ones the sensor pushes the data, you can use and present the data on your dashboards or create notifications when the values are not good.

Dashboard Gauge

In a Gauge, you can directly see if the current co2 value is correct. I used different colors to indicate how bad the condition is. I used the values from the table mentioned in the Introduction.

Home Assistant Gauge
# Sourcecode by vdbrink.github.io
# Dashboard card code
type: gauge
severity:
  green: 400
  yellow: 800
  red: 1200
entity: sensor.senseair_co2_value
min: 350
max: 1500
name: Room Co2 sensor

Dashboard Line Graphic

To show the history of the last X hours, you can use the card.

Home Assistant Graph
# Sourcecode by vdbrink.github.io
# Dashboard card code
type: sensor
graph: line
entity: sensor.senseair_co2_value
name: Room Co2 sensor
hours_to_show: 6

Dashboard History Graphic

Another graph entity is the history-graph.

You can also show baseline values by creating a custom sensor with a fixed value.

# Sourcecode by vdbrink.github.io
# Dashboard card code
type: history-graph
entities:
  - entity: sensor.senseair_co2_value
  - entity: sensor.co2_value_800
  - entity: sensor.co2_value_1200
  - entity: sensor.co2_value_1500
hours_to_show: 24

This is how you create three custom lines in the graph to see the threshold values.


# Sourcecode by vdbrink.github.io
# configuration.yaml
- sensor:
    - platform: template
      sensors:
        co2_value_800:
          friendly_name: "good"
          value_template: 800
          unit_of_measurement: 'ppm'
        co2_value_1200:
          friendly_name: "avarage"
          value_template: 1200
          unit_of_measurement: 'ppm'
        co2_value_1500:
          friendly_name: "bad"
          value_template: 1500
          unit_of_measurement: 'ppm'

Dashboard condition text

Home Assistant conditional Co2 text

This creates a new sensor that shows a textual presentation of the current condition.


# Sourcecode by vdbrink.github.io
# configuration.yaml
- platform: template
  sensors:
    senseair_co2_value_text:
        icon_template: "mdi:molecule-co2"
        friendly_name: "Room Co2"
        value_template: >-
          {% set state = states('sensor.senseair_co2_value') | int %}
          {% if state < 800 %}good
          {% elif state > 800 and state <= 1200 %}average
          {% elif state > 1200 and state <= 1500 %}bad
          {% elif state > 1500%}very bad
          {% else %}unknown{% endif %}

In my dashboard, I have a section with important messages. Only when there is an action required, you see that here. There is also a message when the Co2 value is not good. This section can be achieved by using conditional entities.


# Sourcecode by vdbrink.github.io
# Dashboard card code
type: entities
entities:
- type: conditional
  conditions:
    - entity: sensor.senseair_co2_value_text
      state_not: good
      row:
        entity: sensor.senseair_co2_value_text

Dashboard Mushroom entity

mushroom chips Show a green icon, without any text, if the level is less the 800 ppm, less than 1200 ppm yellow, less than 1500 ppm red.

# Sourcecode by vdbrink.github.io
# Dashboard card code
type: custom:mushroom-chips-card
chips:
  - chip: null
    type: template
    icon: mdi:molecule-co2
    entity: sensor.senseair_co2_value
    content: ''
    icon_color: |-
      {% if is_state('sensor.senseair_co2_value', 'unavailable') %}
         blue
      {% elif states('sensor.senseair_co2_value')|int > 1500 %}
         red
      {% elif states('sensor.senseair_co2_value')|int > 1200 %}
         orange
      {% elif states('sensor.senseair_co2_value')|int > 800 %}
         yellow
      {% else %}
         green
      {% endif %}




Remarks or suggestions?

Do you have any remarks or suggestions please let me know via github issues.

Create an issue

Or via a private message on the Tweakers.net forum.


Top | Homepage | Best Buy Tips