Equivalent to HA's automation trigger condition "for"

I’m looking to check if one of my PIR sensor is “off” for the last 5 minutes. In HA’s Automation, I would have something like this:

trigger:
  - entity_id: binary_sensor.shenzhen_neo_electronics_co_ltd_battery_powered_pir_sensor_v2_sensor
    for: 0:05:00
    platform: state
    to: 'off'

Is there any node that would be equivalent to HA’s Automation condition “for” ?

My first thinking was to start with an “events:state” node on my PIR sensor going to off, than follow by a “delay” node for 5 minute, then check with “trigger:state” if the PIR status was still “off”. But this is not the same at all, as during the 5 min delay the PIR could have gone on/off multiple times. What I need is to check that the status has been “off” during 5 minutes, continuously.

Sometimes you have to think a little differently with Node-RED.

There may be a node that does that function, but this is how I do it. When the sensor reports the state “off” it starts the timer. When the sensor reports “on” it outputs the “STOP” payload which will cancel the 5-minute timer.

image

[{"id":"b64a2728.70fe98","type":"server-state-changed","z":"5f5b2ee4.811bd","name":"PIR SENSOR","server":"26956a45.92d866","version":1,"entityidfilter":"sensor.pir","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"off","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"x":590,"y":400,"wires":[["152440a4.f3d22f"],["4fb7f15c.ffd0a"]]},{"id":"152440a4.f3d22f","type":"stoptimer","z":"5f5b2ee4.811bd","duration":"5","units":"Minute","payloadtype":"num","payloadval":"0","name":"5min","x":890,"y":400,"wires":[[],[]]},{"id":"4fb7f15c.ffd0a","type":"change","z":"5f5b2ee4.811bd","name":"STOP","rules":[{"t":"set","p":"payload","pt":"msg","to":"STOP","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":750,"y":440,"wires":[["152440a4.f3d22f"]]},{"id":"26956a45.92d866","type":"server","z":"","name":"Hass.io","legacy":false,"hassio":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true}]

If you want it to notify you every five minutes until it receive the stop payload, add a loop.

image

1 Like

Interesting approach, indeed things need to be seen differently with node red !
I implemented this, works fine. Thanks !

1 Like

No problem!