Node-Red Palette: Common Choices

So one way to do this is to set mode as a global variable (meaning you can use it across all your flows). And then use a switch node, where necessary, to route messages dependent on that global variable (I call mine global.hubitat_mode).

setting global.hubitat_mode

[{"id":"f92f11e1.c160e8","type":"hubitat mode","z":"7c38f6e6.c33b8","name":"","server":"a22e0ea9.276dc8","sendEvent":true,"x":275,"y":60,"wires":[["925a1bc7.00b64"]]},{"id":"925a1bc7.00b64","type":"change","z":"7c38f6e6.c33b8","name":"global.hubitat_mode","rules":[{"t":"set","p":"hubitat_mode","pt":"global","to":"payload.value","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":460,"y":60,"wires":[[]]},{"id":"834f5e9b.f270c","type":"inject","z":"7c38f6e6.c33b8","name":"","repeat":"","crontab":"","once":true,"onceDelay":"10","topic":"","payload":"10 secs","payloadType":"str","x":125,"y":60,"wires":[["f92f11e1.c160e8"]]},{"id":"a22e0ea9.276dc8","type":"hubitat config","z":"","name":"HubitatM","usetls":false,"host":"192.168.1.46","port":"80","appId":"1522","nodeRedServer":"http://192.168.1.4:1880","webhookPath":"/hubitat/webhook","autoRefresh":true,"useWebsocket":false}]

2 Likes

That's actually the end result of the Video I made!

http://homebridge.hubitatcommunity.com/Hubitat_Node-Red/

From the 2:25 mark onward. :smiley:

Although, importing @aaiyar node code will be faster.

4 Likes

Knew I saw it somewhere. NR overload :exploding_head: thanks for the refresh and to @aaiyar for posting the code which I imported. :wink:

1 Like

Someone else mentioned retaining a "junk yard" on one of their Flows to fundamentally be a 'clipboard' of ideas.

This is a portion of mine...

Junk Yard

[{"id":"952fcefb.7159f8","type":"hubitat device","z":"c200f504.6ecb68","name":"MultiSenDomeU (office3)","server":"c3a39a36.1bf95","deviceId":"98","attribute":"motion","sendEvent":true,"x":312,"y":342,"wires":[["3ec5420e.42656e","40617f76.81b02"]]},{"id":"1275c24b.ee9d36","type":"switch","z":"c200f504.6ecb68","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":528,"y":413,"wires":[["b4ddee7.4a0369"],["cf5c9337.0f6db"]]},{"id":"54b83846.b5e5d","type":"hubitat command","z":"c200f504.6ecb68","name":"Office Ceiling Light ON","server":"c3a39a36.1bf95","deviceId":"76","command":"on","commandArgs":"","x":1167,"y":399,"wires":[["19fc670d.d21879"]]},{"id":"d3d92099.a2bf68","type":"hubitat command","z":"c200f504.6ecb68","name":"Office Ceiling Light OFF","server":"c3a39a36.1bf95","deviceId":"76","command":"off","commandArgs":"","x":1156,"y":523,"wires":[["19fc670d.d21879"]]},{"id":"efe25a0b.8cffd8","type":"hubitat mode","z":"c200f504.6ecb68","name":"Mode Is","server":"c3a39a36.1bf95","sendEvent":true,"x":310,"y":142,"wires":[["3282232a.0d743c"]]},{"id":"3ec5420e.42656e","type":"switch","z":"c200f504.6ecb68","d":true,"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":252,"y":508,"wires":[["1275c24b.ee9d36"],["1275c24b.ee9d36"],["1275c24b.ee9d36"],["d3d92099.a2bf68"]]},{"id":"b5dd4545.cd9178","type":"change","z":"c200f504.6ecb68","name":"saveCurrentMode","rules":[{"t":"set","p":"currentMode","pt":"global","to":"payload.value","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":655,"y":142,"wires":[["901fc539.012088"]]},{"id":"3282232a.0d743c","type":"rbe","z":"c200f504.6ecb68","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":475,"y":142,"wires":[["b5dd4545.cd9178"]]},{"id":"901fc539.012088","type":"debug","z":"c200f504.6ecb68","d":true,"name":"SavedMode IS","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1280,"y":146,"wires":},{"id":"62f0a316.3b0894","type":"inject","z":"c200f504.6ecb68","name":"","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":112,"y":342,"wires":[["952fcefb.7159f8"]]},{"id":"40617f76.81b02","type":"debug","z":"c200f504.6ecb68","d":true,"name":"Motion IS","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1312,"y":342,"wires":},{"id":"10a420f0.53cc6f","type":"comment","z":"c200f504.6ecb68","name":"set a global mode variable, global.currentMode, useful everywhere in this Flow.","info":"","x":340,"y":80,"wires":},{"id":"1433c34c.cb5c5d","type":"comment","z":"c200f504.6ecb68","name":"sample of Motion by Mode","info":"","x":170,"y":283,"wires":},{"id":"bc9829c5.84af","type":"inject","z":"c200f504.6ecb68","name":"","topic":"","payload":"Started!","payloadType":"str","repeat":"","crontab":"","once":true,"onceDelay":"0.1","x":120,"y":143,"wires":[["efe25a0b.8cffd8"]]},{"id":"b4ddee7.4a0369","type":"change","z":"c200f504.6ecb68","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":729,"y":406,"wires":[["91e7bcf3.60a0a8","cf5c9337.0f6db"]]},{"id":"91e7bcf3.60a0a8","type":"time-range-switch","z":"c200f504.6ecb68","name":"Dawn-8PM","lat":"37.3230","lon":"-122.0322","startTime":"sunrise","endTime":"20:00","startOffset":0,"endOffset":0,"x":904,"y":406,"wires":[["54b83846.b5e5d"],["cce8f08a.09307"]]},{"id":"7613c8ca.ab1ec8","type":"comment","z":"c200f504.6ecb68","name":"Duplicate Mode vs Time of Day","info":"This is a Sample flow, thus it has both a Time of day restriction as well as a 'by Mode' restriction. If both are used, then readability is improved if the two match: Dawn to 8pm doesn't work when Mode is not including Day. If both are NOT needed, copy the sample and after pasting, delete one or the other. ","x":561,"y":482,"wires":},{"id":"cce8f08a.09307","type":"hubitat command","z":"c200f504.6ecb68","name":"Office Ceiling Light 10%","server":"c3a39a36.1bf95","deviceId":"76","command":"setLevel","commandArgs":"10","x":1157,"y":460,"wires":[]},{"id":"19fc670d.d21879","type":"debug","z":"c200f504.6ecb68","d":true,"name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1430,"y":460,"wires":},{"id":"cf5c9337.0f6db","type":"stoptimer-varidelay","z":"c200f504.6ecb68","duration":"15","durationType":"num","units":"Second","payloadtype":"num","payloadval":"0","name":"","reporting":"none","x":890,"y":480,"wires":[["d3d92099.a2bf68"],,]},{"id":"c3a39a36.1bf95","type":"hubitat config","z":"","name":"ThirdHubitat","usetls":false,"host":"192.168.7.64","port":"80","appId":"780","nodeRedServer":"http://192.168.7.129:1880","webhookPath":"/hubitat/webhook","autoRefresh":false,"useWebsocket":false}]

There's an identical flow to capture the Mode.. just a fractionally different name. Then a flow that might be Motion+Mode+Time-of-Day(T-o-D) Lighting. I will grab that and delete out the node I don't want.. thus converting it to a Motion+Mode or a Motion+T-o-D. I use the 15 second timer for debug, then change it to 5 mins or similar.

1 Like

Not sure, but I think it might have been @stephack who mentioned it. But it's a very good idea either which way.

3 Likes

I have a flow that is disabled called "On Ice / Trash".. I can put stuff there without having it interfere with things.

Also if getting into globals @TechMedX - you might be interested storing them on the disk rather than in memory so they can be retained across restarts..

https://nodered.org/docs/user-guide/context

It can be a little tricky because a variable declared in the file storage context does not exist in the memory storage context.. can make for some confusing sequence moments..

2 Likes

Some Nodes, such as timers, want Lat/Long. Then it turns out there's a different way, different node and I don't want to discard the baby-with-the-bath-water, so I save that configured node in the junk pile for the next time. It's not like copy/pasting Lat/Long is a giant burden, but it's so easy to save. :smiley:

4 Likes

Yeah I always keep a copy of a "link in" node next to it's related "link out" for that purpose as well.

3 Likes

Same here - I also do that for MQTT nodes.

1 Like

For anyone who uses nodes for hue lights. Does getting state in node red have a large delay if the lights are manually controlled?

Guilty as charged....da,da,danah
1m7sor

2 Likes

Speaking of which .... if you get the chance, watch the original sometime.

2 Likes

Learn something new every day.

1 Like

Now we're talking, "you dirty old maan" :joy:

1 Like

For list consideration - node-red-contrib-repeat

2 Likes

That looks like a nice and simple one!

Also check out these:

and for tasklist style processing - previously mentioned by @tmichael :

2 Likes

I used to use this one. Just be aware that you cannot have more than repeat node acting on the same message. Things get messed up. The loop processing node linked by @erktrek handles that situation ....

2 Likes

I'll never understand most node authors... Why wouldn't you put the loop counter in the node's status area instead of just generic text like "exit loop" (this node) or "running" (most of the timer nodes), etc???

Such a missed opportunity.

On this loop, this means "not running/looping":
image

And this is "running/looping":
image

How many loops are left? Dunno. What is the current loop counter? Dunno. AAAAAAARGH!

Even if you argue that you can't put "how many are left", as it can be a variable you are comparing against, you could always put the current counter value there.

6 Likes

Yeah that seems.... odd. :rofl:

I actually haven't had the need to really do any of that yet so far.. just use split and counter and sometimes DO-RED to make things a little more ordered looking.

edit: I'm guessing just low hanging fruit or minimum viable product!

3 Likes

I have had trouble getting this to successfully work. I've been trying to dim a light over 7 seconds, but there seems to be a significant delay between my msg.arguments command being sent and the response on the hubitat side to a setLevel command.

When I dim over 7 seconds none of the setLevel commands show up in the logs until it hits 0, and then the light shuts off immediately (so it does not actually dim/fade). commands to turn lights on or off, or setLevel to 0 seem to be immediate.

However, if I dim over 20 min then it does get the commands, but there is a significant delay from when node red sends the command to it showing up in the logs for the light on hubitat. Its like the set level command is being slowed down to not spam the hub? 7 seconds seems to be too fast of a fade for some reason. not sure what is going on.