Can't get MH-Z19b with ESP32 to update or even show online

Keep getting this message. I’ve cleaned build files, removed and reinstalled ESPhome, and can’t get this work correctly. Also shows offline.


> 
> ```
> In file included from /data/cache/platformio/packages/framework-arduinoespressif32/cores/esp32/esp32-hal.h:79,
>                  from /data/cache/platformio/packages/framework-arduinoespressif32/cores/esp32/Arduino.h:36,
>                  from src/esphome/core/macros.h:7,
>                  from src/esphome/core/defines.h:2,
>                  from src/esphome/components/api/api_connection.h:3,
>                  from src/esphome/components/api/api_connection.cpp:1:
> /data/cache/platformio/packages/framework-arduinoespressif32/cores/esp32/esp32-hal-gpio.h:29:10: fatal error: pins_arduino.h: No such file or directory
> 
> **********************************************************************
> * Looking for pins_arduino.h dependency? Check our library registry!
> *
> * CLI  > platformio lib search "header:pins_arduino.h"
> * Web  > https://registry.platformio.org/search?q=header:pins_arduino.h
> *
> **********************************************************************
> 
>  #include "pins_arduino.h"
>           ^~~~~~~~~~~~~~~~
> compilation terminated.
> *** [.pioenvs/c02monitor/src/esphome/components/api/api_connection.cpp.o] Error 1
> In file included from /data/cache/platformio/packages/framework-arduinoespressif32/cores/esp32/esp32-hal.h:79,
>                  from /data/cache/platformio/packages/framework-arduinoespressif32/cores/esp32/Arduino.h:36,
>                  from src/esphome/core/macros.h:7,
>                  from src/esphome/core/defines.h:2,
>                  from src/esphome/components/api/api_frame_helper.h:7,
>                  from src/esphome/components/api/api_frame_helper.cpp:1:
> /data/cache/platformio/packages/framework-arduinoespressif32/cores/esp32/esp32-hal-gpio.h:29:10: fatal error: pins_arduino.h: No such file or directory
> 
> **********************************************************************
> * Looking for pins_arduino.h dependency? Check our library registry!
> *
> * CLI  > platformio lib search "header:pins_arduino.h"
> * Web  > https://registry.platformio.org/search?q=header:pins_arduino.h
> *
> **********************************************************************
> 
>  #include "pins_arduino.h"
>           ^~~~~~~~~~~~~~~~
> compilation terminated.
> *** [.pioenvs/c02monitor/src/esphome/components/api/api_frame_helper.cpp.o] Error 1
> In file included from /data/cache/platformio/packages/framework-arduinoespressif32/cores/esp32/esp32-hal.h:79,
>                  from /data/cache/platformio/packages/framework-arduinoespressif32/cores/esp32/Arduino.h:36,
>                  from src/esphome/core/macros.h:7,
>                  from src/esphome/core/defines.h:2,
>                  from src/esphome/components/api/api_pb2_service.h:6,
>                  from src/esphome/components/api/api_pb2_service.cpp:3:
> /data/cache/platformio/packages/framework-arduinoespressif32/cores/esp32/esp32-hal-gpio.h:29:10: fatal error: pins_arduino.h: No such file or directory
> 
> **********************************************************************
> * Looking for pins_arduino.h dependency? Check our library registry!
> *
> * CLI  > platformio lib search "header:pins_arduino.h"
> * Web  > https://registry.platformio.org/search?q=header:pins_arduino.h
> *
> **********************************************************************
> 
>  #include "pins_arduino.h"
>           ^~~~~~~~~~~~~~~~
> compilation terminated.
> *** [.pioenvs/c02monitor/src/esphome/components/api/api_pb2_service.cpp.o] Error 1
> ========================= [FAILED] Took 125.93 seconds =========================
> ```
> ```
> type or paste code here
> ```

My yaml

esphome:
  name: c02monitor
  friendly_name: C02Monitor
  platformio_options:
    platform: [email protected]
    framework: arduino

esp32:
  board: esp32dev
  framework:
   type: arduino
   

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "can'ttellya"

ota:
  - platform: esphome
    

wifi:
  ssid: "**"
  password: "***"

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "C02Monitor Fallback Hotspot"
    password: "**"

captive_portal:

uart:
  rx_pin: GPIO16
  tx_pin: GPIO17
  baud_rate: 9600

sensor:
  - platform: mhz19
    co2:
      name: "MH-Z19 CO2 Value"
    temperature:
      name: "MH-Z19 Temperature"
    update_interval: 60s
    automatic_baseline_calibration: false

Try removing those platformio_options.

1 Like

Try removing the PlatformIO options. Just a guess though :blush: - I have no idea…

1 Like

Couldn’t hurt.

I removed platformio_options and it installed 5.4.0 and received the same error.

It’s complaining about pins.
Are you sure about your board? Plain Esp32 aka Wroom32?
Try to clear every cache you can imagine on your setup.

it’s Wroom32, tried upesy_wroom in there as well.

This is what I got from my logs from ESPHome Web
18:51:38][D][api:122]: Accepted 192.168.1.162
[18:51:38][W][component:182]: Component api cleared Warning flag
[18:51:38][D][api.connection:1529]: Home Assistant 2025.5.3 (192.168.1.162): Connected successfully
[18:52:18][I][safe_mode:041]: Boot seems successful; resetting boot loop counter
[18:52:19][D][esp32.preferences:114]: Saving 1 preferences to flash...
[18:52:19][D][esp32.preferences:142]: Saving 1 preferences to flash: 0 cached, 1 written, 0 failed

I would start with a clean minimal YAML without the mhz sensor. Your problem appears to be happening during the compile. Using a new a device name and YAML file will get you to a clean state. It is possible things are really messed up and this might help show you exactly what is wrong.

I don’t know… I tried a new board, minimal yaml, MH-Z19 not installed, and still get the same .h error.

I cleared all the cleared my temp files… now my dashboards didnt’ restore. Just because I wanted a Co2 monitor.

This has caused more grief. Nothing but one issue after another with HA.

Another good place to ask is…

There is a common misconception that you MUST run the esphome compiler on your HA machine. This is not true. Of course, you can, but many people believe in keeping the two separate.

It sounds like your installation of esphome and/or its dependencies is corrupted. Your HA dashboard is likely a separate issue.

Most definitely the HA dashboard is something else. It’s just stack upon the other issues I have run into.

There are great YT and website on installation of MH-Z19/ESP32 and integration into HA. However there aren’t many on when you run into issues. Even using ChatGPT to find a solution hasn’t really resolved the issue I’m having.

I have uninstalled ESPhome several times, cleared cache, manually installed .bin via ESPHome Web .

I’m not running ESPHome compiler on my HA machine.

You do have missing indentation here.
I don’t understand how could it lead to those errors though…

How are you installing and uninstalling it?

How/which cache are you clearing?

esphome is a Python program I install it using the following:

pip install pipx
pipx install esphome

pip is the standard Python package installer
pipx is a tool that allows installing other Python tools into their own virtual environment.

esphome will install platform. io
platform.io has it’s own cache of tools and libraries that it installs. I suspect that something that it downloaded got corrupted.

I uninstall it from Settings>Add-ons. The Cache I clear is from ESPHome in HA clear install files. Then reboot HA. For the ESP32 board I reset it from ESPHome Web.

Do I use Terminal in HA to install PIP? That’s where I lack the knowledge.

that statement is inconsistent with the statement in the previous post

As far as I understand things that means you are installing and running esphome on your HA machine. You might be using a different computer to access it, but the compile and its dependencies are on the HA computer.

You can and I do install and run esphome on a completely different computer from where I run HA. HA is pushing people to use HAOS because it makes it easier to support things since they then know how things are installed. It does make some things easier. I don’t know if the commands you ran will actually clean up a corrupt platform.io install. It seems not.

Is there a different way to uninstall ESPHome from HA?

I don’t know. I also don’t know if it does or does not uninstall platform.io or if platform.io uninstalls its dependencies all the time. On my install, I know where platform.io installs its dependencies so I know where to delete things safely, so that it will install them again. There probably is a platformio way to get it to reinstall its dependencies.

esphome hides most of platformio from you. This is great when things work, but makes it significantly harder when things stop working. I have used platformio independently so have some understanding of what it is doing and how to get it to do what I want, but it is still challenging when things stop working.

What I’m getting now.

/data/cache/platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/lib/no-rtti/crt0.o: file not recognized: file format not recognized
collect2: error: ld returned 1 exit status
*** [.pioenvs/co2-monitor/firmware.elf] Error 1
========================= [FAILED] Took 217.59 seconds =========================

And what steps have taken to get to this point?

Uninstalled ESPHome from Add-ons, deleted the name of the unit in config/esphome, deleted config/archives, restarted, and reset the ESP32 device.

Reinstalled