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.
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!
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.
@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.
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:
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