ESPHome SDM300D2 issue

Hi,
i try to configure an SDM300D2 Sensor.
I am getting this error message
[sm300d2:024]: Invalid preamble for SM300D2 response!
I am getting only some data shortly after the restart. Then the data transition from the sensor to the ESP stops.

Any idea?


esphome:
  name: airquality
  platform: ESP32
  board: wemos_d1_mini32
  
uart:
  rx_pin: GPIO17
  baud_rate: 9600
  rx_buffer_size: 1042

# Enable logging
logger:
  baud_rate: 0

# Enable Home Assistant API
api:

ota:
  password: "0d01544c3c9bb0bb9a5d60177df96ef4"

wifi:
  ssid: "Benno"
  password: "blablabla"

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

captive_portal:
 

sensor:
  - platform: sm300d2
    co2:
      name: "SM300D2 CO2 Value"
    formaldehyde:
      name: "SM300D2 Formaldehyde Value"
    tvoc:
      name: "SM300D2 TVOC Value"
    pm_2_5:
      name: "SM300D2 PM2.5 Value"
    pm_10_0:
      name: "SM300D2 PM10 Value"
    temperature:
      name: "SM300D2 Temperature Value"
    humidity:
      name: "SM300D2 Humidity Value"
    update_interval: 60s

Disable logger baud rate it probably uses the same uart

it is disbled

Is it?

logger:
  baud_rate: 0

Tried another pin?

I am not sure which board ypu use but try uart 0?

UART0: (GPIO 1 and GPIO3)
UART2: (GPIO 17 and GPIO 16)

(I am not 100% this applies to you board)

Hi,
i tried some GPIOs and different boards.
I assume the problem is the sensor itself.
since yesterday itā€™s connected to a LOLIN board and i get dataā€™s. But not constantly.
the update cycle for the different sensor dataā€˜s is inconsistent.

I just went through this effort to try out my first ESP32, SDM300D2, and ESPHome and Iā€™m getting the exact same response. It works for exactly 5 polling cycles and then a reboot. Then I managed 10 more polling cycles before I got the ā€œ[sm300d2:024]: Invalid preamble for SM300D2 response!ā€

[19:12:22][W][sm300d2:039]: Successfully read SM300D2 data
[19:12:22][D][sm300d2:049]: Received COā‚‚: 515 ppm
[19:12:22][D][sensor:131]: 'SM300D2 CO2 Value': Sending state 515.00000 ppm with 0 decimals of accuracy
[19:12:22][D][sm300d2:053]: Received Formaldehyde: 19 Āµg/mĀ³
[19:12:22][D][sensor:131]: 'SM300D2 Formaldehyde Value': Sending state 19.00000 Āµg/mĀ³ with 0 decimals of accuracy
[19:12:22][D][sm300d2:057]: Received TVOC: 73 Āµg/mĀ³
[19:12:22][D][sensor:131]: 'SM300D2 TVOC Value': Sending state 73.00000 Āµg/mĀ³ with 0 decimals of accuracy
[19:12:22][D][sm300d2:061]: Received PM2.5: 7 Āµg/mĀ³
[19:12:22][D][sensor:131]: 'SM300D2 PM2.5 Value': Sending state 7.00000 Āµg/mĀ³ with 0 decimals of accuracy
[19:12:22][D][sm300d2:065]: Received pm_10_0: 13 Āµg/mĀ³
[19:12:22][D][sensor:131]: 'SM300D2 PM10 Value': Sending state 13.00000 Āµg/mĀ³ with 0 decimals of accuracy
[19:12:22][D][sm300d2:069]: Received Temperature: 24.30 Ā°C
[19:12:22][D][sensor:131]: 'SM300D2 Temperature Value': Sending state 24.30000 Ā°C with 0 decimals of accuracy
[19:12:22][D][sm300d2:073]: Received Humidity: 45.40 percent
[19:12:22][D][sensor:131]: 'SM300D2 Humidity Value': Sending state 45.40000 % with 0 decimals of accuracy
[19:12:38][D][sensor:131]: 'WiFi Signal Sensor': Sending state -67.00000 dBm with 0 decimals of accuracy
[19:13:22][W][sm300d2:039]: Successfully read SM300D2 data
[19:13:22][D][sm300d2:049]: Received COā‚‚: 508 ppm
[19:13:22][D][sensor:131]: 'SM300D2 CO2 Value': Sending state 508.00000 ppm with 0 decimals of accuracy
[19:13:22][D][sm300d2:053]: Received Formaldehyde: 19 Āµg/mĀ³
[19:13:22][D][sensor:131]: 'SM300D2 Formaldehyde Value': Sending state 19.00000 Āµg/mĀ³ with 0 decimals of accuracy
[19:13:22][D][sm300d2:057]: Received TVOC: 68 Āµg/mĀ³
[19:13:22][D][sensor:131]: 'SM300D2 TVOC Value': Sending state 68.00000 Āµg/mĀ³ with 0 decimals of accuracy
[19:13:22][D][sm300d2:061]: Received PM2.5: 7 Āµg/mĀ³
[19:13:22][D][sensor:131]: 'SM300D2 PM2.5 Value': Sending state 7.00000 Āµg/mĀ³ with 0 decimals of accuracy
[19:13:22][D][sm300d2:065]: Received pm_10_0: 13 Āµg/mĀ³
[19:13:22][D][sensor:131]: 'SM300D2 PM10 Value': Sending state 13.00000 Āµg/mĀ³ with 0 decimals of accuracy
[19:13:22][D][sm300d2:069]: Received Temperature: 24.30 Ā°C
[19:13:22][D][sensor:131]: 'SM300D2 Temperature Value': Sending state 24.30000 Ā°C with 0 decimals of accuracy
[19:13:22][D][sm300d2:073]: Received Humidity: 45.40 percent
[19:13:22][D][sensor:131]: 'SM300D2 Humidity Value': Sending state 45.40000 % with 0 decimals of accuracy
[19:13:38][D][sensor:131]: 'WiFi Signal Sensor': Sending state -68.00000 dBm with 0 decimals of accuracy
[19:14:22][W][sm300d2:024]: Invalid preamble for SM300D2 response!
[19:14:38][D][sensor:131]: 'WiFi Signal Sensor': Sending state -68.00000 dBm with 0 decimals of accuracy
[19:15:22][W][sm300d2:024]: Invalid preamble for SM300D2 response!
[19:15:38][D][sensor:131]: 'WiFi Signal Sensor': Sending state -68.00000 dBm with 0 decimals of accuracy

A reboot of the ESP32 gets things going againā€¦ Did you find out what caused this? Defective SDM300D2 or ESP32?

Thanks!

This is a problem with esphome. Thereā€™s a fix here: https://github.com/esphome/esphome/pull/2261

1 Like

Having the same problems with a sm300d2 and and ESP32 running ESPHome 2021.8.2, but I think I found an odd workaround (the sensor has been providing HA with reading overnight without failing for the first time since I got it).

I first tried changing the UART buffer size, which seemed to work fine for a couple of hours. It turned out though, that it was only working as long as I had the post-flash log viewer on screen. Shortly after closing the browser tab, I realised things had broken again.

uart:
  rx_pin: GPIO3
  baud_rate: 9600
  rx_buffer_size: 512

After getting annoyed and deciding to move onto something else, I tried enabling MQTT inside of ESPHome for the ESP32 in question. The MQTT connection has never actually connected or worked (Iā€™m not entirely sure why yet), but for some strange reason, it seems to have fixed my serial issues. I can only assume itā€™s keeping the ESP32 awake which seems to be avoiding the serial buffer issue.

Looking forward to a proper fix, but as Iā€™ve not managed to get an hour of readings before, nevermind overnight, I thought this might interest someone.

edit: now Iā€™ve finally got some trending out of the sm300d2, Iā€™m very suspicious about the temp/humidity readings. Hereā€™s a comparison with a DHT-AM2302 that Iā€™ve been using around the house previously. The peaks and jumps in the DHT reading seem to correlate as expected with taps/doors/weather, where as the SM300d2 readings areā€¦ lacking?

1 Like

Yeah - things were working well for the last week or so - at 10-second intervals. It was wonderful. But after a few restarts - I canā€™t seem to keep anything flowing in unless I keep the live logs in a Web browser window. I upgraded to the latest version of ESPHome that had these latest updates in it (so I wouldnā€™t have to manually keep those two files in sync.) Not sure what happened. Will try to investigate a bit more.

[11:10:24][W][sm300d2:045]: Successfully read SM300D2 data
[11:10:24][D][sm300d2:058]: Received COā‚‚: 422 ppm
[11:10:24][D][sensor:121]: 'SM300D2 CO2 Value': Sending state 422.00000 ppm with 0 decimals of accuracy
[11:10:24][D][sm300d2:062]: Received Formaldehyde: 3 Āµg/mĀ³
[11:10:24][D][sensor:121]: 'SM300D2 Formaldehyde Value': Sending state 3.00000 Āµg/mĀ³ with 0 decimals of accuracy
[11:10:24][D][sm300d2:066]: Received TVOC: 15 Āµg/mĀ³
[11:10:24][D][sensor:121]: 'SM300D2 TVOC Value': Sending state 15.00000 Āµg/mĀ³ with 0 decimals of accuracy
[11:10:24][D][sm300d2:070]: Received PM2.5: 3 Āµg/mĀ³
[11:10:24][D][sensor:121]: 'SM300D2 PM2.5 Value': Sending state 3.00000 Āµg/mĀ³ with 0 decimals of accuracy
[11:10:24][D][sm300d2:074]: Received PM10: 6 Āµg/mĀ³
[11:10:24][D][sensor:121]: 'SM300D2 PM10 Value': Sending state 6.00000 Āµg/mĀ³ with 0 decimals of accuracy
[11:10:24][D][sm300d2:078]: Received Temperature: 24.00 Ā°C
[11:10:24][D][sensor:121]: 'SM300D2 Temperature Value': Sending state 24.00000 Ā°C with 1 decimals of accuracy
[11:10:24][D][sm300d2:082]: Received Humidity: 41.80 percent
[11:10:24][D][sensor:121]: 'SM300D2 Humidity Value': Sending state 41.80000 % with 1 decimals of accuracy
[11:10:31][D][sensor:121]: 'ESP Uptime': Sending state 172.37300 s with 0 decimals of accuracy
[11:10:34][W][sm300d2:026]: Invalid preamble for SM300D2 response!
[11:10:44][W][sm300d2:045]: Successfully read SM300D2 data
[11:10:44][D][sm300d2:058]: Received COā‚‚: 401 ppm
[11:10:44][D][sensor:121]: 'SM300D2 CO2 Value': Sending state 401.00000 ppm with 0 decimals of accuracy
[11:10:44][D][sm300d2:062]: Received Formaldehyde: 0 Āµg/mĀ³
[11:10:44][D][sensor:121]: 'SM300D2 Formaldehyde Value': Sending state 0.00000 Āµg/mĀ³ with 0 decimals of accuracy
[11:10:44][D][sm300d2:066]: Received TVOC: 1 Āµg/mĀ³
[11:10:44][D][sensor:121]: 'SM300D2 TVOC Value': Sending state 1.00000 Āµg/mĀ³ with 0 decimals of accuracy
[11:10:44][D][sm300d2:070]: Received PM2.5: 6 Āµg/mĀ³
[11:10:44][D][sensor:121]: 'SM300D2 PM2.5 Value': Sending state 6.00000 Āµg/mĀ³ with 0 decimals of accuracy
[11:10:44][D][sm300d2:074]: Received PM10: 11 Āµg/mĀ³
[11:10:44][D][sensor:121]: 'SM300D2 PM10 Value': Sending state 11.00000 Āµg/mĀ³ with 0 decimals of accuracy
[11:10:44][D][sm300d2:078]: Received Temperature: 24.00 Ā°C
[11:10:44][D][sensor:121]: 'SM300D2 Temperature Value': Sending state 24.00000 Ā°C with 1 decimals of accuracy
[11:10:44][D][sm300d2:082]: Received Humidity: 41.80 percent
[11:10:44][D][sensor:121]: 'SM300D2 Humidity Value': Sending state 41.80000 % with 1 decimals of accuracy

That pesky ā€œInvalid preamble for SM300D2 response!ā€ is still an issue - even with leaving my ESPHome window open watching the logs. At least this example seemed to recover on the next 10-second polling. It usually never works again until I do an ESP32 remote reset. Iā€™m back to setting a timer to reset every 5 minutes just to keep the data flowing.

Well - itā€™s been working ever since my last postā€¦

I think perhaps removing the rx_buffer_size from my ESP32 config was the only difference I made. Iā€™ll try to break it again to confirm when I have a few minutesā€¦

esphome:
  name: hass-esp01
  platform: ESP32
  board: esp32dev

# Enable logging
logger:
  baud_rate: 0

switch:
  - platform: restart
    id: esp01_restart
    name: "ESP01 Restart"

# Enable Home Assistant API
api:

ota:
  password: "<<password>>"

wifi:
  ssid: "tyle"
  password: "<<password>>"

uart:
  rx_pin: GPIO16
  baud_rate: 9600

sensor:
  - platform: sm300d2
    co2:
      name: "SM300D2 CO2 Value"
    formaldehyde:
      name: "SM300D2 Formaldehyde Value"
    tvoc:
      name: "SM300D2 TVOC Value"
    pm_2_5:
      name: "SM300D2 PM2.5 Value"
    pm_10_0:
      name: "SM300D2 PM10 Value"
    temperature:
      name: "SM300D2 Temperature Value"
    humidity:
      name: "SM300D2 Humidity Value"
    update_interval: 10s
    
  - platform: wifi_signal
    name: "WiFi Signal Sensor"
    update_interval: 60s
    
  - platform: uptime
    name: "ESP Uptime"
    update_interval: 30s # defaults to 60s

As soon as ESPHome 2021.9.0 came out I updated and things seemedā€¦ better. Though still somewhat unstable (with the entire esp rebooting), especially if I was playing with ble as well.

To that end, I ended up swapping out the ESP-32 for an 8266 (so bluetooth could be on a dedicated device) and then spent a couple of weeks failing to get more than a single read from the SDM300d2 and esp-8266 combination.

This patch got submitted to ESPHome nearly a fortnight ago which claims to fix the issues with this sensor. I installed ESPHome-Dev which contained this fix and rebuilt the firmware for the esp-8266 and things have been fantastic since. Not a single failed read: https://github.com/esphome/esphome/commit/c6109024aaff83c9a44ccd579f5994fafe4a3078

My only slight concern is how accurate the data is: As part of my testing Iā€™ve ended up polling the UART every 15 seconds, and each time I get a successful read with slightly different data. - If the device is only updating once a minute then what the heck am I seeing? :wink:

Canā€™t wait for the above commit to make it into mainline. Iā€™d say the sensor is mostly unusable without it.

1 Like

I was so excited about seeing the results with my first SDM300D2 that I ordered to more. They just came and I set them both up. One worked, the other did not. Strangely - to your comment about accuracy - I have both of the devices that are working and sending data sitting side by sideā€¦ And none of the measurements are the same. Even temperature and humidity arenā€™t the same. :slight_smile:

I also noticed that my PM2.5 and PM10 almost always seem to be a 2x factor of each other. :slight_smile:

Will see if I can get my third device working but with no blue flashing light yet the fan is spinning - Iā€™m thinking itā€™s defectiveā€¦

Just a quick note to mention that ESPHome v2021.9.2 has dropped but it does not include the fix for the SM300D2.

Iā€™m stull running mine on the dev build and it still seems stable - though, I still donā€™t believe any of the details coming from it.

@Lux4rd0 - Iā€™m curious if the graph shapes match on your two sensors, even if the values donā€™t? EG does CO2 go up and down vaguely at the same time?

Hrmā€¦ Yeahā€¦ I just ran a soldering iron next to this thing and the PM2.5/PM10 didnā€™t budgeā€¦ hrmā€¦

It also seems to randomly give measurements on restarts. Sometimes I donā€™t read anything for PM2.5/PM10. Maybe thereā€™s just a high probability of a defect? Temp and humidity seem to work every time

My two sensors just flaked out at the same time by not showing Formaldehyde for several hours. Now one is showing date - and the other is still showing 0. But the other sensors seem to be reflecting changes. The kicker is - both of these sensors are sitting side by side to each other. Why the difference? Hmmmā€¦ Couldnā€™t tell you. I also see the data not being consistently being pulled for each of the metrics each polling cycle. Iā€™m guessing that the sensor is tossing in garbage and the checksum is kicking out partial readings. The recent updates to this ESPHome version are tossing the bad ones out and keeping the good ones? This is why itā€™s actually ā€œworkingā€ for now instead of those ā€œInvalid preambleā€ errors.

Also - since the TVOC and CO2 data is the same just scaled differently, I just stopped looking at CO2.

Iā€™ll keep checking on this and seeing how frequently the data gets provided.

Since a few days I have an sm300d2 connected to the same ESP as my SCD30. Both give totally different readings for CO2ā€¦ I think the SCD30 is more reliable and since it is inside of my house the ~400 of the sm300d2 is not correctly. I also see other people above having readings around ~400ā€¦
Add to that some very flaky spikesā€¦ Is that right?

1 Like

I picked up one of these, I have it setup to recieve data on a ESP8266 and Iā€™m getting results but the fan doesnā€™t spin. Also the readings seem to ever increase. If I disconnect the power and reapply it, it starts back at zero values and starts counting up again.

Any suggestions?

in the meanwhile my SDM300D2 works without outages.
But it should be rebooted on a weekly base, because some date a rising without any reason.

1 Like

Your CO2, that is almost always around 400-500 thatā€™s not normal unless your sensor is outside. Inside should have spike to 1000-1500ā€¦

I think the sm300d2 is not reliable enough thusā€¦ (I have it also).

1 Like