ESPHome Temp Humidity LUX CO2 Motion Sensor

After endless research online for a sensor that does all these things in one and preferably without a battery that you have to keep changing, I decided to have a go at it myself using esphome and an esp8266 board and 3D print the enclosure.

In black

And white

Part list

DHT22 temp & humidity sensor
AM312 motion sensor
MH-Z19C CO2 sensor
TEMT6000 light sensor

Wiring diagram

MH-Z19C Black --> GND
MH-Z19C Red --> 3v3
MH-Z19C Blue --> TX
MH-Z19C Green --> RX

DHT22 + --> 3v3
DHT22 --> D7
DHT22 Out --> GND

AM312 VIN --> 3v3
AM312 OUT --> D5
AM312 GND --> GND

TEMT6000 OUT --> A0
TEMT6000 GND --> GND
TEMT6000 VCC --> 3v3

The case: https://www.thingiverse.com/thing:4767981
The 3D printed case is from https://www.thingiverse.com/thing:2361388 but I just edited to include space for the MH-Z19C on the side. Grab the case bottom from this link.

The esphome config

esphome:
  name: living_room
  platform: ESP8266
  board: nodemcuv2

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_pw

captive_portal:

# Enable logging
logger:
  hardware_uart: UART1

# Enable Home Assistant API
api:
  services:
    - service: mhz19_calibrate_zero
      then:
        - mhz19.calibrate_zero: living_room_mhz19c

ota:

uart:
  rx_pin: GPIO3
  tx_pin: GPIO1
  baud_rate: 9600

sensor:
  - platform: mhz19
    id: living_room_mhz19c
    co2:
      name: "Living Room CO2"
    temperature:
      name: "Living Room MH-Z19C Temperature"
    update_interval: 60s
    automatic_baseline_calibration: true
  - platform: dht
    pin: D7
    model: dht22
    temperature:
      name: "Living Room Temperature"
      filters:
      - offset: -2.3
    humidity:
      name: "Living Room Humidity"
    update_interval: 60s
  - platform: adc
    pin: A0
    name: "Living Room LUX"
    unit_of_measurement: lx
    update_interval: 60s
    filters:
      - lambda: |-
          return (x / 10000.0) * 20000000.0;

binary_sensor:
  - platform: gpio
    pin: D5
    name: "Living Room PIR Sensor"
    device_class: motion
    
switch:
  - platform: template
    name: "Living Room MH-Z19C Auto Calibrate"
    optimistic: true
    on_turn_on:
      mhz19.abc_enable: living_room_mhz19c
    on_turn_off:
      mhz19.abc_disable: living_room_mhz19c
  - platform: restart
    name: "Living Room Restart"  

Looks a little like this when all hooked up:

image

Notes

My esp8266 board has only three 3v3 pins so I had so join two of the sensors + cables to one pin.

In the esphome documentation for the MH-Z19 sensor it mentions that the temp reading on the this sensor is inaccurate but as you can see it is very close to the DHT22 reading so if you don’t need humidity value then the DHT22 can be left out.

These little boards are great for connecting them to existing devices with USB ports for power without wasting a socket. I have one connected to my wifi router’s USB port, one to my SmartThings hub, one to the Nvidia Shield TV.

My temperature offset for the DHT22 was -2.3 degrees C so just change this with your setup.

The case also has space for an LED so if you print this in white that can be connected also for notifications etc.

9 Likes

Pretty cool nice job!

/Morten

Looks really nice! Where did you mount the TEMT6000 light sensor? Any pictures of that?

I guess it’s behind the hole on the top (visible on the photo with the black enclosure).

Yes it slots in the top.

Thanks! Looks great!

It looks great, but I’m really having problems with assembly (this is my first ESPHome device).

How do you attach the sensors, in particular ensuring that the light sensor doesn’t move?

The light sensor does have a little plastic pin that it goes into on the case but you will need to hot glue it in place.

Nice setup

I have been fiddling with mhz19c as well, curious to see what is behind your calibration slider?
I can’t seem to get it to calibrate on my side

What do you mean calibration slider? The on/off button from above? Look inside the esphome code, it’s all there.
You have it give it quite a bit time for it to start registering, several hours at least.
It will log 500 or something similar until it is ready.

i just wanted to thank you for this post, this sensor was driving me crazy
i waited 2 to 3 days for it to calibrate and be ready