I’m trying to wrap my mind around the Binary Sensor Templates. I looked through the documentation and searched a lot, but can’t find the correct variables. Basically, I want to create a Binary Sensor switches on as soon as a different binary sensor has been off for X amount of time.
Normally I just use the built in automation for this, since you can trigger based on state time. However I need this in Node-RED. I haven’t found an easy way in Node-RED to do this. So I figured why not create a Binary Sensor for this and use that as the trigger in Node-RED.
Can you help me with this when you have the time? I think I need to use the stoptimer. It states it can stop the timer with a payload STOP. But I don’t know how to set that up.
Doing this though NR is going to be clunky and hacky. There is no need to be constantly running a timer. Using binary_sensor and the state engine is the way to go. Try this:
- platform: template
sensors:
your_sensor:
friendly_name: Your Sensor
value_template: "{{ is_state('binary_sensor.trigger_sensor', 'off') and (states.trigger_sensor.last_changed < (now() - timedelta(minutes=10))) }}"
Replace trigger_sensor with your trigger sensor. The time delta should be how long ago the state changed for the sensor to now be true.
The format for timedelta is:
seconds = 30
minutes = 5
hours = 10
etc.
I suppose that works if you only need to trigger a flow once per time its turned off, but there is no way to check whether the delay was exceeded in subsequent runs of any flow/automation. I guess it depends on OP’s needs.
Thanks all! I see a great solution with both methods (binary sensor template and Node-RED). Binary sensor template is more robust, while the Node-RED method is flexible. I’ll test and see which one works best in this case.
I saw the documentation with delay, but was lost with defining the binary template state itself as code. The part about float got me confused I think this should work then judging by both template methods: