esphome / issues

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

SCD41 (Sensirion CO2, Temperature, and Humidity Sensor) periodically stops reporting measurements #2832

Open Jsakkos opened 2 years ago

Jsakkos commented 2 years ago

The problem

The sensor will occasionally become unresponsive and send the message "Data not ready yet". Power cycling the device has no effect.

Which version of ESPHome has the issue?

2021.12.1

What type of installation are you using?

Home Assistant Add-on

Which version of Home Assistant has the issue?

2021.11.5

What platform are you using?

ESP8266

Board

Wemos D1 mini 4mb

Component causing the issue

i2c

Example YAML snippet

esphome:
  name: air-quality-1
  platform: ESP8266
  board: d1_mini
i2c:
  sda: 4
  scl: 5
  scan: true
  id: bus_a
sensor:
  - platform: scd4x
    co2:
      name: "CO2"
      id: "co2"
    temperature:
      name: "Temperature"
      id: "temperature"
    humidity:
      name: "Humidity"
      id: "humidity"
    update_interval: 30s

Anything in the logs that might be useful for us?

[17:51:01][W][scd4x:175]: Data not ready yet!

Additional information

Seems similar to this issue with the SCD30: https://github.com/esphome/issues/issues/987

probot-esphome[bot] commented 2 years ago

Hey there @sjtrny, mind taking a look at this issue as it has been labeled with an integration (scd4x) you are listed as a code owner for? Thanks! (message by CodeOwnersMention)

sjtrny commented 2 years ago

Any chance you can test with an ESP32 instead?

Jsakkos commented 2 years ago

@sjtrny I unfortunately don't have any ESP32 devices. One thing I will add is that I have 4 of these setup, and only one has this issue. I've tried swapping out the SCD41 itself, reflashing the device OTA, and swapping out the ESP8266 itself. The strange thing is that after a reflash, it will work properly for ~ 30 mins before displaying this message.

agrueing commented 2 years ago

Can confirm on an ESP32

tbailey1712 commented 2 years ago

On an esp8266 nodemcu, having the same issue. The sensor initializes and displays its serial number. The response is "data not ready yet" each time it is polled.

I don't believe the board is defective as it has did output data one time for me. Sensor is an SCD41 from Adafruit.

nicolasff commented 2 years ago

This looks very similar to what I'm seeing, I've just asked about it in the Adafruit forums. Mine isn't using ESPHome though, it's connected to an ESP32-S2 running CircuitPython.

When I detect that it's been too long without data (> 5 min), I stop the periodic measurements, re-initialize the sensor, and start measuring again:

if time.monotonic() - last_co2_read_time > 300:
    print('Stopping periodic measurements')
    scd4x.stop_periodic_measurement()
    time.sleep(1)
    print('Reinitializing CO2 sensor')
    scd4x.reinit()
    time.sleep(1)
    print('Starting periodic measurements again')
    scd4x.start_periodic_measurement()

I don't know enough about ESPHome to tell, but is it possible to program in this kind of workaround with the YAML config? Ideally the best would be to avoid such hacks and have the sensor keep working.

This workaround is usually enough to receive some data again, but it usually doesn't last long and soon enough I'm having the issue once more. In some cases calling reinit doesn't fix it, so I have some code to detect this and restart the whole board; after a reboot I've always seen it produce data again.

I've tried using the sensor both in its regular periodic measurement mode and its low-power mode, and this has made no difference. In both cases I eventually end up stuck on data_ready == False forever. It was said above that it can take ~30 minutes for it to get stuck; for me it's completely unpredictable. Sometimes it takes just 5 minutes, other times 12+ hours.

Since I can use CircuitPython to send commands to the sensor, is there anything I could try to help find what's causing this issue?

edit: I've had good success changing from a periodic measurement to the "one-shot" reads documented in section 3.10.1 of the datasheet. I used the existing methods from the client, just with a new constant:

    def get_data_oneshot(scd4x):
        scd4x._send_command(0x219D, cmd_delay=5)
        scd4x._read_data()

It usually gives me a reading, although even this approach fails from time to time. If you're encountering this issue and are able to use single-shot reads, I'd suggest giving it a try.

V4l3n10 commented 2 years ago

@Jsakkos I am trying to do the same as you are. I will be using an ESP32-S2 Feather. Would you share your code please. Thanks

Freyert commented 1 year ago

Connecting this to a forum post:

General troubleshooting tip, add the following to your configuration:

# Enable logging
logger:
    level: VERY_VERBOSE
nicolasff commented 1 year ago

I should have updated this GitHub issue after I updated my Adafruit forum post. I am no longer encountering this issue, at all.

I had originally connected my SCD-41 in a chain of sensors all connected with STEMMA QT/Qwiic cables with one end being a FeatherS2 Neo and the SCD-41 being the 3rd device in that chain. It went like this:

FeatherS2 Neo → PMSA0003I → MCP9808 → SCD-41 → multiplexer → (2 × SSD1327)

The problem was likely with the amount of power that could be carried by the STEMMA QT port on the Feather to this entire chain. I changed the first link of this chain from a STEMMA QT cable to 4 Dupont cables connected to the board's (5V, GND, SCL, SDA) and going to the PMSA0003I sensor (photo of the device after making this change). I left the rest of the chain as it was, and I never encountered this issue again.

So I would recommend making sure that you are supplying enough power to the SCD-41 sensor. Mine used to get into this "no data" state several times a day, and since making this change it hasn't happened even once.

Freyert commented 1 year ago

@nicolasff thanks for the update! I moved the 3v3 to the 5v pin and it started working again. 🙏 thanks so much!

:| oh no it's back!


In general it seems like initialization state machine is missing retry logic. Instead of just saying oops I couldn't read the firmware and then being dead, why doesn't it attempt multiple times to stop measurements and read firmware?


Looks like I need to restart it every once in awhile. Starting to see a lot of other buggy things:

buggy logs ```console [10:07:42][C][restart.button:017]: Restart Button 'Basement Restart' [10:07:43][C][scd4x:094]: scd4x: [10:07:43][C][scd4x:095]: Address: 0x62 [10:07:43][C][scd4x:112]: Automatic self calibration: ON [10:07:43][C][scd4x:121]: Ambient pressure compensation disabled [10:07:43][C][scd4x:122]: Altitude compensation: 0m [10:07:43][C][scd4x:133]: Measurement mode: single shot [10:07:43][C][scd4x:139]: Temperature offset: 4.00 °C [10:07:43][C][scd4x:140]: Update Interval: 60.0s [10:07:43][C][scd4x:141]: CO2 'scd43 CO2' [10:07:43][C][scd4x:141]: Device Class: 'carbon_dioxide' [10:07:43][C][scd4x:141]: State Class: 'measurement' [10:07:43][C][scd4x:141]: Unit of Measurement: 'ppm' [10:07:43][C][scd4x:141]: Accuracy Decimals: 0 [10:07:43][C][scd4x:141]: Icon: 'mdi:molecule-co2' [10:07:43][C][scd4x:142]: Temperature 'scd43 Temperature' [10:07:43][C][scd4x:142]: Device Class: 'temperature' [10:07:43][C][scd4x:142]: State Class: 'measurement' [10:07:43][C][scd4x:142]: Unit of Measurement: '°C' [10:07:43][C][scd4x:142]: Accuracy Decimals: 2 [10:07:43][C][scd4x:142]: Icon: 'mdi:thermometer' [10:07:43][C][scd4x:143]: Humidity 'scd43 Humidity' [10:07:43][C][scd4x:143]: Device Class: 'humidity' [10:07:43][C][scd4x:143]: State Class: 'measurement' [10:07:43][C][scd4x:143]: Unit of Measurement: '%' [10:07:43][C][scd4x:143]: Accuracy Decimals: 2 [10:07:43][C][scd4x:143]: Icon: 'mdi:water-percent' [10:07:43][C][mdns:084]: mDNS: [10:07:43][C][mdns:085]: Hostname: scd43-basement [10:07:43][C][ota:085]: Over-The-Air Updates: [10:07:43][C][ota:086]: Address: scd43-basement.local:3232 [10:07:43][C][ota:089]: Using Password. [10:07:43][C][api:138]: API Server: [10:07:43][C][api:139]: Address: scd43-basement.local:6053 [10:07:43][C][api:141]: Using noise encryption: YES [10:07:48][D][api:102]: Accepted ::FFFF:192.168.1.91 [10:07:48][D][api.connection:861]: Home Assistant 2022.8.1 (::FFFF:192.168.1.91): Connected successfully [10:08:30][E][sensirion_i2c:026]: CRC8 Checksum invalid at pos 1! 0x0F != 0x08 [10:09:30][D][sensor:125]: 'scd43 CO2': Sending state 622.00000 ppm with 0 decimals of accuracy [10:09:30][D][sensor:125]: 'scd43 Temperature': Sending state 18.65967 °C with 2 decimals of accuracy [10:09:30][D][sensor:125]: 'scd43 Humidity': Sending state 60.92072 % with 2 decimals of accuracy [10:10:30][D][sensor:125]: 'scd43 CO2': Sending state 627.00000 ppm with 0 decimals of accuracy [10:10:30][D][sensor:125]: 'scd43 Temperature': Sending state 18.69438 °C with 2 decimals of accuracy [10:10:30][D][sensor:125]: 'scd43 Humidity': Sending state 61.17249 % with 2 decimals of accuracy [10:11:31][W][scd4x:175]: Data not ready yet! INFO scd43-basement.local: Ping timed out! INFO Disconnected from ESPHome API for scd43-basement.local WARNING Disconnected from API INFO Successfully connected to scd43-basement.local ```
Freyert commented 1 year ago

I've tried setting it to lower and lower power modes. Seems to do better that way.

The data sheet seems to indicate it needs 11-13 mA when running with periodic measurements, and 115-137 mA for high performance at 5V.

I found this ESPHome documentation that indicates the default "drive strength" is about 20 mA. https://esphome.io/guides/configuration-types.html#pin-schema

sensiron power data

https://sensirion.com/media/documents/C4B87CE6/627C2DCD/CD_DS_SCD40_SCD41_Datasheet_D1.pdf

I'm fairly new to this so I can't quite understand if my board is capable of supplying the sort of power the SCD41 needs:

https://docs.espressif.com/projects/esp-idf/en/latest/esp32c3/hw-reference/esp32c3/user-guide-devkitm-1.html

svde commented 7 months ago

Managed to fix this with the factory_reset Action.

Edit: not a long-term fix.

martinanton commented 7 months ago

I can't find my scd41. could you please post your yaml?

i use: https://shop.m5stack.com/products/co2l-unit-with-temperature-and-humidity-sensor-scd41

Communication failed! Is the sensor connected?

[17:23:32][I][i2c.arduino:069]: Results from i2c bus scan: [17:23:32][I][i2c.arduino:071]: Found no i2c devices!

[17:23:32][C][scd4x:095]: Address: 0x62 [17:23:32][W][scd4x:099]: Communication failed! Is the sensor connected? [17:23:32][C][scd4x:112]: Automatic self calibration: ON [17:23:32][C][scd4x:121]: Ambient pressure compensation disabled [17:23:32][C][scd4x:122]: Altitude compensation: 0m [17:23:32][C][scd4x:127]: Measurement mode: periodic (5s) [17:23:32][C][scd4x:139]: Temperature offset: 4.00 °C [17:23:32][C][scd4x:140]: Update Interval: 30.0s

[17:23:32][C][scd4x:141]: Device Class: 'carbon_dioxide' [17:23:32][C][scd4x:141]: State Class: 'measurement' [17:23:32][C][scd4x:141]: Unit of Measurement: 'ppm' [17:23:32][C][scd4x:141]: Accuracy Decimals: 0

[17:23:32][C][scd4x:142]: Device Class: 'temperature' [17:23:32][C][scd4x:142]: State Class: 'measurement' [17:23:32][C][scd4x:142]: Unit of Measurement: '°C' [17:23:32][C][scd4x:142]: Accuracy Decimals: 2

[17:23:32][C][scd4x:143]: Device Class: 'humidity' [17:23:32][C][scd4x:143]: State Class: 'measurement' [17:23:32][C][scd4x:143]: Unit of Measurement: '%' [17:23:32][C][captive_portal:088]: Captive Portal:

thanxs to all! ;-)

R1DEN commented 6 months ago

Every disturbance in power delivery results in the sensor not working, until I restart the ESP. After restart it can work for more than a day without any issues.

I've just set up everything on a breadboard, the module is just hanging. And every time I move it - it's not reporting after. Maybe an auto re-init should be implemented?