Node-Red Flow Samples/Sharing

Moving this over :grinning:

I guess I was overthinking this! Will take a look at the config node. Thanks!

EDIT: Just looked at the setting and it is set to rebuild cache on systemStart event

It's all right - I did almost the exact same thing starting out with NR.. @fblackburn's HE nodes are very well thought out. I have not had any sync issues that weren't my fault. :crossed_fingers:

Also sometimes you might want to generate your own "events" in NR - I do this using MQTT (and the AEDES node)... but you can also use the Link Nodes.

1 Like

I use the Link nodes in a couple of places. Haven't played around with MQTT as yet but may start soon!

It might be overkill but it works well with my stuff.. it's very easy to play around with..

Note: this is not quite as full featured as Mosquitto but a good starting place and simple to integrate.

3 Likes

NOTE: Part of this sequence is deprecated!!! You no longer need my subflow that converts Mode Name to Mode ID... The "Set Mode" can use mode name already (has to be an exact match of course)... see this post further down this list


I created a simple subflow that stores a variable/value into a global AND MQTT. Then use the MQTT Out In node to detect the changes.

For example I control the Modes for all my hubs in Node-RED and store the results in a global variable as an object. That way I can have "Home/Away" be separate from Morning/Afternoon/Night, also add "Guests" etc..

{
	"away":false,
	"guests":true,
	"alert":false,
	"timePeriod":"Evening",
	"alertMsgs":[],
	"sunTimes":{
"solarNoon":1611681235943,"nadir":1611638035943,"sunrise":1611663276120,"sunset":1611699195766,"sunriseEnd":1611663458727,"sunsetStart":1611699013159,"dawn":1611661537899,"dusk":1611700933987,"nauticalDawn":1611659576640,"nauticalDusk":1611702895246,"nightEnd":1611657657704,"night":1611704814182,"goldenHourEnd":1611665678120,"goldenHour":1611696793766
	},
	"hubstatus":{"MAIN":"online","C5":"online","NET":"online"}
}
2 Likes

Hubitat group devices do not support the commands startLevelChange and stopLevelChange even if the individual devices within the group support those commands - for example zigbee bulbs that use the new Advanced Zigbee Bulb drivers, or other devices that support these commands.

So I created this sequence to approximate startLevelChange and stopLevelChange for group devices that are exposed to Node-RED. It works really well for me using a Pico remote to control a group of two zigbee bulbs. No popcorning, no jerky changes in level.

It works by saving the level of the group device to a flow variable and using that to calculate msg.arguments in repetitive steps that are 200 milliseconds apart (i.e. approximating a "held" action for startLevelChange). Releasing the button resets the reiterative timer, thereby approximating a stopLevelChange.

Sequence code:

[{"id":"a0abf5bc.dff248","type":"switch","z":"9cecb34b.b047c8","name":"1/2/3/4/5","property":"payload.value","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"},{"t":"eq","v":"2","vt":"num"},{"t":"eq","v":"3","vt":"num"},{"t":"eq","v":"4","vt":"num"},{"t":"eq","v":"5","vt":"num"}],"checkall":"true","repair":false,"outputs":5,"x":3520,"y":1740,"wires":[["d66182d6.93d2b8"],["6da2d826.4d05b"],["5379a442.f405d4"],["de8d5dd9.b4cb78"],["4b5228e.cfbb5d8"]]},{"id":"6da2d826.4d05b","type":"switch","z":"9cecb34b.b047c8","name":"pushed/held/released","property":"payload.name","propertyType":"msg","rules":[{"t":"eq","v":"pushed","vt":"str"},{"t":"eq","v":"held","vt":"str"},{"t":"eq","v":"released","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":3740,"y":1680,"wires":[["4ef9822d.52e8fc"],["9293c97a.518cb8"],["2ac61b11.701b9c"]]},{"id":"9293c97a.518cb8","type":"delay","z":"9cecb34b.b047c8","name":"200 ms","pauseType":"delay","timeout":"200","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":4020,"y":1680,"wires":[["fbefe70e.f72b28"]]},{"id":"2ac61b11.701b9c","type":"change","z":"9cecb34b.b047c8","name":"reset","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":3895,"y":1700,"wires":[["9293c97a.518cb8"]],"l":false},{"id":"fbefe70e.f72b28","type":"change","z":"9cecb34b.b047c8","name":"raise","rules":[{"t":"set","p":"command","pt":"msg","to":"setLevel","tot":"str"},{"t":"set","p":"arguments","pt":"msg","to":"$flowContext(\"gn_level\") + 3","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":4190,"y":1680,"wires":[["9293c97a.518cb8","65a9d48c.7e0fcc"]]},{"id":"de8d5dd9.b4cb78","type":"switch","z":"9cecb34b.b047c8","name":"pushed/held/released","property":"payload.name","propertyType":"msg","rules":[{"t":"eq","v":"pushed","vt":"str"},{"t":"eq","v":"held","vt":"str"},{"t":"eq","v":"released","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":3740,"y":1800,"wires":[["1a30ac21.8c5264"],["5c74d2bb.ca1e24"],["22a9038e.d950e4"]]},{"id":"5c74d2bb.ca1e24","type":"delay","z":"9cecb34b.b047c8","name":"200 ms","pauseType":"delay","timeout":"200","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":4020,"y":1800,"wires":[["b9e49bc2.7ea398"]]},{"id":"22a9038e.d950e4","type":"change","z":"9cecb34b.b047c8","name":"reset","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":3895,"y":1820,"wires":[["5c74d2bb.ca1e24"]],"l":false},{"id":"b9e49bc2.7ea398","type":"change","z":"9cecb34b.b047c8","name":"lower","rules":[{"t":"set","p":"command","pt":"msg","to":"setLevel","tot":"str"},{"t":"set","p":"arguments","pt":"msg","to":"$flowContext(\"gn_level\") - 3","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":4190,"y":1800,"wires":[["5c74d2bb.ca1e24","b7616fa2.94cc4"]]},{"id":"50ab32be.f7589c","type":"hubitat command","z":"9cecb34b.b047c8","deviceLabel":"Guest Nightstand","name":"","server":"a22e0ea9.276dc8","deviceId":"1482","command":"","commandArgs":"","x":4550,"y":1740,"wires":[[]]},{"id":"7591bac8.38e28c","type":"switch","z":"9cecb34b.b047c8","name":"0-100","property":"arguments","propertyType":"msg","rules":[{"t":"btwn","v":"0","vt":"num","v2":"100","v2t":"num"}],"checkall":"true","repair":false,"outputs":1,"x":4350,"y":1740,"wires":[["50ab32be.f7589c"]]},{"id":"d66182d6.93d2b8","type":"change","z":"9cecb34b.b047c8","name":"on 100%","rules":[{"t":"set","p":"command","pt":"msg","to":"setLevel","tot":"str"},{"t":"set","p":"arguments","pt":"msg","to":"100","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":3700,"y":1620,"wires":[["50ab32be.f7589c"]]},{"id":"4b5228e.cfbb5d8","type":"change","z":"9cecb34b.b047c8","name":"off","rules":[{"t":"set","p":"command","pt":"msg","to":"off","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":3690,"y":1860,"wires":[["50ab32be.f7589c"]]},{"id":"5379a442.f405d4","type":"change","z":"9cecb34b.b047c8","name":"on 50%","rules":[{"t":"set","p":"command","pt":"msg","to":"setLevel","tot":"str"},{"t":"set","p":"arguments","pt":"msg","to":"50","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":3700,"y":1740,"wires":[["50ab32be.f7589c"]]},{"id":"4ef9822d.52e8fc","type":"change","z":"9cecb34b.b047c8","name":"raise by 5","rules":[{"t":"set","p":"command","pt":"msg","to":"setLevel","tot":"str"},{"t":"set","p":"arguments","pt":"msg","to":"$flowContext(\"gn_level\") + 5","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":3895,"y":1660,"wires":[["50ab32be.f7589c"]],"l":false},{"id":"1a30ac21.8c5264","type":"change","z":"9cecb34b.b047c8","name":"lower by 5","rules":[{"t":"set","p":"command","pt":"msg","to":"setLevel","tot":"str"},{"t":"set","p":"arguments","pt":"msg","to":"$flowContext(\"gn_level\") - 5","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":3895,"y":1780,"wires":[["50ab32be.f7589c"]],"l":false},{"id":"65a9d48c.7e0fcc","type":"function","z":"9cecb34b.b047c8","name":"","func":"if (msg.arguments > 100) {\n    msg.arguments = 100\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":4295,"y":1680,"wires":[["7591bac8.38e28c"]],"l":false},{"id":"b7616fa2.94cc4","type":"function","z":"9cecb34b.b047c8","name":"","func":"if (msg.arguments < 0) {\n    msg.arguments = 0\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":4295,"y":1800,"wires":[["7591bac8.38e28c"]],"l":false},{"id":"52498b04.53727c","type":"hubitat device","z":"9cecb34b.b047c8","name":"Guest Nightstand level","server":"a22e0ea9.276dc8","deviceId":"1482","attribute":"level","sendEvent":true,"x":4090,"y":1580,"wires":[["e6e48278.ee0f"]]},{"id":"e6e48278.ee0f","type":"change","z":"9cecb34b.b047c8","name":"flow.gn_level","rules":[{"t":"set","p":"gn_level","pt":"flow","to":"payload.value","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":4310,"y":1580,"wires":[[]]},{"id":"7887fb68.739014","type":"hubitat device","z":"9cecb34b.b047c8","deviceLabel":"Guest Bedroom Pico Hold","name":"Guest Bedroom Pico","server":"662851c4.3ccad","deviceId":"22","attribute":"","sendEvent":true,"x":3300,"y":1740,"wires":[["a0abf5bc.dff248"]]},{"id":"a22e0ea9.276dc8","type":"hubitat config","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},{"id":"662851c4.3ccad","type":"hubitat config","name":"HubitatS","usetls":false,"host":"192.168.1.36","port":"80","appId":"4489","nodeRedServer":"http://192.168.1.4:1880","webhookPath":"/hubitat/webhook2","autoRefresh":true,"useWebsocket":false}]
5 Likes

Quick question - do you know if the device nodes get current state on Nodered restart? Event for systemStart would be for HE restart, right? I know it does it on "deploy" but was wondering if the same thing happened when Nodered is restarted.

Yes the entire cache gets rebuilt on an NR restart and yes it also happens when an HE restarts and that option is set.

2 Likes

Looking for some help with formatting color info. I’m using the virtual-smart-home alexa plugin (which is rock solid, btw)

It basically creates virtual devices that then integrate into node red. I’m trying to get color commands that come out of these nodes to work going into the hubitat nodes. I’m having trouble figuring out how to get it formatted correctly.

I’ve attached the output from a debug node along with the sample flow I’m using. I’m not sure how to take the values and convert them into a JSON expression that the hubitat nodes will take.

Any input would be great. thanks.

Debug

‘’’
object

topic: "alexa"

payload: object

directive: "SetColor"

color: object

hue: 0

saturation: 1

brightness: 1

lightMode: "hsb"

color_rgb: array[3]

0: 255

1: 0

2: 0

color_hex: "#FF0000"

color_cmyk: array[4]

0: 0

1: 100

2: 100

3: 0

color_lab: array[3]

0: 53

1: 80

2: 67

color_xyz: array[3]

0: 41

1: 21

2: 2

_msgid: "98c3e3e9.6b13a"
‘’’

Flow

‘’’
[{"id":"8bd4c911.9db3e","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"e0234f0b.10dbd","type":"vsh-virtual-device","z":"8bd4c911.9db3e","name":"test","topic":"alexa","connection":"848c4e7f.3ee87","template":"COLOR_CHANGING_LIGHT_BULB","passthrough":false,"diff":true,"x":118,"y":204,"wires":[["aa8b238d.e0b568","8062e0d5.de0a08"]]},{"id":"aa8b238d.e0b568","type":"switch","z":"8bd4c911.9db3e","name":"Command","property":"payload.directive","propertyType":"msg","rules":[{"t":"eq","v":"TurnOn","vt":"str"},{"t":"eq","v":"TurnOff","vt":"str"},{"t":"eq","v":"SetBrightness","vt":"str"},{"t":"eq","v":"SetColorTemperature","vt":"str"},{"t":"eq","v":"SetColor","vt":"str"}],"checkall":"true","repair":false,"outputs":5,"x":444,"y":204,"wires":[["5ab71e2.e09616"],["5900d0fc.36f4d8"],["4e3e5fa9.bdc438"],["919a24ad.73394"],["750f8c29.b07e74"]]},{"id":"8062e0d5.de0a08","type":"debug","z":"8bd4c911.9db3e","name":"","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"payload.powerState","statusType":"msg","x":356,"y":102,"wires":[]},{"id":"5900d0fc.36f4d8","type":"debug","z":"8bd4c911.9db3e","name":"","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"_msgid","statusType":"msg","x":781,"y":170,"wires":[]},{"id":"4e3e5fa9.bdc438","type":"debug","z":"8bd4c911.9db3e","name":"","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"_msgid","statusType":"msg","x":781,"y":221,"wires":[]},{"id":"750f8c29.b07e74","type":"debug","z":"8bd4c911.9db3e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"_msgid","statusType":"msg","x":781,"y":323,"wires":[]},{"id":"919a24ad.73394","type":"debug","z":"8bd4c911.9db3e","name":"","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"_msgid","statusType":"msg","x":781,"y":272,"wires":[]},{"id":"5ab71e2.e09616","type":"debug","z":"8bd4c911.9db3e","name":"","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"_msgid","statusType":"msg","x":781,"y":119,"wires":[]},{"id":"848c4e7f.3ee87","type":"vsh-connection","name":"jrau272@gmail.com","port":"8883","accessTokenExpiry":"1610909547461"}]
‘’’

I am using the NR dashboard to generate the color, but this is what the object that I am sending to the Hubitat node looks like:
image

msg.command and msg.arguments are the only parts relevant to the hubitat node.

One other note, I have found the color convert node (node-red-contrib-color-convert) is really useful in getting to the format needed for a given device.

2 Likes

I’m having a hard time getting my arguments formatted like that. perhaps this is a better way to show the output from this node:

it outputs about every way to describe color that there is. I just can’t figure out how to pipe it into a hubitat node.

Have you tried JSONATA in a change node?

'{"hue":' & payload.xxx & ',"saturation":' & payload.yyy & ',"level":' & payload.zzz & '}'

Here is an example sequence you can import - it's "wrong" but should give you an idea...

[{"id":"fe30603.3f31ca","type":"inject","z":"af91369d.586338","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"test","payload":"{\"color\":{\"hue\":0,\"saturation\":1,\"brightness\":1}}","payloadType":"json","x":380,"y":2240,"wires":[["d81c6f5d.03f11"]]},{"id":"d81c6f5d.03f11","type":"change","z":"af91369d.586338","name":"","rules":[{"t":"set","p":"arguments","pt":"msg","to":"'{\"hue\":' & payload.color.hue & ',\"saturation\":' & payload.color.saturation & ',\"level\":' & payload.color.brightness & '}'\t","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":630,"y":2240,"wires":[["fa011b65.7b24f8"]]},{"id":"fa011b65.7b24f8","type":"debug","z":"af91369d.586338","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":910,"y":2240,"wires":[]}]

Otherwise a function node would do the trick.

Oh man. I’m so close, but I don’t know anything about jsonata

this:
'{"hex":' & payload.color_hex & '}'

gets me
(“hex”:FF0000)

and I need it to be
(“hex”:”FF0000”)

'{"hex":"' & payload.color_hex & '"}'

2 Likes

You rock! Thanks. That worked.

2 Likes

well for some reason sending hex codes to hubitat isn’t working correctly. I’m not sure if this is an issue with the nodes or my device or what. the mapping doesn’t seem to come out correctly. Red works, but other colors i’ve tried aren’t working.

I can send HSL values and get it to work. the problem now is that the outputs of this alexa node all have to be scaled.

payload.color.hue needs to be scaled from 0-360 to 0-100
payload.color.saturation and payload.color.brightness need to be scaled from 0-1 to 0-100

I can use the range node to do the scaling, but it requires 3 nodes and then I end up with 3 separate outputs.

How do I combine these back together in a format I can send to a command node?

You can use a Join node but there is some setup involved.

Just a quickie, I've checked the NR forum and don't find anything, but does anyone else not see Alexa Routines when using Alexa Routine node of Alexa-Remote2?

Just noticed today that no routines are showing, just ???? And thats after re-authing (just in case).

Cheers :+1:

I think you could do it in a function node like below:

msg.payload.color.hue =  Math.ceil((msg.payload.color.hue/360)*100);
msg.payload.color.saturation = msg.payload.color.saturation*10;
msg.payload.color.level = msg.payload.color.level*10;
return msg;

Thanks for everyone’s help. I got it working. Turns out I could just put my range nodes in sequence. if anyone else is interested here is an example flow for a color changing bulb with the virtual smart home node (which works far more reliably, if in a somewhat more limited fashion, than the alexa-remote2

I combined all those range nodes and the color node into a subflow just for neatness sake.

flow

‘’’
[{"id":"cc5490a0.5d9b","type":"subflow","name":"Alexa Color Bulb","info":"","category":"","in":[{"x":122,"y":374,"wires":[{"id":"f8f545a9.76fd3"}]}],"out":[{"x":1210,"y":238,"wires":[{"id":"c93c2e11.70e4","port":0}]},{"x":1210,"y":289,"wires":[{"id":"dd3aa503.a6f6d","port":0}]},{"x":1210,"y":340,"wires":[{"id":"8452c43b.2ba2f8","port":0}]},{"x":1210,"y":391,"wires":[{"id":"6f79aafa.3da2c4","port":0}]},{"x":1210,"y":442,"wires":[{"id":"5e77579d.cfa98","port":0}]}],"env":[],"color":"#C7E9C0","inputLabels":["alexa"],"outputLabels":["On","Off","Level","Color Temperature","Color"],"icon":"node-red/switch.svg"},{"id":"33ef047f.5f7af4","type":"range","z":"cc5490a0.5d9b","minin":"0","maxin":"360","minout":"0","maxout":"100","action":"scale","round":true,"property":"payload.color.hue","name":"hue","x":577,"y":442,"wires":[["372edb60.dcc474"]]},{"id":"372edb60.dcc474","type":"range","z":"cc5490a0.5d9b","minin":"0","maxin":"1","minout":"0","maxout":"100","action":"scale","round":true,"property":"payload.color.saturation","name":"saturation","x":723,"y":442,"wires":[["2f1322be.d5db86"]]},{"id":"2f1322be.d5db86","type":"range","z":"cc5490a0.5d9b","minin":"0","maxin":"1","minout":"0","maxout":"100","action":"scale","round":true,"property":"payload.color.brightness","name":"level","x":883,"y":442,"wires":[["5e77579d.cfa98"]]},{"id":"5e77579d.cfa98","type":"change","z":"cc5490a0.5d9b","name":"Color","rules":[{"t":"set","p":"command","pt":"msg","to":"setColor","tot":"str"},{"t":"set","p":"arguments","pt":"msg","to":"'{\"hue\":' & payload.color.hue & ',\"saturation\":' & payload.color.saturation & ',\"level\":' & payload.color.brightness & '}'","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1036,"y":442,"wires":[[]]},{"id":"f8f545a9.76fd3","type":"switch","z":"cc5490a0.5d9b","name":"Command","property":"payload.directive","propertyType":"msg","rules":[{"t":"eq","v":"TurnOn","vt":"str"},{"t":"eq","v":"TurnOff","vt":"str"},{"t":"eq","v":"SetBrightness","vt":"str"},{"t":"eq","v":"SetColorTemperature","vt":"str"},{"t":"eq","v":"SetColor","vt":"str"}],"checkall":"true","repair":false,"outputs":5,"x":308,"y":374,"wires":[["c93c2e11.70e4"],["dd3aa503.a6f6d"],["8452c43b.2ba2f8"],["6f79aafa.3da2c4"],["33ef047f.5f7af4"]]},{"id":"8452c43b.2ba2f8","type":"change","z":"cc5490a0.5d9b","name":"Brightness","rules":[{"t":"set","p":"command","pt":"msg","to":"setLevel","tot":"str"},{"t":"set","p":"arguments","pt":"msg","to":"payload.brightness","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":597,"y":374,"wires":[[]]},{"id":"6f79aafa.3da2c4","type":"change","z":"cc5490a0.5d9b","name":"CT command","rules":[{"t":"set","p":"command","pt":"msg","to":"setColorTemperature","tot":"str"},{"t":"set","p":"arguments","pt":"msg","to":"payload.colorTemperatureInKelvin","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":607,"y":408,"wires":[[]]},{"id":"c93c2e11.70e4","type":"change","z":"cc5490a0.5d9b","name":"On","rules":[{"t":"set","p":"command","pt":"msg","to":"on","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":577,"y":306,"wires":[[]]},{"id":"dd3aa503.a6f6d","type":"change","z":"cc5490a0.5d9b","name":"Off","rules":[{"t":"set","p":"command","pt":"msg","to":"off","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":577,"y":340,"wires":[[]]}]
‘’’

3 Likes