I have a heartbeat function outside of my main while loop (the main body of my code) that relies on a timer. The problem is that the “every /10 seconds” is not configurable w/ a variable. and I enter the timer loop at random times, thus rebooting the ESP when not needed.
Basically I want to kick off a variable time timer (based on a calc) time_x every time a certain GPIO on_state or on_value changes to off. If I don’t see an update of the heartbeat flag by lapse of time_x, then SomeTing has gone Wong - reboot the ESP.
This is proving to be harder than it sounds…
time:
- platform: homeassistant
id: time_homeassistant
- platform: sntp
on_time:
# Every 10 seconds
- seconds: /10
then:
- logger.log: "time.on_time triggered after 10s"
- if:
condition:
lambda: return !id(heartbeat_flag);
then:
- logger.log: "**********Heartbeat missed, flag not set REBOOTING ESP *********************"
- button.press: restart_esp
else:
- switch.turn_off: heartbeat
- globals.set:
id: heartbeat_flag
value: 'false'
- logger.log: "**HEARTBEAT switch & flag set to FALSE"
button:
- platform: restart #allows remote reset of tywe1s chip from home assistant or internally
id: restart_esp
name: "ESPH dev Stove Restart"
The section of code that currently updates the heartbeat flag:
#new P5 Auger routine
- if:
condition:
- lambda: return id(p5flag); #All conditions met and P5flag == true.
then:
- switch.turn_on: auger_output_to_optoisolator
- delay: !lambda "return id(auger_on_timez).state * 1000;"
- switch.turn_off: auger_output_to_optoisolator
- switch.turn_on: heartbeat
- globals.set:
id: heartbeat_flag
value: 'true'
- delay: !lambda "return id(auger_off_timez).state * 1000;"