Read MH-Z19 CO2 meter to Domoticz using an arduino and esp8266

  Domoticz

In order to further automate the ventilation of my house I want to be able to measure CO2 levels in the livingroom and have the ventilation adjusted according.


This post describes how to connect everything and get the readings to Domoticz. In a next post I will describe how to use these readings to setup automatic home ventilation.


Domoticz Setup

Before we start messing with the ESP and connecting the MH-Z19 to the arduino, we need to create a dummy device to update the status to in Domoticz.

In Domoticz go to Setup > Hardware and, if you don’t have one already, add the dummy hardware (1,2). And then click create a virtual switch.

Now add a new virtual sensor, choose Custom Sensor as the Sensor Type. The name is up to you.

Add Custom Sensor

In Domoticz go to Setup > Devices, locate the custom sensor just created and make note of it’s IDx, we will need it later.

Custom Sensor IDx 325


ESP8266 Setup

I prefer to have the correct and most recent arduino drivers present on my computer, to do this. I install Arduino IDE from the windows 10 store, this way it is kept up to date for me automatically. But obviously there are several way’s to get the drivers.

ESP8266

Next we download the latest version of ESP Easy by letscontrolit. ESP Easy can be found on their github page.

Then flash the firmware by using FlashESP8266.exe

For a much more comprehensive story on how to flash these see their wiki.

Finish the installation by following the last steps on the wiki.

Where to go from here

If everything has gone right you have a useable ESP Easy device now.

As no parameters are set it will go to "AP mode" for configuration.

Use your computer, tablet or smartphone and search a WiFi network named "ESP_Easy_0".

Connect to ESP_Easy_0 using the password "configesp" (without "").

Open your internet browser and type 192.168.4.1 as internet address into the browser. The WiFi setup of the ESP Easy opens.

You can choose your WiFi network now. Select the SSID and enter your passphrase, click connect.

It will take 20 seconds until a result is shown. If you typed everything correctly it will show a message that it is connected to the network and it shows the IP address.

Note the IP address!

Connect your computer or whatever back to your usual network. Open a browser and type the ip address into the browser.

You should see the config pages of ESPEasy now.

Connecting MH-Z19 to ESP8266

Now that we have got Domoticz and the ESP8266 ready let’s hook everything up. Connecting everything is very simple. Just connect everything up as in the follows. Note that i’m using VU (usb power output pin) to supply 5v to the MH-Z19.

ESP8266 and MH-Z19


Power-up the Arduino and connect to it’s ip adress.

Under the tab controllers input the details of your domoticz.

ESPEasy settings

 

Next, under the devices tab add the MH-Z19 sensor and give the domoticz device IDx for the virtual device that was created at the beginning.

ESPEasy settings

After submitting the settings you should see the device starts to update in Domoticz.

Thank you for Chang and TD-er for making the fritzing components

5 thoughts on - Read MH-Z19 CO2 meter to Domoticz using an arduino and esp8266

  • Ben zeer geïnteresseerd in dit projectje. Heb inmiddels domoticz draaien om mijn p1 meter uit te lezen. Nu wil ik de mechanische ventilatie beter gaan aansturen via Domoticz.
    Hoewel ik thuis ben in linux, is de wereld van domotica nieuw voor me. Kan ik jou via mail vragen stellen als ik vastloop? Met vriendelijke groet, Pieter uit Arnhem

    • 2 mogelijkheden waar je eens naar kunt kijken zijn heb je de juiste idx opgegeven in de devices tab van espeasy? Of iIs het formaat waarin de data binnen komt het probleem, misschien een , als decimalen scheidingsteken waar Domoticz een . verwacht?

LEAVE A COMMENT