This is a bit of a niche post, but it might help someone to accomplish this in less time than I did. The tutorial will be as easy as it gets. Since the guys from ESPHome did a great job and almost everything you could wish for is already managed by ESPHome.

Required Hardware:

Used Software:

This image has an empty alt attribute; its file name is 421479-23-800x800-1.jpg

Wiring the hardware

In the end, it should look something like this. UnfortunatelyI did not have the right colours 🙂

Wiring

ESPHome

This tutorial will not be too detailed, because I expect you to already have an ESP installation at home or enough experience to install it on Docker or Hassbian.

If you are using Hassbian:

This is pretty much installing it in the addons page on Homeassistant.

https://esphome.io/guides/getting_started_hassio.html

If you want to use ESPHome on Docker use the following:

  1. docker pull esphome/esphome
  2. docker run -v /MyDockerVols/ESPHome:/config -p 6052:6052 -d esphome/esphome
  3. Connect to the website on port 6052

Flashing your Device with ESPHome

First, you need to download the ESPHome flasher, this needs to be done the first time. After that, we can update our devices Over the air (OTA).

  1. Add a new node on the website ( “+” on the bottom right)
  2. Follow the steps in the wizard.
  3. I will name my node co2
  4. Device type will be NodeMCU-32S
  5. IF you have Wifi add your SSID and password in step 4. (Required for OTA Updates)
  6. Finish and submit
  1. After completing this hit edit on your new node, this is where we will put in our changes. Add the following to your code.
uart:
  rx_pin: 3
  tx_pin: 1
  baud_rate: 9600

sensor:
  - platform: mhz19
    co2:
      name: "MH-Z19 CO2 Value"
    temperature:
      name: "MH-Z19 Temperature"
    update_interval: 60s
    automatic_baseline_calibration: false
  1. Hit save and click on compile
  2. After successfully compiling the code you can now download the binary.
  3. Now head over to https://github.com/esphome/esphome-flasher and download the ESPHome-Flasher for your OS.
  4. Open ESPHome-Flasher and search your firmware binary.
  1. Hold this button on your board, then hit Flash ESP

The board will now connect to your Wifi network and you can access it via Homeassistant.

Adding the sensor to homeassistant

This one is pretty self-explanatory but I like my tutorials complete 😀

  1. Open Homeassistant and open Integrations
  2. Search for ESPHome
  3. Add the IP of your device (It will be visible on the ESP Home Terminal)
  4. Enjoy your CO2 Sensor