I’m stretching my head to find out the issue with my trigger-based template binary sensor, which listens to log events, I’d like the sensor to be “on” when certain log event happens, and “off” when nothing triggers in the past 5 minutes.
So the turn on of the sensor works great, but once it’s on, it never turns off even though the trigger never fires and timeout 5 minutes passed. Maybe I misunderstood how delay_off is supposed to work in HA? Any hint or suggestion what to do?
Your input is appreciated!
If you review how the delay_off option works you’ll see your configuration (notably state) presents no opportunity for the option’s requirements to be met.
Thank you! The documentation for delay_off and auto_off:
delay_off time (optional)
The amount of time the template state must be not met before this sensor will switch to off. This can also be a template.
auto_off time (optional) Requires a trigger. After how much time the entity should turn off after it rendered ‘on’.
I guess it’s because I hard code the state to “on” which means the state is always met since it’s triggered. Would like to understand the how auto_off works: say auto_off is 5 minutes, the sensor is triggered ON at T. At T+3min it gets triggered ON again, does auto_off turn off it at T+5min or T+8min (T+3min+5min)?
no, that’s not how it works. The state template is just executed when a trigger occurs.
delay_off requires the state template to resolve off. When the trigger occurs and the state template resolves off, delay_off will delay that off for 5 minutes.
auto_off is what you want because that does not requires an off to resolve from the state, it does require the state to resolve on though. The entity will turn off 5 minutes after it turns on.
Thank you both, it works flawlessly, now I need to figure out how to restart HA VM in case of the error.
Usually this error comes after restart and my rs485 usb adaptor runs into some wired race condition,m and stop providing data, the only way to solve is to reset the VM (or reboot HAOS). As I understand there is no way to do it as an automation.