Node-Red Flow Samples/Sharing

Cant you use a switch after the light, and only continue if off? Like this, seems simple, so hoping so :slight_smile:
So the below will only turn on, if the light itself is already off.

If by "lights turned out outside of motion" you mean lights turned off, a simply trigger node when the lights are turned off into a change node to change the payload to STOP and then into your motion timer will stop the timer when the lights are turned off.

If by "lights turned out" was supposed to be lights turned on then I'd use a virtual switch as suggested by TechMedX. There's a few other ways I can think of doing this but that would be the simplest.

Sorry @MRobi there was a typo. It was meant to be lights turned on outside of motion. Sometimes we want the light on and motion disabled, I just can't figure out how to get it back off without manually doing it

any one have a flow that captures a device status and then restores it?

I want to use a wled light strip to indicate when doors are open and when motion is detected but after a period of time return to its previous state

Created a thread. Still not sure it’s right. Did I do this right? RM to Nodered

2 Likes

Here is a simple subflow "wrapper" around the vari-timer delay node that allows for intermediate steps.. either seconds or minutes. You set the intervals via a delimited string in the subflow instance properties..

You could also do a similar thing via switch node and some additional logic but this is nice and encapsulated if you need it..

Delay with Intervals Subflow Example

[{"id":"85e4d659.1f2e28","type":"subflow","name":"Delay with Interval","info":"","category":"","in":[{"x":40,"y":80,"wires":[{"id":"ebdad02d.af581"}]}],"out":[{"x":1260,"y":60,"wires":[{"id":"907cab7d.d1bf58","port":0}]},{"x":1440,"y":180,"wires":[{"id":"709a5ed7.8312","port":0}]}],"env":[{"name":"DELAY","type":"num","value":"30"},{"name":"INTERVALS","type":"str","value":"10/20/30"},{"name":"USE_MINS","type":"bool","value":"true"}],"color":"#DDAA99","outputLabels":["Timer Completed","Interval Output"],"status":{"x":1440,"y":280,"wires":[{"id":"3bb0ab2a.dc0894","port":0},{"id":"709a5ed7.8312","port":1}]}},{"id":"907cab7d.d1bf58","type":"stoptimer-varidelay","z":"85e4d659.1f2e28","duration":"DELAY","durationType":"env","units":"Second","payloadtype":"num","payloadval":"0","name":"","reporting":"every_second","persist":false,"x":840,"y":60,"wires":[[],[],["efedccd6.62f1"]]},{"id":"ff01a84a.1f68f8","type":"change","z":"85e4d659.1f2e28","name":"set flow.intervals to array, set max = delay in secs.","rules":[{"t":"set","p":"intervals","pt":"flow","to":"$map(\t    $split($env('INTERVALS'),\"/\")\t    , function($v) {$number($v) * ( $env(\"USE_MINS\") ? 60: 1)\t})\t","tot":"jsonata"},{"t":"set","p":"max","pt":"flow","to":"$env('DELAY') * ( $env(\"USE_MINS\") ? 60: 1)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":290,"y":140,"wires":[["4ce3c5a6.88859c"]]},{"id":"7841b7c2.be35a8","type":"change","z":"85e4d659.1f2e28","name":"set flow.currSecs = max delay secs - timer secs","rules":[{"t":"set","p":"currSecs","pt":"flow","to":"$flowContext(\"max\") -\t(\t$number($split(payload,\":\")[0]) * 3600 +\t$number($split(payload,\":\")[1]) * 60 +\t$number($split(payload,\":\")[2])\t)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":940,"y":220,"wires":[["709a5ed7.8312"]]},{"id":"ebdad02d.af581","type":"switch","z":"85e4d659.1f2e28","name":"payload = stop","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"stop","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":200,"y":80,"wires":[["907cab7d.d1bf58"],["ff01a84a.1f68f8"]]},{"id":"efedccd6.62f1","type":"switch","z":"85e4d659.1f2e28","name":"payload == stopped","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"stopped","vt":"str"},{"t":"neq","v":"stopped","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":850,"y":160,"wires":[["3bb0ab2a.dc0894"],["7841b7c2.be35a8"]]},{"id":"3bb0ab2a.dc0894","type":"change","z":"85e4d659.1f2e28","name":"format payload","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\t    \"fill\":\"red\",\t    \"shape\":\"ring\",\t    \"text\": payload\t}","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1100,"y":160,"wires":[[]]},{"id":"709a5ed7.8312","type":"function","z":"85e4d659.1f2e28","name":"output to current interval  when it occurs and currSecs in H:mm:ss format ","func":"var useMins = env.get(\"USE_MINS\");\nvar maxDelay = env.get(\"DELAY\") * (useMins ? 60 : 1);\nvar currSecs = flow.get(\"currSecs\");\nvar intervals = flow.get(\"intervals\");\nvar ret1;\nvar ret2 = msg;\n\nif (typeof intervals === \"number\") {\n    intervals = [intervals];\n}\n\n\nvar nextInterval = intervals.find(element => element > currSecs);\nif (currInterval = intervals.find(element => element == currSecs)) {\n        ret1 = { payload: currSecs / (useMins ? 60 : 1) };\n}\n\n//if (intervals.includes(currSecs)) {\n//        ret1 = { payload: currSecs / 60 };\n//}\n\nvar nextIntStr; \nif (maxDelay === currSecs) {\n    nextIntStr = \" / complete.\";\n} else {\n    nextIntStr = ( nextInterval ? \" / Next: \" + new Date(nextInterval * 1000).toISOString().substr(11, 8) :\" / No more intervals\")    \n}\n\nvar payLoad = new Date(currSecs * 1000).toISOString().substr(11, 8) + nextIntStr ;\n\nret2.payload = {fill:\"green\",shape:\"dot\",text:payLoad};\n\nreturn [ret1,ret2];\n\n","outputs":2,"noerr":0,"initialize":"","finalize":"","x":1020,"y":360,"wires":[[],[]]},{"id":"4ce3c5a6.88859c","type":"change","z":"85e4d659.1f2e28","name":"","rules":[{"t":"set","p":"delay","pt":"msg","to":"$env(\"USE_MINS\") ? $env(\"DELAY\") * 60 :  $env(\"DELAY\")","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":200,"wires":[["907cab7d.d1bf58"]]},{"id":"61a35e4.d8615a","type":"subflow:85e4d659.1f2e28","z":"af91369d.586338","name":"","env":[{"name":"INTERVALS","value":"1/5/8/13/22/25","type":"str"},{"name":"USE_MINS","value":"false","type":"bool"},{"name":"DELAY_MINS","value":"2","type":"num"}],"x":1130,"y":240,"wires":[["22944a1c.c26ce6"],["99348740.0576e8"]]},{"id":"99348740.0576e8","type":"debug","z":"af91369d.586338","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1370,"y":260,"wires":[]},{"id":"f42a81b.9bf2e8","type":"inject","z":"af91369d.586338","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":880,"y":220,"wires":[["61a35e4.d8615a"]]},{"id":"22944a1c.c26ce6","type":"debug","z":"af91369d.586338","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1370,"y":220,"wires":[]},{"id":"2fe82ee9.4f6162","type":"inject","z":"af91369d.586338","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"stop","payloadType":"str","x":870,"y":260,"wires":[["61a35e4.d8615a"]]}]
2 Likes

Curious if you got this working; I asked the same earlier in this thread and got a couple responses on how it should be done. I tried to get it to work and didn't have much luck, but haven't had the time really to revisit.

Well kind of..
The work around I used was I know what the state of the device was supposed to be based on what the Mode was
Work time vrs Bed time in this case.

Hadn't thought about doing it that way, but it would work. Thanks!

Just finally getting to look at this. There are a couple of things on this:

I'm assuming the primary trigger is motion?
If so wouldn't this rule turn lights on and never turn them all, as it checks to see if the light is on and if it is then do nothing, so when motion triggers it on it'll be on and therefore not turn off?

I am 2 weeks late in seeing this and really getting what its implications are, but I wanted to say thanks. This was really insightful.

Have you tried to see if you can tell who invoked Alexa? I have looked through the info returned by the node and couldn't find it. Using one of the other nodes, I was able to see the family members who it sees as different, but none of those identifiers seem to be included in the data for an individual invocation.

I have not looked into seeing if those nodes can determine who was last speaking. One of my big pet peeves is that Alexa controls all of our home automation great when in my acct but not so much when in wife's account. My wife's account has all of the good music accounts so that's usually where Alexa "sits". I can't find a good way to have Alexa perform automations reliably when in wife's account. That would be helpful.

1 Like

Just a thought. Can you create 2 separate remote2 links into amazon, 1 for your account and 1 for your wife’s? If it works, it would require twice as many inputs to get the feedback.

Of course while I am writing, I am thinking and I am guessing for the instance logged in as her it wouldn’t see the echo’s.

1 Like

Credit to @JasonJoel - I felt it's worth linking here as well from the main NR thread. These are a great examples of simple motion lighting timer sequences.

4 Likes

Sorry mate, completely overlooked your reply.

In that example it would, but only because deCONZ has an "end" action, whereas the HE NR pallet, you can continue after the lights are on, to say put it back into the timer loop, if you see what I mean?

where does one find the GATE node

3 Likes

Any thoughts on the best way to accomplish this? I want the light to stay on in the bonus room if motion is detected at any time, and stay on for 15 minutes. If it's a weekday between 7:00-17:00, I want the light to come on if motion and stay on until 17:00.

I think this will work, but I believe if I leave the room (no motion) before 17:00, the light would stay on. What am I doing wrong or anyone have a better way to accomplish this. TU.

If I'm interpreting this correctly, you basically want active motion to switch ON the light, no matter what time or day. But you want the inactive event to switch OFF the light only outside of the given windows of time. Correct?

I think you basically just need to move the time-related stuff to after the delay node. So, if you leave the room at 10 minutes before 17:00, the countdown will still run, and by the time the 15 minute countdown is done, the light will switch off (at 17:05). If you really want to force the light off at 17:00 even if there's still some time left on the countdown, you could have a separate sequence that switches the light off at 17:00 if no motion is currently active.

1 Like

I believe you're correct. This is what I have now.

1 Like