Is MH-Z19B NDIR CO2 Sensor Compatible with Home Assistant (ESPHome)?
Electrical Specifications
Always confirm pin assignments against the manufacturer datasheet before wiring.
Compatibility Overview
Gold-plated NDIR carbon dioxide gas sensor measuring indoor CO2 levels from 0 to 5000 PPM with high selectivity.
Typical UART Wiring Reference
Standard UART signal names. This is a bus reference, not a pinout for this specific board — check the silkscreen and datasheet for its actual pin order.
Reference circuit only. A shifter is needed when the host and peripheral run at different logic levels — check both datasheets to confirm whether this applies to your pairing.
Technical Specification Matrix
| Feature / Attribute | Specification / Status |
|---|---|
| Hardware Protocol | UART Serial / 3.3V |
| Bridge Required | NO |
| Border Router Needed | None |
| Hardware Capabilities & Peripherals | Carbon Dioxide CO2 (PPM) Temperature (C) Automatic Calibration Note: these entities come from the ESPHome configuration you flash — each one needs its matching component in that YAML before it appears. |
| Pairing Complexity | Plug-and-Play |
| Factory Reset Instruction | Hold BOOT button for 3s. |
Wire, Flash, Adopt, Check
Wire it up
Follow the bus reference above. The host pins in the configuration are defaults — any free GPIO of the right kind will do, as long as the YAML names the pin you actually used.
Flash the configuration
Create a new device in the ESPHome dashboard (the Home Assistant add-on) and paste the configuration below into it, or save it as emb_esp32_mhz19b_esphome.yaml and run esphome run emb_esp32_mhz19b_esphome.yaml. The first flash goes over USB. If it is not detected, hold BOOT button for 3s to put it in download mode. Every update after that is over the air.
Adopt it in Home Assistant
Settings → Devices & Services. A node on the same network shows up as a discovered ESPHome device within a minute of joining Wi-Fi; choose Configure and enter the API encryption key from your secrets.yaml. If discovery does not find it, add the ESPHome integration by hand with the node's IP address.
Check it works
The entities on this page appear under the device in Home Assistant and update at the configured interval. The ESPHome log (Logs in the dashboard, or esphome logs) reports the setup of each component and any bus scan results at boot.
ESPHome Configuration
Starting configuration for MH-Z19B NDIR CO2 Sensor on ESP32. Untested on hardware — verify wiring and pins against your own board.
# ESPHome configuration for MH-Z19B NDIR CO2 Sensor
# Host: ESP32. Pin numbers below are host-side defaults — any free
# GPIO will do, and you should change them to match your own wiring.
esphome:
name: emb_esp32_mhz19b_esphome
friendly_name: "MH-Z19B NDIR CO2 Sensor"
esp32:
board: esp32dev
framework:
type: esp-idf
logger:
api:
encryption:
key: !secret api_encryption_key
ota:
- platform: esphome
password: !secret ota_password
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
uart:
rx_pin: GPIO16
tx_pin: GPIO17
baud_rate: 9600
sensor:
- platform: mhz19
co2:
name: "CO2"
temperature:
name: "Temperature"
update_interval: 60s
automatic_baseline_calibration: false
Before you flash:
the !secret values come from your
secrets.yaml, and the GPIO numbers are host-side
defaults rather than properties of this part — change them to match how you actually wired it.
Report a Pinout Error or Submit Tested Code Snippets
Found a pin mapping quirk or built a custom ESPHome YAML driver for MH-Z19B NDIR CO2 Sensor? Submit a pull request or report corrections to our index.