Node-Red Flow Samples/Sharing

Quick question; I'm trying to wrap my head around this and the epiphany just hasn't hit yet. Very new and still learning. I need lighting triggered by motion, but I only want the flow to fire if the the target sensor is triggered and the hub is in a specific mode. I've gone through the flows in the post and haven't quite seen anything that is giving me the "ah ha" moment.

As an example, I've got 4 modes I want a flow to fire for (Morning, Day, Evening, Night) so that it is only firing if someone is actually home, from one motion sensor. I can get the thing to work if I just stick a mode node and switch to determine the mode, but I obviously don't want the lights turning on every time the mode changes to one of the allowed modes.


I'm sure the solution is easy, but for some reason I'm having trouble wrapping my head around it. Might be 36 hours of work in 3 days catching up...but it just isn't sticking.

I would suggest making Mode into a flow or global variable and then using it in a switch node. For example, in the sequence below, the closet light is turned on to 100% in home mode, or 10% in sleep mode. It is not turned on in Away mode unless another variable (maid switch) is "on".

3 Likes

You might be overcomplicating with the Boolean Logic node. Just put the mode check inline.

You also want to make sure that the Send events box in the mode node is deslected:

screenshot-10.10.10.228-1880-2020.07.24-22-40-20

Summary

[{"id":"951071b7.73859","type":"hubitat device","z":"bf2927e5.5af798","name":"Basement Motion Stairs","server":"2c08a6b7.b90c4a","deviceId":"546","attribute":"motion","sendEvent":true,"x":180,"y":1340,"wires":[["40335305.2b438c"]]},{"id":"d3ef4aeb.1af928","type":"hubitat mode","z":"bf2927e5.5af798","name":"","server":"2c08a6b7.b90c4a","sendEvent":false,"x":590,"y":1340,"wires":[["d757b69f.c68a68"]]},{"id":"d757b69f.c68a68","type":"switch","z":"bf2927e5.5af798","name":"Away?","property":"payload.value","propertyType":"msg","rules":[{"t":"eq","v":"Away","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":730,"y":1340,"wires":[[],[]]},{"id":"40335305.2b438c","type":"switch","z":"bf2927e5.5af798","name":"Active/Inactive?","property":"payload.value","propertyType":"msg","rules":[{"t":"eq","v":"active","vt":"str"},{"t":"eq","v":"inactive","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":410,"y":1340,"wires":[["d3ef4aeb.1af928"],[]]},{"id":"2c08a6b7.b90c4a","type":"hubitat config","z":"","name":"Hubitat","usetls":false,"host":"10.10.10.24","port":"80","appId":"32","nodeRedServer":"http://10.10.10.228:1880","webhookPath":"/hubitat/webhook","autoRefresh":true,"useWebsocket":false}]

3 Likes

I do it this way as well... mostly just to save myself some time adding the mode node a million times. Also, I store the previous mode in a global as well for use in some situations.

1 Like

Same here ...

Motion Lighting is one of those things many of us use over and over. So I created a 'template' on my 1st page of Node-Red. I can just copy/paste the nodes anytime I need them. Because it's a template, I also tried to add options.. so that I can just delete items vs adding them in. This one has both Mode and time-of-day..

I detailed a large portion of this in my video for Node-Red

Flow

[{"id":"c17b4e60.1855e8","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"4ac9a4f7.b6b094","type":"hubitat device","z":"c17b4e60.1855e8","name":"MotionSensor","server":"4681f676.154b78","deviceId":"","attribute":"","sendEvent":true,"x":300,"y":320,"wires":[["2d67ce4e.fe0d8a","96d7be23.de1ed8"]]},{"id":"907ce4f9.26f49","type":"switch","z":"c17b4e60.1855e8","name":"Active/Inactive","property":"payload.value","propertyType":"msg","rules":[{"t":"eq","v":"active","vt":"str"},{"t":"eq","v":"inactive","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":546,"y":391,"wires":[["c065ee86.379aa8"],["1433aecc.60b411"]]},{"id":"ca479ee8.17a6","type":"hubitat command","z":"c17b4e60.1855e8","name":"Office Ceiling Light ON","server":"4681f676.154b78","deviceId":"","command":"","commandArgs":"","x":1185,"y":377,"wires":[["fa994e7.641dc3"]]},{"id":"bcc35300.a236d","type":"hubitat command","z":"c17b4e60.1855e8","name":"Office Ceiling Light OFF","server":"4681f676.154b78","deviceId":"","command":"","commandArgs":"","x":1174,"y":501,"wires":[["fa994e7.641dc3"]]},{"id":"69086cbb.978a64","type":"hubitat mode","z":"c17b4e60.1855e8","name":"Mode Is","server":"4681f676.154b78","sendEvent":true,"x":328,"y":120,"wires":[["396af26d.353eae"]]},{"id":"2d67ce4e.fe0d8a","type":"switch","z":"c17b4e60.1855e8","name":"Mode Switch","property":"currentMode","propertyType":"global","rules":[{"t":"eq","v":"Day","vt":"str"},{"t":"eq","v":"Evening","vt":"str"},{"t":"eq","v":"Night","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":4,"x":270,"y":486,"wires":[["907ce4f9.26f49"],["907ce4f9.26f49"],["907ce4f9.26f49"],["bcc35300.a236d"]]},{"id":"4ef189ac.1550f","type":"change","z":"c17b4e60.1855e8","name":"saveCurrentMode","rules":[{"t":"set","p":"currentMode","pt":"global","to":"payload.value","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":673,"y":120,"wires":[["a4b0dca3.fa323"]]},{"id":"396af26d.353eae","type":"rbe","z":"c17b4e60.1855e8","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":493,"y":120,"wires":[["4ef189ac.1550f"]]},{"id":"a4b0dca3.fa323","type":"debug","z":"c17b4e60.1855e8","d":true,"name":"SavedMode IS","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1298,"y":124,"wires":[]},{"id":"71a8a072.d0bcc","type":"inject","z":"c17b4e60.1855e8","name":"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":130,"y":320,"wires":[["4ac9a4f7.b6b094"]]},{"id":"96d7be23.de1ed8","type":"debug","z":"c17b4e60.1855e8","d":true,"name":"Motion IS","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1330,"y":320,"wires":[]},{"id":"bd451cc7.0b89e","type":"comment","z":"c17b4e60.1855e8","name":"set a global mode variable, global.currentMode, useful everywhere in this Flow.","info":"","x":358,"y":58,"wires":[]},{"id":"161bd6c6.6c2dc9","type":"comment","z":"c17b4e60.1855e8","name":"sample of Motion by Mode","info":"","x":188,"y":261,"wires":[]},{"id":"c30c9e14.48887","type":"inject","z":"c17b4e60.1855e8","name":"","repeat":"","crontab":"","once":true,"onceDelay":"0.1","topic":"","payload":"Started!","payloadType":"str","x":138,"y":121,"wires":[["69086cbb.978a64"]]},{"id":"c065ee86.379aa8","type":"change","z":"c17b4e60.1855e8","name":"Cancelable","rules":[{"t":"delete","p":"payload.value","pt":"msg"},{"t":"set","p":"payload","pt":"msg","to":"stop","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":747,"y":384,"wires":[["f149ae45.565e","1433aecc.60b411"]]},{"id":"f149ae45.565e","type":"time-range-switch","z":"c17b4e60.1855e8","name":"Dawn-8PM","lat":"37.3230","lon":"-122.0322","startTime":"sunrise","endTime":"20:00","startOffset":0,"endOffset":0,"x":922,"y":384,"wires":[["ca479ee8.17a6"],["e100ee34.01d4e"]]},{"id":"e100ee34.01d4e","type":"hubitat command","z":"c17b4e60.1855e8","name":"Office Ceiling Light 10%","server":"4681f676.154b78","deviceId":"","command":"","commandArgs":"10","x":1175,"y":438,"wires":[[]]},{"id":"fa994e7.641dc3","type":"debug","z":"c17b4e60.1855e8","d":true,"name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1448,"y":438,"wires":[]},{"id":"1433aecc.60b411","type":"stoptimer-varidelay","z":"c17b4e60.1855e8","duration":"15","durationType":"num","units":"Second","payloadtype":"num","payloadval":"0","name":"","reporting":"none","x":908,"y":458,"wires":[["bcc35300.a236d"],[],[]]},{"id":"4681f676.154b78","type":"hubitat config","z":"","name":"TEST Hub","usetls":false,"host":"192.168.1.100","port":"80","appId":"33","nodeRedServer":"http://raspberrypi2.aclysnet.com:1880","webhookPath":"/hubitat/webhook_","autoRefresh":true,"useWebsocket":false}]

6 Likes

got projects 80% setup
stuck on getting connect to github working

Thanks guys; I'd forgotten I had saved the mode in a global variable. Figured I had to be overcomplicating it. Switched the flows I had to a pi from synology docker and missed setting up the global variable again. Works like a charm now.

I followed this thread and was able to successfully push.

1 Like

Here is my circadian lighting flow. It uses the circadian-light node, which will report the position of the sun in the sky from 0-100% and converts that percent into a specified range. I’m using two different ranges for different bulbs. one that goes from 2200-5000 and one that goes from 2700-5000 and back down again. it then puts this info into a global variable in node red and into a rule-machine-connector on two different hubs. It also graphs it on the node red dashboard.

works really well, better than my hubitat rules did since it is now using astronomical noon for the peak, which is about 2pm where I live this time of year.

Flow
[{"id":"e9166966.9cbf1","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"2bf3bbed.b3c15c","type":"debug","z":"e9166966.9cbf1","name":"2700","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":730,"y":34,"wires":[]},{"id":"30a25f07.ef00a8","type":"Circadian Light","z":"e9166966.9cbf1","lat":"39.878050","lon":"-86.053259","period":"1","topic":"","name":"","x":128,"y":221,"wires":[["dc54d300.47f4","2e2d183a.df8ad"]]},{"id":"dc54d300.47f4","type":"range","z":"e9166966.9cbf1","minin":"0","maxin":"100","minout":"2700","maxout":"5000","action":"clamp","round":true,"property":"payload.percent","name":"","x":342,"y":187,"wires":[["beb9e90c.e8fcd"]]},{"id":"beb9e90c.e8fcd","type":"change","z":"e9166966.9cbf1","name":"global.circadian2700","rules":[{"t":"set","p":"circadian2700","pt":"global","to":"payload.percent","tot":"msg"},{"t":"set","p":"arguments","pt":"msg","to":"payload.percent","tot":"msg"},{"t":"set","p":"payload","pt":"msg","to":"payload.percent","tot":"msg"},{"t":"set","p":"topic","pt":"msg","to":"2700","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":559,"y":187,"wires":[["2bf3bbed.b3c15c","904442df.989218","181a2d9e.9a8732","a9bc4a50.9a95f8"]]},{"id":"2e2d183a.df8ad","type":"range","z":"e9166966.9cbf1","minin":"0","maxin":"100","minout":"2200","maxout":"5000","action":"clamp","round":true,"property":"payload.percent","name":"","x":342,"y":255,"wires":[["170a69db.2f54be"]]},{"id":"170a69db.2f54be","type":"change","z":"e9166966.9cbf1","name":"global.circadian2200","rules":[{"t":"set","p":"circadian2200","pt":"global","to":"payload.percent","tot":"msg"},{"t":"set","p":"arguments","pt":"msg","to":"payload.percent","tot":"msg"},{"t":"set","p":"payload","pt":"msg","to":"payload.percent","tot":"msg"},{"t":"set","p":"topic","pt":"msg","to":"2200","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":559,"y":255,"wires":[["9fdfa2a5.fd4b8","dbe4eecc.39b2a8","bc620dd.9acd5f","181a2d9e.9a8732"]]},{"id":"9fdfa2a5.fd4b8","type":"debug","z":"e9166966.9cbf1","name":"2200","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":730,"y":408,"wires":[]},{"id":"dbe4eecc.39b2a8","type":"hubitat command","z":"e9166966.9cbf1","name":"North colorTemp","server":"319c6842.9a57d8","deviceId":"2066","command":"setColorTemperature","commandArgs":"","x":838,"y":255,"wires":[[]]},{"id":"904442df.989218","type":"hubitat command","z":"e9166966.9cbf1","name":"North colorTemp2700","server":"319c6842.9a57d8","deviceId":"2065","command":"setColorTemperature","commandArgs":"","x":848,"y":187,"wires":[[]]},{"id":"181a2d9e.9a8732","type":"ui_chart","z":"e9166966.9cbf1","name":"","group":"76293fc1.a8af3","order":0,"width":0,"height":0,"label":"Color Temperature","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"2000","ymax":"5200","removeOlder":"3","removeOlderPoints":"","removeOlderUnit":"86400","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"outputs":1,"x":838,"y":221,"wires":[[]]},{"id":"f1a62368.faa898","type":"comment","z":"e9166966.9cbf1","name":"Circadian Level","info":"","x":115,"y":68,"wires":[]},{"id":"a9bc4a50.9a95f8","type":"hubitat command","z":"e9166966.9cbf1","name":"South colorTemp2700 circadian","server":"cd816c39.6978b","deviceId":"2241","command":"setColorTemperature","commandArgs":"","x":878,"y":153,"wires":[[]]},{"id":"bc620dd.9acd5f","type":"hubitat command","z":"e9166966.9cbf1","name":"South colorTemp circadian","server":"cd816c39.6978b","deviceId":"2240","command":"setColorTemperature","commandArgs":"","x":868,"y":289,"wires":[[]]},{"id":"319c6842.9a57d8","type":"hubitat config","z":"","name":"Hubitat North","usetls":false,"host":"hubnorth.local","port":"80","appId":"1685","nodeRedServer":"http://nodered.local:1880/","webhookPath":"/hubitat/webhook_","autoRefresh":true,"useWebsocket":false},{"id":"76293fc1.a8af3","type":"ui_group","z":"","name":"Default","tab":"f61e3daf.afe048","order":1,"disp":true,"width":"6","collapse":false},{"id":"cd816c39.6978b","type":"hubitat config","z":"","name":"Hubitat South","usetls":false,"host":"hubsouth.local","port":"80","appId":"2064","nodeRedServer":"http://nodered.local:1880","webhookPath":"/hubitat/webhook","autoRefresh":true,"useWebsocket":false},{"id":"f61e3daf.afe048","type":"ui_tab","z":"","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]
2 Likes

I get to this screen

and nothing I typein find or create works

And because we can always do it more than 1 way... instead of saving mode as a variable, I created 2 sub flows for mode switching, one that is passive and switches for inline checking, and one that switches based on the mode changing event. I can post if anyone is interested.

Another thing you can do - which I've ended up doing a lot is to convert the logic bit of sequences like these into subflows.. Then it becomes easy to change behavior across all your sequences without editing everything.

You can do a ton of stuff with subflows + environment variables (kind of an odd name for "properties").

I even do simple things like put a preconfigured email node in a subflow so I only have to change it in one place...

"Big Timeout" and "Big Convert" are both subflows.. here is the property page for "Big Timeout" (my mudroom motion sequence).

Note: I can supply a (global) variable name which I then use to test in the subflow itself and disable motion sensing if it is set to true. Also define INPUT and OUTPUT types so I can use this for motion or any binary condition..

Big Convert is simply a catch-all conversion logic subflow used to change one binary result to another. It can also probably be easily handled via switch/change nodes but I wanted my logic to be consistent across sequences.

Edit: I dunno if it's the unsafe function node I'm using inside but in some cases the "Big Convert" subflow seems faster then a set of switch/change nodes in the same place. Particularly for looping type situations. Because I did not test thoroughly I could be mistaken but it's definitely not any slower.

4 Likes

OK, For subflows I didn't know you could set properties. I would like to convert my 2 mode event subflows to 1 since the only difference is if the mode node has send event toggled. I created the property in the sub flow, how do I get the mode node to see the subflow property?

https://nodered.org/docs/user-guide/editor/workspace/subflows

2 Likes

Not sure what you mean here? If you mean turn "send events" on/off with subflow properties - you can't.

That was what I was trying to do... Darn.

You could always make a feature request to @fblackburn to make the "send events" option settable by variable. Not sure how many people want that / how hard it is to do. The code is currently expecting it to be set at creation time, though, so probably not a completely trivial change.

I usually keep my HE Nodes out of my subflows just to keep things simple.

Yeah, What I have works, and my want was for cosmetic reasons. I'll pass on asking for just that.

1 Like