Re: Converting an automation to Code Red problem

I’m trying to get my feel wet in Node-RED by converting my automations to Node-Red. Here is a simple automation that triggers if the door has been left open for 10 minutes. I don’t know how to duplicate the 10 minute wait part in Node-Red

- id: '1537476839142'
  alias: Front Door Left Open
  trigger:
  - entity_id: binary_sensor.0x00158d00023eb10f
    for:
      minutes: 10
    platform: state
    to: 'on'
  condition: []
  action:
  - data:
      entity_id: media_player.echo_plus
      message: Front Door Left Open
    service: media_player.alexa_tts

Here is a Node-RED screenshot of what little I have so far:

Obviously I cannot just add a 10 minute delay because I only want the action to occur if the door has remained open for the full 10 minutes. What to do?

Ok a Stop Timer seems to have been what I was looking for. This appears to be working at first glance:

I think you should be looking at a trigger-state instead. With your current flow, if the door is opened and closed and re-opened, you are likely to get the Alexa message. A trigger-state can be configured to only pass on the message if the door stays open for 10 minutes - closing the door and re-opening will reset the timer.

Yes, trigger node is the way to do it

1 Like

Thanks! Can you please explain further? The reason I thought the stop-timer was the way to go is because of the following description of the stop-timer:

Sends the msg through the first output after the set timer duration. If a new msg is received before the timer has ended, it will replace the existing msg and the timer will be restarted, unless the new msg has a payload of stop or STOP

On the “Front Door Open” node above, I don’t use the “halt if” field. So when the door is opened or closed, on or off gets sent to the stop timer. The stop timer resets the timer to 10 mins each time the door is opened or closed. Once the 10 min timer expires, it sends the on or off to the “Door Open?” node. Then if the “Door Open?” node receives an “on” , it activate Alexa with the msg. If instead it receives an off, it does nothing.

Is my interpretation in the above paragraph incorrect? (I’m very new to node red) I also want to understand trigger-state. After googling, I don’t see how to only trigger after a certain amount of minutes of the binary_sensor being on. Can you get me started in the right direction with trigger-state?

Thanks. Please see my questions above.

Start with a Home-Assistant event:state node and set the entity_id to the binary sensor.

Add a Trigger node to the output of the HA state node and set to the following:

Send : “nothing”
then : "wait for:
“10 mins”
tick extend delay if new message arrives
then send “the latest message object”
Handling : "all messages:

leave the other boxes blank or leave as-is.

This will have the effect of only passing a message through if it hasn’t changes in 10mins. If it does change, the timer resets and the 10min countdown restarts (this is what the tick box extend delay if new message arrives does).

The final step is to filter to check if it’s gone from off to on or vice versa - you can do this with either a switch node or function node. Let me know if you get stuck here.

1 Like

Ok I think I see why I’m confused. @michaelblight said the trigger-state node which is a different than the trigger node. Therefore I will experiment with that. Thanks.

Above in my last reply to @michaelblight , I describe my understanding of the stop-timer node and how it seems to be working for me. Can you see any circumstance where it wouldn’t work as I want it to? It seems to be working just fine, but that doesn’t mean some circumstance might not cause it to fail.

tl;dr The stop-timer function is working for me. Am I crazy?

I got it working with the trigger node. Took out the stop-timer nodes on all 3 external doors sequences and replaced with trigger node. Thanks for the help.

I can’t access my node red right now, but I thought there was a node that triggered based on how long something was “on”. I used it for a safety timeout for my sprinklers and it acted like it was working. I’ll try to remember to look tonight.

I use the node “poll state”. It has the information for “time since changed”. I use it as a safety backup for my sprinklers. If they have been on continuously for more than three hours then they aren’t switching zones and something happened.
Screenshot%20from%202018-10-26%2021-29-46