Moving Automations to NodeRed help

Decided to make the switch to NodeRed for my automations. Been watching some tutorial videos and reading threads and blogs. Starting to make sense. I’ve made a few flows that work great, but I’m having trouble wrapping my head around doing things after a certain amount of time.

  1. I have a presence detection flow. Sets Home or Away based on state of devices/input_booleans etc. No issues with that part. But I want to have an Extended Away setting that triggers if the house occupancy tracker is set as Away for x amount of time. I made this pretty easy in YAML. House Away for 24 hours then set Extended Away. I tried to use both trigger and delay nodes that are initiated when the house goes into Away mode, but haven’t been able to stop the message when the house goes into Home mode before the timer is up. I see that delay has a “reset” option, and I tried sending a payload of “reset” from a change node off of a service node setting “Home”. But maybe I wasn’t using it right.

  2. I have an automation that watches my front door open/closed sensor. When it goes closed it sets an input_select to “Maybe Away” for 20 mins, after 20 mins it changes to “Away.” But if at anytime it is in “Maybe Away” or “Away” and motion is detected in the house it changes that input_select to “Home”. Again, I can make it go through all those steps, but don’t know how to stop it from going “Away” once triggered.

  1. You should not put a condition on the trigger, all values should flow to the delay node with the reset option enabled. Then you should use a switch node after the delay node to make sure that the value that has not changed since 24 hours is indeed ‘away’.

  2. I use the traffic light node for these kind of situations. Put the light to ‘green’ when the door closes and ‘red’ when motion is detected in the house. Put this traffic light after the delay node and you should be good.

I see that delay has a “reset” option, and I tried sending a payload of “reset” from a change node off of a service node setting “Home”. But maybe I wasn’t using it right.

You weren’t using it right. I only know this because I spent more time and rum trying to figure this out that I really probably should have. But I eventually figured it out.

You don’t send "reset as a msg.payload field. What you actually need is to ADD a msg.reset field to the message being sent.

I’m sure I’m doing it an overly complicated way and there is probably a better way; but this is how I accomplished it for my particular use:

I have a “manual control” switch that I use to disable some of my lighting automations, because you try and explain to a 2 year old why the Christmas lights won’t turn on during the day. The problem was that whenever a Mother-In-Law would use it, it would stay on manual control until I realized that the schedule wasn’t working.

At this point I decided I would put the “manual control” on a 2-hour timer. After 2 hours, revert to auto. Simple enough.

Except after 2 hours, it would turn off “manual control” like I told it to. Problem being, it didn’t matter if I had toggled the “manual control” multiple times in that 2-hr block. I needed a way to reset the timer if I turned off “manual control”, well, manually.

To explain how I accomplished it in words, it goes like this:

Poll state: manual control every 7 seconds (random, arbitrary number. Use what works for you)

Pass through ‘rbe’ node to only report when the state changes.

Next up is a ‘switch’ node:
If “manual control” state is ‘on’ I pass on to a 120m ‘delay’ node which then turns off manual control after the timer expires.

If “manual"control” state is ‘off’ I then pass on to a ‘change’ node.

In the change node I have 2 rules:
Set msg.payload to ’ ’ (Null, nothing, nada, zilch, blank)
Set msg.reset to 1

From there it passes the new changed message to the same delay mode, at which point the timer is expired.

If my wording is hard to follow, I also pasted that flow below, so if you wanted to you could import it into your Node-Red to actually look at it and change it to fit your system. It may generate some errors because your HASS instance is not the same as mine, but you may be able to figure out what you need from there.

[{"id":"2d988fb5.c27fa","type":"poll-state","z":"e1493802.d833a8","name":"","server":"eb6b4bea.ddd5a8","updateinterval":"7","outputinitially":true,"outputonchanged":true,"entity_id":"input_boolean.manual_control_ib","x":180,"y":600,"wires":[["a140386.7a6cbc8"]]},{"id":"63851fc4.aef7c","type":"switch","z":"e1493802.d833a8","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":true,"outputs":2,"x":550,"y":600,"wires":[["6ff8ca80.c4edc4","75ecd1e8.f0b76"],["6a287a48.228a74","6c460922.18bd78"]]},{"id":"a140386.7a6cbc8","type":"rbe","z":"e1493802.d833a8","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":410,"y":600,"wires":[["63851fc4.aef7c"]]},{"id":"75ecd1e8.f0b76","type":"delay","z":"e1493802.d833a8","name":"","pauseType":"delay","timeout":"120","timeoutUnits":"minutes","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":390,"y":480,"wires":[["86c0fcbf.0dfcc"]]},{"id":"6c460922.18bd78","type":"change","z":"e1493802.d833a8","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"1","tot":"num"},{"t":"set","p":"payload","pt":"msg","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":140,"y":480,"wires":[["75ecd1e8.f0b76"]]},{"id":"eb6b4bea.ddd5a8","type":"server","z":"","name":"Home Assistant","legacy":false}]

Is this an actual saying, or were you drinking rum with every failed effort?

Thanks for the responses both. I’ll try some of this out.

More like I poured a little glass of rum and sat down to figure it out. By the time I got it working there was much less rum in the bottle and many more mistakes on the screen. Which is partly why I’m certain there is a better, more efficient way to figure it out.

ok this makes sense. I got it to work. Also needed the tip about msg.reset from oembob.

This I still don’t understand. I think this is the flow you’re describing.

Event State Trigger : Front Door Closed → Delay → Traffic Light → Call Service?
What info do I send to the Traffic Light to both make it ‘green’ when the door closes, but also allow the msg to pass through after the Delay? Do I need to connect a wire both from the State Trigger to the Light, and from the State Trigger to the Delay to the Light?

And then use a separate Event Trigger for the motions? Or something else like the Poll State?

You can specify which value sets a traffic light to stop and which value to go. I was thinking the flow would look like this:

You will want to reset the delay each time the door closes.