esphome / issues

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

C8 CO2 sensor looks like MH-Z19 but is not. Results in "Reading from UART timed out at byte 0!" and sometimes in "Invalid preamble" #4534

Closed moritzschaefer closed 11 months ago

moritzschaefer commented 1 year ago

The problem

Similarly to #488, I get "Reading from UART timed out at byte 0!" error messages with the MH-Z19C (https://www.ebay.de/itm/225181851233).

As shown in the logs and yaml below, I am using UART2 and disable uart-logging, so my issue seems to be different from #488.

Pin-wise, I only connect GND and 5V on one side and RX and TX on the other side.

Can you see anything in the logs that hints towards what's wrong?

Which version of ESPHome has the issue?

2022.10.2 & 2023.05.03

What type of installation are you using?

pip

Which version of Home Assistant has the issue?

No response

What platform are you using?

ESP8266

Board

nodemcu v2/3

Component causing the issue

uart/mh-z19

Example YAML snippet

esphome:
  name: mowater
  platform: ESP8266
  board: nodemcuv2

wifi:
  ssid: "Monet"
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Mowater Fallback Hotspot"
    password: "VynwNZN3glml"
  manual_ip:
    # Set this to the IP of the ESP
    static_ip: 192.168.0.13
    # Set this to the IP address of the router. Often ends with .1
    gateway: 192.168.0.1
    # The subnet of the network. 255.255.255.0 works for most home networks.
    subnet: 255.255.255.0

uart:
  id: mhz19_uart
  rx_pin: GPIO13
  tx_pin: GPIO15
  # rx_pin: GPIO3
  # tx_pin: GPIO1
  baud_rate: 9600
  debug:

captive_portal:

# Enable logging
logger:
# Disable UART Logging
  baud_rate: 0
  level: VERY_VERBOSE

# Enable Home Assistant API
api:

ota:

sensor:

  - platform: mhz19
    co2:
      name: "MH-Z19 CO2 Value"
    temperature:
      name: "MH-Z19 Temperature"
    update_interval: 10s
    automatic_baseline_calibration: false
    uart_id: mhz19_uart

Anything in the logs that might be useful for us?

[22:46:46][I][app:102]: ESPHome version 2022.10.2 compiled on Jan  1 1980, 00:00:00
[22:46:46][C][wifi:502]: WiFi:
[22:46:46][C][wifi:360]:   Local MAC: 8C:AA:B5:C5:DF:E8
[22:46:46][C][wifi:361]:   SSID: 'Monet'
[22:46:46][C][wifi:362]:   IP Address: 192.168.0.13
[22:46:46][C][wifi:363]:   BSSID: 34:2C:C4:35:FE:B4
[22:46:46][C][wifi:365]:   Hostname: 'mowater'
[22:46:46][C][wifi:367]:   Signal strength: -58 dB ▂▄▆█
[22:46:46][V][wifi:369]:   Priority: 0.0
[22:46:46][C][wifi:371]:   Channel: 1
[22:46:46][C][wifi:372]:   Subnet: 255.255.255.0
[22:46:46][C][wifi:373]:   Gateway: 192.168.0.1
[22:46:46][C][wifi:374]:   DNS1: 0.0.0.0
[22:46:46][C][wifi:375]:   DNS2: 0.0.0.0
[22:46:46][C][logger:275]: Logger:
[22:46:46][C][logger:276]:   Level: VERY_VERBOSE
[22:46:46][C][logger:277]:   Log Baud Rate: 0
[22:46:46][C][logger:278]:   Hardware UART: UART0
[22:46:46][C][uart.arduino_esp8266:102]: UART Bus:
[22:46:46][C][uart.arduino_esp8266:103]:   TX Pin: GPIO15
[22:46:46][C][uart.arduino_esp8266:104]:   RX Pin: GPIO13
[22:46:46][C][uart.arduino_esp8266:106]:   RX Buffer Size: 256
[22:46:46][C][uart.arduino_esp8266:108]:   Baud Rate: 9600 baud
[22:46:46][C][uart.arduino_esp8266:109]:   Data Bits: 8
[22:46:46][C][uart.arduino_esp8266:110]:   Parity: NONE
[22:46:46][C][uart.arduino_esp8266:111]:   Stop bits: 1
[22:46:46][C][uart.arduino_esp8266:113]:   Using hardware serial interface.
[22:46:46][C][mhz19:094]: MH-Z19:
[22:46:46][C][mhz19:095]:   CO2 'MH-Z19 CO2 Value'
[22:46:46][C][mhz19:095]:     Device Class: 'carbon_dioxide'
[22:46:46][C][mhz19:095]:     State Class: 'measurement'
[22:46:46][C][mhz19:095]:     Unit of Measurement: 'ppm'
[22:46:46][C][mhz19:095]:     Accuracy Decimals: 0
[22:46:46][C][mhz19:095]:     Icon: 'mdi:molecule-co2'
[22:46:46][C][mhz19:096]:   Temperature 'MH-Z19 Temperature'
[22:46:46][C][mhz19:096]:     Device Class: 'temperature'
[22:46:46][C][mhz19:096]:     State Class: 'measurement'
[22:46:46][C][mhz19:096]:     Unit of Measurement: '°C'
[22:46:46][C][mhz19:096]:     Accuracy Decimals: 0
[22:46:46][C][mhz19:102]:   Automatic baseline calibration disabled on boot
[22:46:46][C][captive_portal:088]: Captive Portal:
[22:46:46][C][mdns:100]: mDNS:
[22:46:46][C][mdns:101]:   Hostname: mowater
[22:46:46][V][mdns:102]:   Services:
[22:46:46][V][mdns:104]:   - _esphomelib, _tcp, 6053
[22:46:46][V][mdns:106]:     TXT: version = 2022.10.2
[22:46:46][V][mdns:106]:     TXT: mac = 8caab5c5dfe8
[22:46:46][V][mdns:106]:     TXT: platform = ESP8266
[22:46:46][V][mdns:106]:     TXT: board = nodemcuv2
[22:46:46][V][mdns:106]:     TXT: network = wifi
[22:46:47][C][ota:089]: Over-The-Air Updates:
[22:46:47][C][ota:090]:   Address: 192.168.0.13:8266
[22:46:47][C][api:138]: API Server:
[22:46:47][C][api:139]:   Address: 192.168.0.13:6053
[22:46:47][C][api:143]:   Using noise encryption: NO
[22:46:52][VV][scheduler:195]: Running interval 'update' with interval=10000 last_execution=11966 (now=21972)
[22:46:52][D][uart_debug:114]: <<< 42:4D:08:D0:08:8C:01:CB:01:2E:00:00:E2:11:02:EB:42:4D:08:D0:08:8C:01:CB:01:2E:00:00:E2:11:02:EB:42:4D:08:D0:08:8C:01:CB:01:2E:00:00:E2:11:02:EB:42:4D:08:D0:08:8D:01:CD:01:2E:00:00:E2:11:02:EE:42:4D:08:D0:08:8D:01:CD:01:2E:00:00:E2:11:02:EE:42:4D:08:D0:08:8D:01:CD:01:2E:00:00:E2:11:02:EE:42:4D:08:D0:08:8E:01:CD:01:2E:00:00:E2:11:02:EF:42:4D:08:D0:08:8E:01:CD:01:2E:00:00:E2:11:02:EF:42:4D:08:D0:08:8E:01:CD:01:2E:00:00:E2:11:02:EF:42:4D:08:D5:08:90
[22:46:52][D][uart_debug:114]: <<< 01:C9:01:2E:00:00:E2:11:02:F2
[22:46:52][VV][uart.arduino_esp8266:180]:     Flushing...
[22:46:52][E][uart:015]: Reading from UART timed out at byte 0!
[22:46:52][W][mhz19:034]: Reading data from MHZ19 failed!
[22:46:52][V][component:199]: Component mhz19.sensor took a long time for an operation (0.13 s).
[22:46:52][V][component:200]: Components should block for at most 20-30ms.
[22:46:52][D][uart_debug:114]: >>> FF:01:86:00:00:00:00:00:79
[22:47:00][VV][api.service:470]: on_ping_request: PingRequest {}
[22:47:00][VV][api.service:043]: send_ping_response: PingResponse {}
[22:47:01][VV][api.service:470]: on_ping_request: PingRequest {}
[22:47:01][VV][api.service:043]: send_ping_response: PingResponse {}
[22:47:02][VV][scheduler:195]: Running interval 'update' with interval=10000 last_execution=21966 (now=31974)
[22:47:02][D][uart_debug:114]: <<< 42:4D:08:D5:08:90:01:C9:01:2E:00:00:E2:11:02:F2:42:4D:08:D5:08:90:01:C9:01:2E:00:00:E2:11:02:F2:42:4D:08:D5:08:90:01:C9:01:2E:00:00:E2:11:02:F2:42:4D:08:D3:08:8C:01:C5:01:2E:00:00:E2:11:02:E8:42:4D:08:D3:08:8C:01:C5:01:2E:00:00:E2:11:02:E8:42:4D:08:D3:08:8C:01:C5:01:2E:00:00:E2:11:02:E8:42:4D:08:D3:08:8D:01:C2:01:2E:00:00:E2:11:02:E6:42:4D:08:D3:08:8D:01:C2:01:2E:00:00:E2:11:02:E6:42:4D:08:D3:08:8D:01:C2:01:2E:00:00:E2:11:02:E6:42:4D:08:D6:08:90
[22:47:02][D][uart_debug:114]: <<< 01:BC:01:2E:00:00:E2:11:02:E6
[22:47:02][VV][uart.arduino_esp8266:180]:     Flushing...
[22:47:02][E][uart:015]: Reading from UART timed out at byte 0!
[22:47:02][W][mhz19:034]: Reading data from MHZ19 failed!
[22:47:02][V][component:199]: Component mhz19.sensor took a long time for an operation (0.13 s).
[22:47:02][V][component:200]: Components should block for at most 20-30ms.
[22:47:02][D][uart_debug:114]: >>> FF:01:86:00:00:00:00:00:79
[22:47:07][VV][scheduler:195]: Running interval '' with interval=60000 last_execution=4294943887 (now=36597)
[22:47:12][VV][scheduler:195]: Running interval 'update' with interval=10000 last_execution=31966 (now=41973)
[22:47:12][D][uart_debug:114]: <<< 42:4D:08:D6:08:90:01:BC:01:2E:00:00:E2:11:02:E6:42:4D:08:D6:08:90:01:BC:01:2E:00:00:E2:11:02:E6:42:4D:08:D6:08:90:01:BC:01:2E:00:00:E2:11:02:E6:42:4D:08:D6:08:90:01:B5:01:2E:00:00:E2:11:02:DF:42:4D:08:D6:08:90:01:B5:01:2E:00:00:E2:11:02:DF:42:4D:08:D6:08:90:01:B5:01:2E:00:00:E2:11:02:DF:42:4D:08:D5:08:8E:01:AC:01:2E:00:00:E2:11:02:D3:42:4D:08:D5:08:8E:01:AC:01:2E:00:00:E2:11:02:D3:42:4D:08:D5:08:8E:01:AC:01:2E:00:00:E2:11:02:D3:42:4D:08:D5:08:92
[22:47:12][D][uart_debug:114]: <<< 01:A7:01:2E:00:00:E2:11:02:D2
[22:47:12][VV][uart.arduino_esp8266:180]:     Flushing...
[22:47:12][E][uart:015]: Reading from UART timed out at byte 0!
[22:47:12][W][mhz19:034]: Reading data from MHZ19 failed!
[22:47:12][V][component:199]: Component mhz19.sensor took a long time for an operation (0.13 s).
[22:47:12][V][component:200]: Components should block for at most 20-30ms.
[22:47:12][D][uart_debug:114]: >>> FF:01:86:00:00:00:00:00:79
[22:47:15][VV][api.service:470]: on_ping_request: PingRequest {}
[22:47:15][VV][api.service:043]: send_ping_response: PingResponse {}
[22:47:16][VV][api.service:470]: on_ping_request: PingRequest {}
[22:47:16][VV][api.service:043]: send_ping_response: PingResponse {}
[22:47:22][VV][scheduler:195]: Running interval 'update' with interval=10000 last_execution=41966 (now=51972)
[22:47:22][D][uart_debug:114]: <<< 42:4D:08:D5:08:92:01:A7:01:2E:00:00:E2:11:02:D2:42:4D:08:D5:08:92:01:A7:01:2E:00:00:E2:11:02:D2:42:4D:08:D4:08:91:01:A4:01:2E:00:00:E2:11:02:CD:42:4D:08:D4:08:91:01:A4:01:2E:00:00:E2:11:02:CD:42:4D:08:D4:08:91:01:A4:01:2E:00:00:E2:11:02:CD:42:4D:08:D4:08:91:01:A4:01:2E:00:00:E2:11:02:CD:42:4D:08:D4:08:92:01:A0:01:2E:00:00:E2:11:02:CA:42:4D:08:D4:08:92:01:A0:01:2E:00:00:E2:11:02:CA:42:4D:08:D4:08:92:01:A0:01:2E:00:00:E2:11:02:CA:42:4D:08:D4:08:92
[22:47:22][D][uart_debug:114]: <<< 01:9D:01:2E:00:00:E2:11:02:C7
[22:47:22][VV][uart.arduino_esp8266:180]:     Flushing...
[22:47:22][E][uart:015]: Reading from UART timed out at byte 0!
[22:47:22][W][mhz19:034]: Reading data from MHZ19 failed!
[22:47:22][V][component:199]: Component mhz19.sensor took a long time for an operation (0.13 s).
[22:47:22][V][component:200]: Components should block for at most 20-30ms.
[22:47:22][D][uart_debug:114]: >>> FF:01:86:00:00:00:00:00:79
[22:47:30][VV][api.service:470]: on_ping_request: PingRequest {}
[22:47:30][VV][api.service:043]: send_ping_response: PingResponse {}
[22:47:31][VV][api.service:470]: on_ping_request: PingRequest {}
[22:47:31][VV][api.service:043]: send_ping_response: PingResponse {}
[22:47:32][VV][scheduler:195]: Running interval 'update' with interval=10000 last_execution=51966 (now=61969)

Additional information

No response

remb0 commented 1 year ago

I have the same problem :(

moritzschaefer commented 1 year ago

I read thorugh all the comments from all the threads I found again and esphome claims it's a 'hardware issue' with the NodeMCUs. Apparently, other ESP-based board designs are working fine

74ls04 commented 12 months ago

You accidentally ended up with an HC8 sensor, another Chinese one -- I did the same thing. There are multiple eBay listings selling it as an MH-Z19 sensor but it has a completely different protocol. See this link .

moritzschaefer commented 11 months ago

Kind of sad that I gaslighted myself by lengthy threads on connectivity issues between MH-Z19 and NodeMCU. Would be amazing if someone builds an esphome plugin for this decide. I can't commit to it unfortunately at the moment