For anyone using ESPHome, here is the equivalent code that’s working for me that does not require an additional pin:
interval:
- interval: 150s
# Two-minute interval to extend the life span of the PMS5003 sensor
then:
- switch.turn_on: pms_switch
- delay: 30s
- switch.turn_off: pms_switch
# Source: https://github.com/airgradienthq/arduino/blob/master/AirGradient.cpp#L123
switch:
- platform: template
name: "PMS5003"
id: pms_switch
optimistic: true
turn_on_action:
- uart.write:
id: pms5003_uart
data: [0x42, 0x4D, 0xE4, 0x00, 0x01, 0x01, 0x74]
turn_off_action:
- uart.write:
id: pms5003_uart
data: [0x42, 0x4D, 0xE4, 0x00, 0x00, 0x01, 0x73]
There is a warning in the log when sleep is called:
[W][pmsx003:108]: PMSX003 length 4 doesn't match. Are you using the correct PMSX003 type?
(maybe that 0x00 at pos 4 should be 0x01 like turn on? not sure)
But it doesn’t seem to affect anything, I can hear the fan cycling on and off and watch the readings stop and go in the logs.
Full example, forked from this one is here