esphome / issues

Issue Tracker for ESPHome
https://esphome.io/
291 stars 34 forks source link

MH-Z19C Co2 Sensor: Zeropoint Calibration not working #5515

Open ar-ml opened 4 months ago

ar-ml commented 4 months ago

The problem

(Please check my code below!)

I also tried it using the code from the documentation, but it did not work either: https://esphome.io/components/sensor/mhz19.html

(Please check below what I see in the logs, when I push the button for triggering zero point calibration.)

Could it be that mhz19.calibrate_zero Action is not working with MH-Z19C ??? Can you fix that?

Which version of ESPHome has the issue?

2024.2.0

What type of installation are you using?

Home Assistant Add-on

Which version of Home Assistant has the issue?

2024.1.3

What platform are you using?

ESP32

Board

Berrybase NMCU-ESP32

Component causing the issue

No response

Example YAML snippet

esphome:
  name: zw-esp32-co2
  friendly_name: ZW_ESP32_CO2

esp32:
  board: esp32dev
  framework:
    type: arduino

# Example configuration co2 sensor MH-Z19
uart:
  rx_pin: GPIO3
  tx_pin: GPIO1
  baud_rate: 9600

sensor:
  - platform: mhz19
    co2:
      name: "MH-Z19 CO2 Value"
    temperature:
      name: "MH-Z19 Temperature"
    update_interval: 25s
    automatic_baseline_calibration: true
    id: zw_esp32_co2_id

button: #creates a button to calibrate the sensor - this will reset the zero point so use it only when it's been 20 minutes either outside or in a room you know the co2 level is at a minimum
  - platform: template
    name: "Calibrate Zero (20 minutes at 400ppm)"
    id: calibrate_zero
    entity_category: diagnostic
    on_press:
      - mhz19.calibrate_zero: zw_esp32_co2_id

switch: # this will expose a switch to home assistant to turn on and off the ABC
  - platform: template
    name: "Automatic Baseline Calibration"
    entity_category: diagnostic
    optimistic: true
    on_turn_on:
      mhz19.abc_enable: zw_esp32_co2_id
    on_turn_off:
      mhz19.abc_disable: zw_esp32_co2_id

binary_sensor: # exposes online status
  - platform: status
    name: "Sensor Status"

text_sensor:
  - platform: wifi_info
    ip_address: # exposes the IP Address when connected
      internal: true
      id: wifi_ip_addr
      name: "IP Address"
    ssid: # exposes the SSID when connected
      internal: true
      id: wifi_ssid

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "XXXXXXX"

ota:
  password: "XXXXXXX"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Zw-Esp32-Co2 Fallback Hotspot"
    password: "XXXXXXX"

captive_portal:

Anything in the logs that might be useful for us?

[00:32:47][D][button:010]: 'Calibrate Zero (20 minutes at 400ppm)' Pressed.
[00:32:47][D][mhz19:065]: MHZ19 Calibrating zero point
[00:32:47][W][component:214]: Component api took a long time for an operation (0.15 s).
[00:32:47][W][component:215]: Components should block for at most 20-30ms.
[00:32:52][D][mhz19:057]: MHZ19 Received CO₂=820ppm Temperature=5°C Status=0x00
[00:32:52][D][sensor:094]: 'MH-Z19 CO2 Value': Sending state 820.00000 ppm with 0 decimals of accuracy
[00:32:53][D][sensor:094]: 'MH-Z19 Temperature': Sending state 5.00000 °C with 0 decimals of accuracy

Additional information

No response

ar-ml commented 4 months ago

I contacted the manufactorer Winsen Sensor and got the following reply:

Q1: Why is Zeropoint Calibration not working? For the MH-Z19C Co2 Sensor there are two ways to calibrate the zero point:

Q2: How to switch auto-calibration (ABC) between 1 day and 7 day cycle?

Is there anyone who can update the ESPhome mhz19 component code, to support these commands? https://esphome.io/components/sensor/mhz19.html https://github.com/esphome/esphome/tree/dev/esphome/components/mhz19

ar-ml commented 4 months ago

Update: A dev checked the code and found out that zero point calibration should already be using the command mentioned above... No idea why it is not working then...

Maybe someone else wants to continue here one day...

I will probably switch to a different model / manufacturer now for further development: https://esphome.io/components/sensor/senseair.html (Seems to have much better ABC auto-calibration, and should work with sensor models Senseair Sunlight, Senseair Sunrise and Senseair S8.)

github-actions[bot] commented 1 day ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.