Ignoring sensor values during warm up after periodic wake up

ESPHome is incredibly well thought out and written. Thank you for making this and sharing!

I’m using the PMS7003 sensor by reading it for 1 minute every 15 minutes, and making it sleep for 14mins. Doing this to minimize power as well as preserve the sensor life:

I’m using code like this to implement the sleep-wake-measure-sleep:

The problem is, the sensor needs to warm up for 30sec after it is up. Values for that time period should be ignored. So the cycle needs to look like:

00:00 sleep PMS7003 via set pin
14:00 wake up via set pin; ignore values for the next 30sec*
14:30 start taking measurements, once every two seconds
15:00 sleep PMS7003 via set pin

How can I implement the 30-second warm up period in ESPHome? Thank you.

1 Like

Stable data should be got at least 30 seconds after the sensor wakeup from the sleep mode because of the fan’s performance.

I tried this idea: to create an interval to handle turning on the sensor, which also sets a (software) switch indicating warm_up is complete. I then attempted to filter the sensor itself on this warm_up switch. That filter unfortunately doesn’t allow anything through at all:

# turn on for 1min every 15min, and flip a switch after a 30sec warm up period
interval:
  - interval: 15min
    then:
      - switch.turn_on: pms_set
      - delay: 30s
      - switch.turn_on: pms_ready_to_read
      - delay: 45s
      - switch.turn_off: pms_ready_to_read
      - switch.turn_off: pms_set

switch:
  - platform: template
    name: "PMSX003 Ready to Read Post Warm-Up"
    id: pms_ready_to_read

sensor:
  - platform: uptime
    name: ${device_full_name} Uptime
    update_interval: 1s
    id: uptime_sensor
    filters:
      - lambda: if (id(pms_ready_to_read).state) { return(x); } else { return {}; };
    on_value:
      then:
        - lambda: |-
            ESP_LOGD("main", "Uptime sensor value is: %d", int(x));

Would this idea work at all? Can anyone help me see if what I’m doing wrong here? Thank you!

Bumping you see if anyone has ideas. Thank you.

One more bump

What if you made the sensor internal and then used and interval to keep track of time since wake up to then force an update to a template sensor which is then published out to HA or wherever? Just spitballing idea, not sure if it would work for you but perhaps worth investigating if you haven’t already.

-J

@iotisunderrated Thank you very much for sharing your config and the hint. I just implemented today the new PMS7003 sensor in EspHome and I took a more simple approach by switching on the measurement for a minute every 14 minutes with the time platform.

time:
  - platform: homeassistant
    on_time:
      - seconds: 0
        minutes: /14
        then:
          - switch.turn_on: pms_set
          - delay: 60s
          - switch.turn_off: pms_set 

I don’t really care about the accuracy of the readings since HA just shows the last measured readings in my graph and that’s what it looks like in my card:

      - type: 'custom:mini-graph-card'
        entities:
          - sensor.feinstaub_2_5um_konzentration
        name: 'Feinstaub PM2,5'
        hours_to_show: 36
        points_per_hour: 1
        show:
          labels: true
        color_thresholds:
          - value: 15
            color: '#21ED28'
          - value: 25
            color: '#d36600'
          - value: 80
            color: '#d30003'

Nevertheless, if you have any approach to read only the “accurate” / warmed up values, I would be interested. Please share if you already solved it.

Bump! Did someone ever figure out a solution for this problem? I’m trying to do the exact same thing.

Just made my solution to ignore PMS7003 values during warm up. Based on iotisunderrated idea.

sensor:
  - platform: pmsx003
    type: PMSX003
    pm_1_0:
      name: "Particulate Matter <1.0µm Concentration"
      filters:
        - lambda: if (id(pms_ready_to_read).state) { return(x); } else { return {}; };
    pm_2_5:
      name: "Particulate Matter <2.5µm Concentration"
      filters:
        - lambda: if (id(pms_ready_to_read).state) { return(x); } else { return {}; };
    pm_10_0:
      name: "Particulate Matter <10.0µm Concentration"
      filters:
        - lambda: if (id(pms_ready_to_read).state) { return(x); } else { return {}; };

interval:
  - interval: 5min
    then:
      - switch.turn_on: pms_set
      - delay: 30s
      - switch.turn_on: pms_ready_to_read
      - delay: 5s
      - switch.turn_off: pms_ready_to_read
      - switch.turn_off: pms_set

switch:
  - platform: template
    name: "PMSX003 Ready to Read Post Warm-Up"
    id: pms_ready_to_read
    optimistic: true
    
  - platform: gpio
    pin: 
      number: GPIO10
    id: pms_set

Works fine for now. Delay time 5s can be reduced to 1-2 seconds. Full my ESPHome config (using 3 sensors: BME280, MH-Z19B and PMS7003) here: https://pastebin.com/saC98GrX

1 Like