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:
- NodeMCU-32S ESP32 WiFi (V 1.2 or V 1.1) (Bastelgarage.ch / Affiliate Aliexpress)
- MH-Z19B NDIR CO2 Sensor (Bastelgarage.ch / Affiliate Aliexpress)
- 1x Breadboard
- 4x Jumper Wires M/M
Used Software:
- Homeassistant (any Installation)
- ESP Home on Docker
- Esphome-Flasher
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:
- docker pull esphome/esphome
- docker run -v /MyDockerVols/ESPHome:/config -p 6052:6052 -d esphome/esphome
- 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).
- Add a new node on the website ( “+” on the bottom right)
- Follow the steps in the wizard.
- I will name my node co2
- Device type will be NodeMCU-32S
- IF you have Wifi add your SSID and password in step 4. (Required for OTA Updates)
- Finish and submit
- 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
- Hit save and click on compile
- After successfully compiling the code you can now download the binary.
- Now head over to https://github.com/esphome/esphome-flasher and download the ESPHome-Flasher for your OS.
- Open ESPHome-Flasher and search your firmware binary.
- 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 :D
- Open Homeassistant and open Integrations
- Search for ESPHome
- Add the IP of your device (It will be visible on the ESP Home Terminal)
- Enjoy your CO2 Sensor