Node-Red Flow Samples/Sharing

I'm suspecting that this is right based on what I'm seeing in the Inovelli LED (Blue = 65 Hue)

This is awesome! :clap:t3: :clap:t3:

do-red is also a great "organizational" node as well.. I use it to prettify my water main valve check sequence.

3 Likes

Thanks for pointing this node out.. looks like a great utility node!

I use do-red a places now. Can be quite handy.

1 Like

@stephen_nutt gets the credit for mentioning it - I just showed an example..

:grinning_face_with_smiling_eyes:

1 Like

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