Node-Red Flow Samples/Sharing

Or you could just use this simple flow:

3 Likes

Yeah, there are many ways to skin a cat as they say

I was sharing what I put together

No disrespect intended...

I tried pasting this flow but got this:

I'm trying to convert this to Node-red. I am assuming I should do something similar to your example - get switch status on Heater, Pool speed 2, and temp (I'm assuming they all need to have send-events checked as I'd want a change in either to trigger going further). Then use a function to do the "and"?

This might work and cover "true" statement (only send-events is turned on for Pool temp), but it would not capture if switch state changed on either - it would have to wait for a pool temp change before they'd trigger. Also don't know how I'd cover the "false" statement. Any tips (if this shouldn't be in this thread and should be in a "node-red flow help" thread, let me know/or feel free to move).

1 Like

I fixed the sample (thanks for pointing it out). It should import now.

I'm not great at the function stuff, so if you cannot figure it out using the sample I would start a separate thread for help.

1 Like

Does anyone have a flow that is for motion lighting but can be disabled/overridden when the lights are turned out outside of motion e.g. with google? I can't seem to figure it out.

Could you create a virtual switch 'override motion', tell google to turn it on, and have your flow set to not use motion if 'override motion' switch is on. I guess it would be similar to your button flow just with a virtual switch exposed to googs?

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