I have GPIO5 in ESPHome that I want to use as a heatbeat signal (auger_output_to_optoisolator) for another binary sensor (dev_auger_heartbeat). If I dont see the GPIO5 signal change in 10 seconds, I want the binary sensor to turn on indicating I’ve lost hearbeat. I thought I could do this inside the binary sensor w/ delayed_on_off and a lambda.
Nothing happens even though I have no change in GPIO5 after 10 or more seconds.
switch:
- platform: gpio
pin: GPIO5
name: "esph House AugerOut to optoisolator +LED"
id: auger_output_to_optoisolator
binary_sensor:
- platform: homeassistant
id: dev_auger_heartbeat
name: "dev_auger_heartbeat"
#internal: true
entity_id: input_boolean.dev_auger_heartbeat
filters:
- delayed_on_off: 10s
- lambda: |-
if (id(auger_output_to_optoisolator)) {
return x;
} else {
return {};
}
am I using this filter incorrectly or assuming it operates in a different way?
zoogara
(Daryl)
December 22, 2022, 10:35pm
2
You are using it the wrong way, filters will only trigger when the value changes, if the value doesn’t change none of your code will execute.
Maybe use time: on_time:
to check if state has changed every 10 seconds? There may be some cleverer way to do it though.
zoogara:
ime: on_time:
Interesting. I’ll look into the time: function. that might work. Folks must have set up hearbeat monitors in ESPHome before??
How come you aren’t just using a ESPHome template binary sensor that points straight at auger_output_to_optoisolator?
I think your approach should work if you do that.
Why bring in a HA sensor into it?
Because I gave up after spending a day+ trying to figure it out…
This is what I’m trying to monitor
...code...
- if:
condition:
- lambda: return id(p5flag); #All conditions met and P5flag == true.
then:
- logger.log: "script.check.p5flag | P5FLAG tests TRUE. Modified P5 running"
- switch.turn_on: auger_output_to_optoisolator
- delay: !lambda "return id(auger_on_timez).state * 1000;"
- logger.log: "script.newP5 active. Auger ON"
- switch.turn_off: auger_output_to_optoisolator
- delay: !lambda "return id(auger_off_timez).state * 1000;"
- logger.log: "script.newP5 active. Auger OFF"
If I stop getting on/off signals from auger_output_to_optoisolator for like 30 seconds I want to reboot the ESP (that’s the easy part)
EDIT: I tried the time: function. It works.
time:
- platform: sntp
on_time:
# Every 10 seconds
- seconds: /20
then:
- logger.log: "time.on_time triggered after 20s"
- if:
condition:
lambda: return !id(heartbeat_flag);
then:
- logger.log: "**********Heartbeat flag not set REBOOTING *********************"
else:
- globals.set:
id: heartbeat_flag
value: 'false'
- logger.log: "heartbeat flag set to FALSE"
- delay: !lambda "return id(auger_off_timez).state * 1000 +5000;" #take into account Auger off time+ 5s
#