Node-Red Flow Samples/Sharing

I do something similar in my sensor alert light depending on mode turn it on and off and delay for 1 minute before returning it to previous state

@aaiyar would you be willing to share you Sleep By Number bed flow or at least an example that show how you deflate and inflate it to set it back to 100 daily. I was reading your post on the Sleep Number Controller page. Thanks

2 Likes

This flow deflates it to 1 (in steps of 10), then inflates it to 100 (in steps of 10), then waits a couple minutes and sets it to my preferred Sleep Number. This is only for one side. I have an equivalent flow for the other side. Also, the flow only begins if the bed is not occupied. I have my Sleep Number bed plugged into a controlled outlet which is switched off when the mode is Away, so the flow also runs only when that outlet is on.

[{"id":"fd0ec42f.7d087","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"7bc67c56.7d8fcc","type":"hubitat device","z":"fd0ec42f.7d087","name":"Bed - Outlet","server":"662851c4.3ccad","deviceId":"4394","attribute":"switch","sendEvent":false,"x":330,"y":540,"wires":[["5b33a630.b169d8"]]},{"id":"fe500e5e.df95e8","type":"cronplus","z":"fd0ec42f.7d087","name":"","outputField":"payload","timeZone":"","persistDynamic":true,"commandResponseMsgOutput":"output1","outputs":1,"options":[{"name":"schedule1","topic":"schedule1","payloadType":"str","payload":"","expressionType":"cron","expression":"0 15 19 * * * *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"}],"x":80,"y":540,"wires":[["7bc67c56.7d8fcc"]]},{"id":"5b33a630.b169d8","type":"switch","z":"fd0ec42f.7d087","name":"on","property":"payload.value","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":490,"y":540,"wires":[["219c2f39.a481b8"]]},{"id":"219c2f39.a481b8","type":"switch","z":"fd0ec42f.7d087","name":"vacation off","property":"vacation_status","propertyType":"global","rules":[{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":650,"y":540,"wires":[["f4140fef.3aa0e8"]]},{"id":"f4140fef.3aa0e8","type":"hubitat device","z":"fd0ec42f.7d087","name":"Ashok","server":"662851c4.3ccad","deviceId":"4642","attribute":"presence","sendEvent":false,"x":810,"y":540,"wires":[["f4ead7eb.fba35"]]},{"id":"f4ead7eb.fba35","type":"switch","z":"fd0ec42f.7d087","name":"not present","property":"payload.value","propertyType":"msg","rules":[{"t":"eq","v":"not present","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":990,"y":540,"wires":[["46e373e0.8d983c"]]},{"id":"46e373e0.8d983c","type":"hubitat device","z":"fd0ec42f.7d087","name":"Ashok","server":"662851c4.3ccad","deviceId":"4642","attribute":"level","sendEvent":false,"x":1150,"y":540,"wires":[["747afba0.c0b9ac"]]},{"id":"3b38b2b5.8cf7c6","type":"delay","z":"fd0ec42f.7d087","name":"30","pauseType":"delay","timeout":"30","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":2230,"y":540,"wires":[["46e373e0.8d983c"]]},{"id":"747afba0.c0b9ac","type":"delay","z":"fd0ec42f.7d087","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1255,"y":540,"wires":[["af4c2fc8.132868"]],"l":false},{"id":"87aceb32.8cb1d","type":"hubitat command","z":"fd0ec42f.7d087","name":"Ashok","server":"662851c4.3ccad","deviceId":"4642","command":"setLevel","commandArgs":"msg.arguments","x":2090,"y":540,"wires":[["3b38b2b5.8cf7c6"]]},{"id":"af4c2fc8.132868","type":"change","z":"fd0ec42f.7d087","name":"","rules":[{"t":"set","p":"arguments","pt":"msg","to":"payload.value","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1390,"y":540,"wires":[["a446366d.eded28"]]},{"id":"98576f10.cbfe2","type":"switch","z":"fd0ec42f.7d087","name":"<1/>1/1","property":"arguments","propertyType":"msg","rules":[{"t":"lt","v":"1","vt":"num"},{"t":"gt","v":"1","vt":"num"},{"t":"eq","v":"1","vt":"num"}],"checkall":"true","repair":false,"outputs":3,"x":1880,"y":540,"wires":[["b1fde12f.bb02d8"],["87aceb32.8cb1d"],["a446366d.eded28"]]},{"id":"b1fde12f.bb02d8","type":"change","z":"fd0ec42f.7d087","name":"","rules":[{"t":"set","p":"arguments","pt":"msg","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":1995,"y":520,"wires":[["87aceb32.8cb1d"]],"l":false},{"id":"a446366d.eded28","type":"switch","z":"fd0ec42f.7d087","name":">1/1","property":"arguments","propertyType":"msg","rules":[{"t":"gt","v":"1","vt":"num"},{"t":"eq","v":"1","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":1570,"y":540,"wires":[["c0f27c62.43c0e"],["fecc06b1.96a2f"]]},{"id":"c0f27c62.43c0e","type":"change","z":"fd0ec42f.7d087","name":"Sub 10","rules":[{"t":"set","p":"arguments","pt":"msg","to":"arguments - 10","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1720,"y":540,"wires":[["98576f10.cbfe2"]]},{"id":"fecc06b1.96a2f","type":"delay","z":"fd0ec42f.7d087","name":"","pauseType":"delay","timeout":"2","timeoutUnits":"minutes","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1115,"y":620,"wires":[["30143c1e.5aadfc"]],"l":false},{"id":"30143c1e.5aadfc","type":"hubitat device","z":"fd0ec42f.7d087","name":"Ashok","server":"662851c4.3ccad","deviceId":"4642","attribute":"level","sendEvent":false,"x":1230,"y":620,"wires":[["2025dd13.859b82"]]},{"id":"2025dd13.859b82","type":"delay","z":"fd0ec42f.7d087","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1335,"y":620,"wires":[["68c3d69a.c835c8"]],"l":false},{"id":"289aa599.f3f4ba","type":"delay","z":"fd0ec42f.7d087","name":"30","pauseType":"delay","timeout":"30","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":2350,"y":620,"wires":[["30143c1e.5aadfc"]]},{"id":"68c3d69a.c835c8","type":"change","z":"fd0ec42f.7d087","name":"","rules":[{"t":"set","p":"arguments","pt":"msg","to":"payload.value","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1470,"y":620,"wires":[["32c900a3.ca0158"]]},{"id":"325a514a.094966","type":"hubitat command","z":"fd0ec42f.7d087","name":"Ashok","server":"662851c4.3ccad","deviceId":"4642","command":"setLevel","commandArgs":"msg.arguments","x":2210,"y":620,"wires":[["289aa599.f3f4ba"]]},{"id":"32c900a3.ca0158","type":"switch","z":"fd0ec42f.7d087","name":"<100/100","property":"arguments","propertyType":"msg","rules":[{"t":"lt","v":"100","vt":"num"},{"t":"eq","v":"100","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":1660,"y":620,"wires":[["4d955af9.87b32c"],["6e4d3735.e0347","a4f7a37b.e9633"]]},{"id":"f1ca3d7d.cdd57","type":"switch","z":"fd0ec42f.7d087","name":">100/<=100","property":"arguments","propertyType":"msg","rules":[{"t":"gt","v":"100","vt":"str"},{"t":"lte","v":"100","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":1990,"y":620,"wires":[["f6cbf1ff.0ebd88"],["325a514a.094966"]]},{"id":"f6cbf1ff.0ebd88","type":"change","z":"fd0ec42f.7d087","name":"","rules":[{"t":"set","p":"arguments","pt":"msg","to":"100","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":2115,"y":600,"wires":[["325a514a.094966"]],"l":false},{"id":"4d955af9.87b32c","type":"change","z":"fd0ec42f.7d087","name":"Add 10","rules":[{"t":"set","p":"arguments","pt":"msg","to":"arguments + 10","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1820,"y":620,"wires":[["f1ca3d7d.cdd57"]]},{"id":"6e4d3735.e0347","type":"change","z":"fd0ec42f.7d087","name":"Ashok's Head Position","rules":[{"t":"set","p":"arguments","pt":"msg","to":"12","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":1860,"y":740,"wires":[["78fa50ff.4160c8"]]},{"id":"a4f7a37b.e9633","type":"delay","z":"fd0ec42f.7d087","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"minutes","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1775,"y":680,"wires":[["788dce2e.ff7c8"]],"l":false},{"id":"78fa50ff.4160c8","type":"hubitat command","z":"fd0ec42f.7d087","name":"Ashok Head","server":"662851c4.3ccad","deviceId":"4643","command":"setLevel","commandArgs":"msg.arguments","x":2070,"y":740,"wires":[[]]},{"id":"788dce2e.ff7c8","type":"change","z":"fd0ec42f.7d087","name":"Ashok's Sleep Number","rules":[{"t":"set","p":"arguments","pt":"msg","to":"55","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":1930,"y":680,"wires":[["e13d0e18.1189f"]]},{"id":"e13d0e18.1189f","type":"hubitat command","z":"fd0ec42f.7d087","name":"Ashok","server":"662851c4.3ccad","deviceId":"4642","command":"setLevel","commandArgs":"msg.arguments","x":2130,"y":680,"wires":[[]]},{"id":"662851c4.3ccad","type":"hubitat config","z":"","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}]

@aaiyar Thanks you so much for sharing.

1 Like

@leeonestop and anyone else using the SleepIQ node-red sequence I posted a few days ago:

There's an error in it, because the mattress doesn't respond to inflation levels that are not numbers ending in 0 or 5.

But this is simple to fix in the change nodes that use JSONata for subtraction and addition.

In the change node named "Sub 10",

Change:
arguments - 10
to
$round(arguments, -1) - 10

Similarly, in the change node named, "Add 10",
Change
arguments + 10
to
$round(arguments, -1) + 10

Sorry about the previous error ....

Hey guys - I posted a Node-RED solution for shutting down and restarting the hub in case of power outages (Shutdown and restart Hub in case of power outage (Node-red solution) - LONG READ).

Thought I would link it here in case anyone wanted to take a look.

5 Likes

Here are some Sonos flows, so that if you have Sonos playing somewhere (Master), and then walk into another room with a motion sensor, then it will start playing in that room. There are a couple of versions. There are switches on a Node Red dashboard that turn "party time" on and off.

This is for actived by motion in the slave, and will join the master Sonos, at a set volume.

[{"id":"4f62b245.556d2c","type":"hubitat device","z":"7f5e3dd.11d05c4","name":"MD - Kitchen 2","server":"2120cd99.47cc12","deviceId":"12","attribute":"motion","sendEvent":true,"x":560,"y":80,"wires":[["63d16379.ed480c"]]},{"id":"e8b0988d.5de038","type":"hubitat device","z":"7f5e3dd.11d05c4","name":"MDChild -  Kitchen","server":"b37b2cbb.28c06","deviceId":"18","attribute":"motion","sendEvent":true,"x":550,"y":140,"wires":[["63d16379.ed480c"]]},{"id":"33894329.82eb1c","type":"comment","z":"7f5e3dd.11d05c4","name":"Kitchen: slave, Office: master","info":"","x":140,"y":100,"wires":[]},{"id":"a0d3fddf.d2b38","type":"ui_switch","z":"7f5e3dd.11d05c4","name":"Kitchen party time","label":"<b>Kitchen </b>party","tooltip":"On to allow joining","group":"58dc097d.1c35f8","order":2,"width":0,"height":0,"passthru":false,"decouple":"false","topic":"","style":"","onvalue":"on","onvalueType":"str","onicon":"","oncolor":"","offvalue":"off","offvalueType":"str","officon":"","offcolor":"","x":290,"y":220,"wires":[["2be31cb5.ec8024"]]},{"id":"2be31cb5.ec8024","type":"switch","z":"7f5e3dd.11d05c4","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":450,"y":220,"wires":[["ec25cb9b.b8ef18"],["335c4bea.02a1e4"]]},{"id":"ec25cb9b.b8ef18","type":"change","z":"7f5e3dd.11d05c4","name":"Open","rules":[{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"open","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":580,"y":200,"wires":[["63d16379.ed480c"]]},{"id":"335c4bea.02a1e4","type":"change","z":"7f5e3dd.11d05c4","name":"Close","rules":[{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"close","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":580,"y":240,"wires":[["63d16379.ed480c","7271f093.96bc9","40f16b0c.4da3b4"]]},{"id":"63d16379.ed480c","type":"q-gate","z":"7f5e3dd.11d05c4","name":"Dash Switch","controlTopic":"control","defaultState":"open","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","queueCmd":"queue","defaultCmd":"default","triggerCmd":"trigger","flushCmd":"flush","resetCmd":"reset","peekCmd":"","dropCmd":"","statusCmd":"","maxQueueLength":"100","keepNewest":false,"qToggle":false,"persist":true,"x":740,"y":220,"wires":[["10162c82.264263"]]},{"id":"10162c82.264263","type":"switch","z":"7f5e3dd.11d05c4","name":"","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":890,"y":220,"wires":[["3563948e.14618c","ced5be5e.bfeb2"],["3563948e.14618c"]]},{"id":"3563948e.14618c","type":"stoptimer-varidelay","z":"7f5e3dd.11d05c4","duration":"7","durationType":"num","units":"Minute","payloadtype":"num","payloadval":"0","name":"","reporting":"none","x":1160,"y":260,"wires":[["20c7f80c.43dd68"],[],[]]},{"id":"20c7f80c.43dd68","type":"sonos-universal","z":"7f5e3dd.11d05c4","confignode":"e7f03a53.241ce8","compatibilityMode":false,"command":"player.leave.group","state":"","stateType":"str","name":"Kitchen","x":1340,"y":260,"wires":[["2ba1c919.c218d6"]]},{"id":"2ff0be75.79bf92","type":"sonos-universal","z":"7f5e3dd.11d05c4","confignode":"e7f03a53.241ce8","compatibilityMode":false,"command":"player.join.group","state":"","stateType":"str","name":"Kitchen","x":1980,"y":220,"wires":[["df5172a2.6b87c"]]},{"id":"a184e75d.c5c878","type":"change","z":"7f5e3dd.11d05c4","name":"Join Office","rules":[{"t":"set","p":"payload","pt":"msg","to":"Office","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1830,"y":220,"wires":[["2ff0be75.79bf92"]]},{"id":"df5172a2.6b87c","type":"sonos-universal","z":"7f5e3dd.11d05c4","confignode":"fbea6094.43c19","compatibilityMode":false,"command":"player.get.volume","state":"","stateType":"str","name":"Office","x":2130,"y":220,"wires":[["55fa2657.091fb8"]]},{"id":"55fa2657.091fb8","type":"sonos-universal","z":"7f5e3dd.11d05c4","confignode":"e7f03a53.241ce8","compatibilityMode":false,"command":"player.set.volume","state":"","stateType":"str","name":"Kitchen","x":2420,"y":220,"wires":[["6902f9ca.a1b088"]]},{"id":"9f01982b.b61198","type":"sonos-universal","z":"7f5e3dd.11d05c4","confignode":"e7f03a53.241ce8","compatibilityMode":false,"command":"player.get.role","state":"","stateType":"str","name":"Kitchen","x":1140,"y":200,"wires":[["8ac02480.ed3f18"]]},{"id":"8ac02480.ed3f18","type":"switch","z":"7f5e3dd.11d05c4","name":"Check grouped?","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"joiner","vt":"str"},{"t":"eq","v":"coordinator","vt":"str"},{"t":"eq","v":"standalone","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":1320,"y":200,"wires":[["88905734.7f4b28"],[],["a184e75d.c5c878"]]},{"id":"40f16b0c.4da3b4","type":"sonos-universal","z":"7f5e3dd.11d05c4","confignode":"e7f03a53.241ce8","compatibilityMode":false,"command":"player.get.role","state":"","stateType":"str","name":"Kitchen","x":980,"y":340,"wires":[["7b04113a.5450e"]]},{"id":"7b04113a.5450e","type":"switch","z":"7f5e3dd.11d05c4","name":"Check grouped?","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"joiner","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":1160,"y":340,"wires":[["20c7f80c.43dd68"]]},{"id":"7271f093.96bc9","type":"delay","z":"7f5e3dd.11d05c4","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":955,"y":300,"wires":[["8f2e250d.2851d8"]],"l":false},{"id":"8f2e250d.2851d8","type":"change","z":"7f5e3dd.11d05c4","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"stop","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1015,"y":300,"wires":[["3563948e.14618c"]],"l":false},{"id":"497b11e.1861ff","type":"switch","z":"7f5e3dd.11d05c4","name":"Check Co-ordinator","property":"payload.coordinatorName","propertyType":"msg","rules":[{"t":"neq","v":"Office","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":1650,"y":180,"wires":[["a184e75d.c5c878"]]},{"id":"88905734.7f4b28","type":"sonos-universal","z":"7f5e3dd.11d05c4","confignode":"e7f03a53.241ce8","compatibilityMode":false,"command":"group.get.state","state":"","stateType":"str","name":"Kitchen","x":1480,"y":180,"wires":[["497b11e.1861ff"]]},{"id":"6902f9ca.a1b088","type":"change","z":"7f5e3dd.11d05c4","name":"","rules":[{"t":"set","p":"sonos_kitchen","pt":"flow","to":"joined","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":2535,"y":220,"wires":[[]],"l":false},{"id":"ced5be5e.bfeb2","type":"switch","z":"7f5e3dd.11d05c4","name":"","property":"sonos_kitchen","propertyType":"flow","rules":[{"t":"neq","v":"joined","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":1015,"y":200,"wires":[["9f01982b.b61198"]],"l":false,"info":"This switch is to stop the sonos speakers getting smashed by constant requests to join/check volume/check groups status, every time motion sensors change to active. "},{"id":"2ba1c919.c218d6","type":"change","z":"7f5e3dd.11d05c4","name":"","rules":[{"t":"set","p":"sonos_kitchen","pt":"flow","to":"standalone","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1475,"y":260,"wires":[[]],"l":false},{"id":"40c7c88f.02d9f8","type":"calculator","z":"7f5e3dd.11d05c4","name":"","inputMsgField":"payload","outputMsgField":"payload","operation":"sum","constant":"2","x":2270,"y":220,"wires":[[]]},{"id":"2120cd99.47cc12","type":"hubitat config","z":"","name":"Hubitat Coordinator","usetls":false,"host":"192.168.1.100","port":"80","appId":"1731","nodeRedServer":"http://192.168.1.90:1880","webhookPath":"/hubitat/webhook","autoRefresh":true,"useWebsocket":false},{"id":"b37b2cbb.28c06","type":"hubitat config","z":"","name":"Hubitat Client","usetls":false,"host":"192.168.1.217","port":"80","appId":"808","nodeRedServer":"http://192.168.1.90:1880","webhookPath":"/hubitatclient/webhook","autoRefresh":true,"useWebsocket":false},{"id":"58dc097d.1c35f8","type":"ui_group","z":"","name":"Sonos","tab":"1862e313.45ffad","order":7,"disp":true,"width":"4","collapse":false},{"id":"e7f03a53.241ce8","type":"sonos-config","z":"","name":"Sonos - Kitchen","serialnum":"B8-E9-37-2F-9C-9C:6","ipaddress":"192.168.1.47"},{"id":"fbea6094.43c19","type":"sonos-config","z":"","name":"Sonos - Office","serialnum":"B8-E9-37-2F-9C-48:7","ipaddress":"192.168.1.44"},{"id":"1862e313.45ffad","type":"ui_tab","z":"","name":"Mike","icon":"dashboard","disabled":false,"hidden":false}]

This one will check to see if the TV is already playing (my TV Sonos may already be playing TV). Also checks to see if the dash board switch Party Time TV is ON.

[{"id":"678d617a.02213","type":"comment","z":"7f5e3dd.11d05c4","name":"TV: slave, Office: master","info":"","x":130,"y":500,"wires":[]},{"id":"5c2b5e94.79a69","type":"switch","z":"7f5e3dd.11d05c4","name":"","property":"bool","propertyType":"msg","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":710,"y":580,"wires":[["da871b7.79190e8"],["50f4b803.9e8b08","eda4af02.f9c27"]]},{"id":"da871b7.79190e8","type":"change","z":"7f5e3dd.11d05c4","name":"Open","rules":[{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"open","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":990,"y":560,"wires":[["ffaeca6.3c1c638"]]},{"id":"50f4b803.9e8b08","type":"change","z":"7f5e3dd.11d05c4","name":"Close","rules":[{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"close","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":990,"y":600,"wires":[["ffaeca6.3c1c638"]]},{"id":"ffaeca6.3c1c638","type":"q-gate","z":"7f5e3dd.11d05c4","name":"Dash Switch","controlTopic":"control","defaultState":"open","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","queueCmd":"queue","defaultCmd":"default","triggerCmd":"trigger","flushCmd":"flush","resetCmd":"reset","peekCmd":"","dropCmd":"","statusCmd":"","maxQueueLength":"100","keepNewest":false,"qToggle":false,"persist":true,"x":1160,"y":560,"wires":[["4ffd9a22.97c464"]]},{"id":"4ffd9a22.97c464","type":"switch","z":"7f5e3dd.11d05c4","name":"","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":1300,"y":580,"wires":[["636faa47.6e89f4","4cda6840.280148"],["636faa47.6e89f4"]]},{"id":"636faa47.6e89f4","type":"stoptimer-varidelay","z":"7f5e3dd.11d05c4","duration":"7","durationType":"num","units":"Minute","payloadtype":"num","payloadval":"0","name":"","reporting":"none","x":1490,"y":620,"wires":[["a40dc311.9bbc8"],[],[]]},{"id":"a40dc311.9bbc8","type":"sonos-universal","z":"7f5e3dd.11d05c4","confignode":"b677af92.bb012","compatibilityMode":false,"command":"player.leave.group","state":"","stateType":"str","name":"TV","x":1660,"y":620,"wires":[["4b3c73b3.66141c"]]},{"id":"9676d8a2.932df8","type":"sonos-universal","z":"7f5e3dd.11d05c4","confignode":"b677af92.bb012","compatibilityMode":false,"command":"player.join.group","state":"","stateType":"str","name":"TV","x":2310,"y":560,"wires":[["79ce6f8c.f20b6"]]},{"id":"298d0438.c2802c","type":"change","z":"7f5e3dd.11d05c4","name":"Join Office","rules":[{"t":"set","p":"payload","pt":"msg","to":"Office","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":2170,"y":560,"wires":[["9676d8a2.932df8"]]},{"id":"79ce6f8c.f20b6","type":"sonos-universal","z":"7f5e3dd.11d05c4","confignode":"fbea6094.43c19","compatibilityMode":false,"command":"player.get.volume","state":"","stateType":"str","name":"Office","x":2490,"y":560,"wires":[["b9a03206.ec086"]]},{"id":"d96b8512.782198","type":"sonos-universal","z":"7f5e3dd.11d05c4","confignode":"b677af92.bb012","compatibilityMode":false,"command":"player.set.volume","state":"","stateType":"str","name":"TV","x":2910,"y":560,"wires":[["cd7d3c50.44f6"]]},{"id":"e7631e8f.a5e5c","type":"ui_switch","z":"7f5e3dd.11d05c4","name":"TV party time","label":"<b>TV</b> party","tooltip":"ON to allow joining","group":"58dc097d.1c35f8","order":1,"width":4,"height":1,"passthru":false,"decouple":"false","topic":"TV Party Time","style":"","onvalue":"on","onvalueType":"str","onicon":"","oncolor":"","offvalue":"off","offvalueType":"str","officon":"","offcolor":"","x":290,"y":580,"wires":[["5423c672.997e78"]]},{"id":"ff836d83.184ed","type":"hubitat device","z":"7f5e3dd.11d05c4","name":"MD - TV Room 2","server":"2120cd99.47cc12","deviceId":"21","attribute":"motion","sendEvent":true,"x":990,"y":500,"wires":[["ffaeca6.3c1c638"]]},{"id":"a2ff4f74.9b611","type":"hubitat device","z":"7f5e3dd.11d05c4","name":"MDChild -  TV","server":"b37b2cbb.28c06","deviceId":"17","attribute":"motion","sendEvent":true,"x":1010,"y":440,"wires":[["ffaeca6.3c1c638"]]},{"id":"22e8e500.06e84c","type":"hubitat device","z":"7f5e3dd.11d05c4","name":"TV - Downstairs TV","server":"b37b2cbb.28c06","deviceId":"96","attribute":"switch","sendEvent":true,"x":290,"y":640,"wires":[["5423c672.997e78"]]},{"id":"5421cda9.182a74","type":"sonos-universal","z":"7f5e3dd.11d05c4","confignode":"b677af92.bb012","compatibilityMode":false,"command":"player.get.role","state":"","stateType":"str","name":"TV","x":1330,"y":680,"wires":[["38f4ec9d.430884"]]},{"id":"38f4ec9d.430884","type":"switch","z":"7f5e3dd.11d05c4","name":"Check grouped?","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"joiner","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":1500,"y":680,"wires":[["a40dc311.9bbc8"]]},{"id":"5423c672.997e78","type":"and-gate","z":"7f5e3dd.11d05c4","name":"TV OFF and Switch ON","rules":[{"t":"eq","v":"on","vt":"str","propertyType":"msg","property":"payload","topic":"TV Party Time"},{"t":"eq","v":"off","vt":"str","propertyType":"msg","property":"payload.value","topic":"TV - Downstairs TV"}],"outputTopic":"Control","gateType":"and","emitOnlyIfTrue":false,"x":510,"y":580,"wires":[["5c2b5e94.79a69"]]},{"id":"eda4af02.f9c27","type":"link out","z":"7f5e3dd.11d05c4","name":"","links":["ab2d2025.a8fe3"],"x":815,"y":660,"wires":[]},{"id":"ab2d2025.a8fe3","type":"link in","z":"7f5e3dd.11d05c4","name":"","links":["eda4af02.f9c27"],"x":1215,"y":660,"wires":[["5421cda9.182a74","6f27d6af.09fdf8"]]},{"id":"6f27d6af.09fdf8","type":"delay","z":"7f5e3dd.11d05c4","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1295,"y":640,"wires":[["7cf6f91a.b3b078"]],"l":false},{"id":"7cf6f91a.b3b078","type":"change","z":"7f5e3dd.11d05c4","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"stop","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1355,"y":640,"wires":[["636faa47.6e89f4"]],"l":false},{"id":"76a1a8cb.6a7b68","type":"calculator","z":"7f5e3dd.11d05c4","name":"","inputMsgField":"payload","outputMsgField":"payload","operation":"sub","constant":"4","x":2760,"y":540,"wires":[["d96b8512.782198"]]},{"id":"cd7d3c50.44f6","type":"change","z":"7f5e3dd.11d05c4","name":"","rules":[{"t":"set","p":"sonos_tv","pt":"flow","to":"joined","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":3015,"y":560,"wires":[[]],"l":false},{"id":"ec3b4015.e350c","type":"sonos-universal","z":"7f5e3dd.11d05c4","confignode":"b677af92.bb012","compatibilityMode":false,"command":"player.get.role","state":"","stateType":"str","name":"TV","x":1490,"y":520,"wires":[["211bcc01.9a25e4"]]},{"id":"211bcc01.9a25e4","type":"switch","z":"7f5e3dd.11d05c4","name":"Check grouped?","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"joiner","vt":"str"},{"t":"eq","v":"coordinator","vt":"str"},{"t":"eq","v":"standalone","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":1680,"y":520,"wires":[["debefae5.18ad48"],[],["298d0438.c2802c"]]},{"id":"8dded682.6e9938","type":"switch","z":"7f5e3dd.11d05c4","name":"Check Co-ordinator","property":"payload.coordinatorName","propertyType":"msg","rules":[{"t":"neq","v":"Office","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":2010,"y":500,"wires":[["298d0438.c2802c"]]},{"id":"debefae5.18ad48","type":"sonos-universal","z":"7f5e3dd.11d05c4","confignode":"b677af92.bb012","compatibilityMode":false,"command":"group.get.state","state":"","stateType":"str","name":"TV","x":1830,"y":500,"wires":[["8dded682.6e9938"]]},{"id":"4cda6840.280148","type":"switch","z":"7f5e3dd.11d05c4","name":"","property":"sonos_tv","propertyType":"flow","rules":[{"t":"neq","v":"joined","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":1395,"y":520,"wires":[["ec3b4015.e350c"]],"l":false,"info":"This switch is to stop the sonos speakers getting smashed by constant requests to join/check volume/check groups status, every time motion sensors change to active. "},{"id":"4b3c73b3.66141c","type":"change","z":"7f5e3dd.11d05c4","name":"","rules":[{"t":"set","p":"sonos_tv","pt":"flow","to":"standalone","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1775,"y":620,"wires":[[]],"l":false},{"id":"b9a03206.ec086","type":"delay","z":"7f5e3dd.11d05c4","name":"","pauseType":"delay","timeout":"100","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":2575,"y":560,"wires":[["aa7e8213.75447"]],"l":false},{"id":"aa7e8213.75447","type":"switch","z":"7f5e3dd.11d05c4","name":"","property":"payload","propertyType":"msg","rules":[{"t":"gte","v":"7","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":2635,"y":560,"wires":[["76a1a8cb.6a7b68"],["d96b8512.782198"]],"l":false},{"id":"e28e1f43.efadd","type":"inject","z":"7f5e3dd.11d05c4","name":"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":135,"y":620,"wires":[["e7631e8f.a5e5c","22e8e500.06e84c"]],"l":false},{"id":"b677af92.bb012","type":"sonos-config","z":"","name":"Sonos - TV","serialnum":"5c:aa:fd:1e:30:cd","ipaddress":"192.168.1.36"},{"id":"fbea6094.43c19","type":"sonos-config","z":"","name":"Sonos - Office","serialnum":"B8-E9-37-2F-9C-48:7","ipaddress":"192.168.1.44"},{"id":"58dc097d.1c35f8","type":"ui_group","z":"","name":"Sonos","tab":"1862e313.45ffad","order":7,"disp":true,"width":"4","collapse":false},{"id":"2120cd99.47cc12","type":"hubitat config","z":"","name":"Hubitat Coordinator","usetls":false,"host":"192.168.1.100","port":"80","appId":"1731","nodeRedServer":"http://192.168.1.90:1880","webhookPath":"/hubitat/webhook","autoRefresh":true,"useWebsocket":false},{"id":"b37b2cbb.28c06","type":"hubitat config","z":"","name":"Hubitat Client","usetls":false,"host":"192.168.1.217","port":"80","appId":"808","nodeRedServer":"http://192.168.1.90:1880","webhookPath":"/hubitatclient/webhook","autoRefresh":true,"useWebsocket":false},{"id":"1862e313.45ffad","type":"ui_tab","z":"","name":"Mike","icon":"dashboard","disabled":false,"hidden":false}]

This one has no motion sensors, just a switch in the dash, for my Sonos Move, which moves in and out of rooms. So, just a dash switch for activation.

[{"id":"d53a5f18.dc60b","type":"ui_switch","z":"7f5e3dd.11d05c4","name":"MOVE party time","label":"<b>Move</b> party","tooltip":"On to allow joining","group":"58dc097d.1c35f8","order":3,"width":0,"height":0,"passthru":false,"decouple":"false","topic":"","style":"","onvalue":"on","onvalueType":"str","onicon":"","oncolor":"","offvalue":"off","offvalueType":"str","officon":"","offcolor":"","x":350,"y":1120,"wires":[["ed2358b0.a737e8"]]},{"id":"65d54dbe.fa5b64","type":"sonos-universal","z":"7f5e3dd.11d05c4","confignode":"c5ce9036.67dea","compatibilityMode":false,"command":"player.leave.group","state":"","stateType":"str","name":"Move","x":690,"y":1140,"wires":[[]]},{"id":"ed2358b0.a737e8","type":"switch","z":"7f5e3dd.11d05c4","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":530,"y":1120,"wires":[["c25dd54f.b26878"],["65d54dbe.fa5b64"]]},{"id":"88c4dc00.dc55b","type":"sonos-universal","z":"7f5e3dd.11d05c4","confignode":"c5ce9036.67dea","compatibilityMode":false,"command":"player.join.group","state":"","stateType":"str","name":"Move","x":870,"y":1100,"wires":[["55bf743e.f6f09c"]]},{"id":"c25dd54f.b26878","type":"change","z":"7f5e3dd.11d05c4","name":"Join Office","rules":[{"t":"set","p":"payload","pt":"msg","to":"Office","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":710,"y":1100,"wires":[["88c4dc00.dc55b"]]},{"id":"55bf743e.f6f09c","type":"sonos-universal","z":"7f5e3dd.11d05c4","confignode":"fbea6094.43c19","compatibilityMode":false,"command":"group.get.volume","state":"","stateType":"str","name":"Office","x":1010,"y":1100,"wires":[["ab529a79.b58f38"]]},{"id":"ab529a79.b58f38","type":"sonos-universal","z":"7f5e3dd.11d05c4","confignode":"c5ce9036.67dea","compatibilityMode":false,"command":"player.set.volume","state":"","stateType":"str","name":"Move","x":1170,"y":1100,"wires":[[]]},{"id":"58dc097d.1c35f8","type":"ui_group","z":"","name":"Sonos","tab":"1862e313.45ffad","order":7,"disp":true,"width":"4","collapse":false},{"id":"c5ce9036.67dea","type":"sonos-config","z":"","name":"Sonos Move","serialnum":"48:a6:b8:e0:66:90","ipaddress":"192.168.1.89"},{"id":"fbea6094.43c19","type":"sonos-config","z":"","name":"Sonos - Office","serialnum":"B8-E9-37-2F-9C-48:7","ipaddress":"192.168.1.44"},{"id":"1862e313.45ffad","type":"ui_tab","z":"","name":"Mike","icon":"dashboard","disabled":false,"hidden":false}]
4 Likes

Very cool. I like the idea of dynamic allocation of devices to a music group like this. Nice. I guess the same could be achieved for Chromecast or Google Home devices instead of Sonos. I only have a couple of Sonos but more GH devices dotted around the house.

@aaiyar hey just wanted to say thanks for the fix.

@leeonestop

One more change. Change both the 30 second delay nodes to 2 minute delay nodes. The SleepNumber cloud API is rate limited, and hitting it every 30 seconds is too quick. Even 1 minute is too fast. But 2 minutes seems to work fine.

Ok will do thanks

1 Like

For the Alexa Routine, what do I set for the "When this happens" in the routine? Do I set it as "Alexa, word/phrase"? Because if I do this then it will not work unless I say it exactly.

Yes and you are at the mercy of how particular Alexa is in deciding if what she heard is close enough to the trigger phrase in your dummy routine.

.
Fun little flow I put together tonight to pull data from the Trakt.TV API


.

I use the first row of nodes to send a telegram message to myself that has the link and the device code

Once the code is entered there, Node-RED will pull the generated token and that is good for 3 months from that point. So obviously I am using the persistent storage option for my flow variables to store that to survive reboots. Setting that up is the only thing special needed.

I was thinking of storing the date the token was generated and checking that once a day and if it's close to expiring shoot off that message to Telegram to renew the token.
.

An example of what to do with the data retrieved.

2 Likes

How I check for battery sensors still being alive:


I have separate flows for each type.

Code

[{"id":"ff5ad7f6.3f46a8","type":"pushover api","z":"f1e3446e.38da88","keys":"2a52b42c.7e9f0c","title":"","name":"Push: No Response","x":1060,"y":480,"wires":[]},{"id":"d087ae9.ce4895","type":"string","z":"f1e3446e.38da88","name":"","methods":[{"name":"append","params":[{"type":"str","value":" has not responded in 24 Hours!"}]}],"prop":"topic","propout":"payload","object":"msg","objectout":"msg","x":890,"y":480,"wires":[["ff5ad7f6.3f46a8"]]},{"id":"11491c90.a694f3","type":"stoptimer-varidelay","z":"f1e3446e.38da88","duration":"24","durationType":"num","units":"Hour","payloadtype":"num","payloadval":"0","name":"","reporting":"last_minute_seconds","x":520,"y":100,"wires":[["d087ae9.ce4895","928ab9ea.00d278"],[],[]]},{"id":"928ab9ea.00d278","type":"hubitat device","z":"f1e3446e.38da88","name":"Becca Room: Window","server":"f17566a9.c052b8","deviceId":"2554","attribute":"","sendEvent":true,"x":200,"y":100,"wires":[["11491c90.a694f3"]]},{"id":"2a52b42c.7e9f0c","type":"pushover-keys","name":""},{"id":"f17566a9.c052b8","type":"hubitat config","name":"","usetls":false,"host":"192.168.1.50","port":"80","appId":"3424","nodeRedServer":"http://192.168.1.50:1880","webhookPath":"/hubitat/webhook","autoRefresh":true,"useWebsocket":false}]

4 Likes

If you use it, have you ever considered pulling the data from Sonarr instead? Trakt has been having significant performance issues lately and they're making all kinds of changes to their API. I find 1 of 3 times I try to hit trakt.tv lately the site is down. Sonarr would keep things local.

I had never heard of that site before.

I've been using Trakt for years, even subscribed to it, I'll keep using either their RSS feed or API until I have issues with it (which has been zero to this point)

TheTVDB is another super popular site that seems to be crumbling under traffic, as it's now $12 a year to use their API, that for sure used to be free up until recently.

Sonarr isn't really a site. It's an application used for automating downloads/naming/moving/sorting/etc of tv series. It pulls its data from TVDB. There's also Radarr for movies and Lidarr for music. All are commonly used by cord cutters and have local api's since their applications run within your system.

I use trakt to keep watched status in sync between 2 Emby servers and a Plex server. But with the issues with their site, I've been using Simkl.com for this the past few months.

Okay so this is a stab at trying to get generic pseudo HE grouping in NR... wanted to put this out there in case someone was interested. This will work across multiple hubs/maker instances but for now some "hard-coding" (manual node-editing) is required.

nr221

Basic installation..

  • import subflows.
  • delete erroneous HE hub configs.
  • You will have to manually edit the HubGrpCommand, HubGrpEvents, HubGrpRequest nodes.
    • Come up with a "hub id" for each hub. Can be any alphanum string at this point. deviceIds take the form [hubId]/[deviceId] and are separated by commas.
    • Edit the HubGroup subflows and modify the existing nodes with your hub config and "hub id"' info.

Usage Notes:

  • The basic idea is to set the deviceId property with all the HE node deviceIds you want to group separated by commas and in the form hubId/deviceId1,hubId/deviceId2... etc. Then use DevGrpEvent and DevGrpCommand subflow nodes like you would with the HE Device and Command Nodes.
  • There are lots of properties of the nodes you can play around with.. specifically the "ACTION" properties - you can group "switches" (default) together or "contact sensors" etc - just have to define:
    • TOPIC - The "name" of the group used in various messages etc.
    • TYPE - "switch","contact" etc
    • ACTIONS - "on/off","open/closed" etc
    • When the event should fire using TYPE = "switch" / ACTIONS = "on/off" as an example
      • ALL_Action1 refers to the "on" in "on/off" in the ACTIONS property while ALL_Action2 refers to the "off" part.
      • Setting ALL_Action1 to true fires "on" events when all devices are "on"
      • Setting ALL_Action2 to true fires "off" events when all devices are "off"
      • If both ALL_Action1 & ALL_Action2 are set to true then when some switches are turned on or off the state is considered "pending" and no events will fire.
      • Setting both ALL_Action1 and ALL_Action2 to false is "undefined" because any switch "on" or "off" would never trigger an action.
    • SEND_ALL_EVENTS generates messages based on incoming events from the defined group.
    • RETURN_ALL_MSGS returns the payload.value of the triggered individual device instead of the accumulated group. Good for door open alerts etc (when one or more door is open).

WARNING!!!

  • This is still a work in progress so expect many bugs/headaches etc - use at your own risk.
  • There are probably a 1000 much easier ways to do this.. but I am sadly prone to greatly over-engineering things.
  • I haven't tested non "switch" TYPE groupings.. but as long as the responses are binary in nature (on/off, open/closed, active/inactive) they should work.
  • The "groups" are simple predefined aggregations of the same type of device. No mixing of devices allowed.
  • Importing the following subflows will add a bunch of HE hub configs you will have to remove.
  • There are no instructions on node usage yet so kind of have to wing it for now.

Here ya go:

Groupings in NR - this is the original posting

[{"id":"4e1e6fde.a5bbf","type":"subflow","name":"HubGrpCommand","info":"","category":"","in":[{"x":40,"y":40,"wires":[{"id":"b47983a7.7b5f7"}]}],"out":[{"x":1220,"y":180,"wires":[{"id":"7c32f9e4.9fd4f8","port":0},{"id":"e076de00.f88b6","port":0},{"id":"320acf5d.6b427","port":0},{"id":"ef3ddba.1057c28","port":0},{"id":"b706dd3b.cf87a","port":0},{"id":"47e952f6.d8d37c","port":0}]}],"env":[],"color":"#DDAA99"},{"id":"fb597717.109328","type":"hubitat command","z":"4e1e6fde.a5bbf","name":"Control Hub / CTRL","server":"bc9b2ba4.2458c8","deviceId":"","command":"","commandArgs":"","x":510,"y":60,"wires":[["7c32f9e4.9fd4f8"]]},{"id":"2a44d5ee.875b7a","type":"hubitat command","z":"4e1e6fde.a5bbf","name":"Main Hub / OMNF","server":"5664ca29.3af904","deviceId":"","command":"","commandArgs":"","x":510,"y":120,"wires":[["e076de00.f88b6"]]},{"id":"448a391d.a21278","type":"hubitat command","z":"4e1e6fde.a5bbf","name":"Main Hub - Zigbee / OZIG","server":"623daead.b1d2b","deviceId":"","command":"","commandArgs":"","x":530,"y":180,"wires":[["320acf5d.6b427"]]},{"id":"e719a313.c7d78","type":"hubitat command","z":"4e1e6fde.a5bbf","name":"Main Hub - Zwave / OZWA","server":"7631dfd4.02862","deviceId":"","command":"","commandArgs":"","x":540,"y":240,"wires":[["ef3ddba.1057c28"]]},{"id":"e65b768b.ab1f68","type":"hubitat command","z":"4e1e6fde.a5bbf","name":"Main Hub C7 / MNZW","server":"106ae29b.a1d83d","deviceId":"","command":"","commandArgs":"","x":520,"y":360,"wires":[["47e952f6.d8d37c"]]},{"id":"ddcc8d55.8b128","type":"hubitat command","z":"4e1e6fde.a5bbf","name":"Upstairs Hub / OUPS","server":"925818a7.4a4018","deviceId":"","command":"","commandArgs":"","x":520,"y":300,"wires":[["b706dd3b.cf87a"]]},{"id":"7c32f9e4.9fd4f8","type":"change","z":"4e1e6fde.a5bbf","name":"hub = CTRL","rules":[{"t":"set","p":"hub","pt":"msg","to":"CTRL","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":830,"y":60,"wires":[[]]},{"id":"e076de00.f88b6","type":"change","z":"4e1e6fde.a5bbf","name":"hub = OMNF","rules":[{"t":"set","p":"hub","pt":"msg","to":"OMNF","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":830,"y":120,"wires":[[]]},{"id":"320acf5d.6b427","type":"change","z":"4e1e6fde.a5bbf","name":"hub = OZIG","rules":[{"t":"set","p":"hub","pt":"msg","to":"OZIG","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":830,"y":180,"wires":[[]]},{"id":"ef3ddba.1057c28","type":"change","z":"4e1e6fde.a5bbf","name":"hub = OZWA","rules":[{"t":"set","p":"hub","pt":"msg","to":"OZWA","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":830,"y":240,"wires":[[]]},{"id":"47e952f6.d8d37c","type":"change","z":"4e1e6fde.a5bbf","name":"hub = MNZW","rules":[{"t":"set","p":"hub","pt":"msg","to":"MNZW","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":830,"y":360,"wires":[[]]},{"id":"b47983a7.7b5f7","type":"switch","z":"4e1e6fde.a5bbf","name":"hub = CTRL \\n hub = OMNF \\n hub = OZIG \\n hub = OZWA \\n hub = OUPS \\n hub = MNZW","property":"hub","propertyType":"msg","rules":[{"t":"eq","v":"CTRL","vt":"str"},{"t":"eq","v":"OMNF","vt":"str"},{"t":"eq","v":"OZIG","vt":"str"},{"t":"eq","v":"OZWA","vt":"str"},{"t":"eq","v":"OUPS","vt":"str"},{"t":"eq","v":"MNZW","vt":"str"}],"checkall":"true","repair":false,"outputs":6,"x":190,"y":200,"wires":[["fb597717.109328"],["2a44d5ee.875b7a"],["448a391d.a21278"],["e719a313.c7d78"],["ddcc8d55.8b128"],["e65b768b.ab1f68"]]},{"id":"b706dd3b.cf87a","type":"change","z":"4e1e6fde.a5bbf","name":"hub = OUPS","rules":[{"t":"set","p":"hub","pt":"msg","to":"OUPS","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":830,"y":300,"wires":[[]]},{"id":"5f0d4ee4.54595","type":"subflow","name":"DevGrpCommand","info":"","category":"","in":[{"x":20,"y":80,"wires":[{"id":"12bc27d.a7615d8"}]}],"out":[{"x":1640,"y":80,"wires":[{"id":"5033935.2de806c","port":0}]}],"env":[{"name":"TOPIC","type":"str","value":"swGroupName"},{"name":"DEVICES","type":"str","value":""},{"name":"TYPE","type":"str","value":"switch"}],"color":"#DDAA99","status":{"x":1640,"y":220,"wires":[{"id":"eb697deb.09311","port":0}]}},{"id":"12bc27d.a7615d8","type":"switch","z":"5f0d4ee4.54595","name":"does msg.command exist \\n and is on/off?","property":"$exists(command) ? \t    ($contains(command,/(on)|(off)/) ? true : false )\t: false\t\t","propertyType":"jsonata","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":210,"y":80,"wires":[["5716210f.80d6f"],[]]},{"id":"fd492199.dfaea","type":"join","z":"5f0d4ee4.54595","name":"","mode":"auto","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":650,"y":140,"wires":[["5033935.2de806c"]]},{"id":"5033935.2de806c","type":"change","z":"5f0d4ee4.54595","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload_send","tot":"msg"},{"t":"delete","p":"deviceId","pt":"msg"},{"t":"delete","p":"payload_send","pt":"msg"},{"t":"delete","p":"response","pt":"msg"},{"t":"set","p":"topic","pt":"msg","to":"TOPIC","tot":"env"}],"action":"","property":"","from":"","to":"","reg":false,"x":900,"y":140,"wires":[["eb697deb.09311"]]},{"id":"eb697deb.09311","type":"change","z":"5f0d4ee4.54595","name":"payload = payload.value","rules":[{"t":"set","p":"payload","pt":"msg","to":"\t{\t\"fill\": (payload.value = \"on\" ? \"green\" : (payload.value = \"off\" ? \"blue\" : \"black\")),\t\"shape\":\"dot\",\t\"text\":'Command: \"' & payload.value & '\"'\t}\t","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1410,"y":220,"wires":[[]]},{"id":"caefe429.207cc8","type":"subflow:4e1e6fde.a5bbf","z":"5f0d4ee4.54595","name":"","env":[],"x":450,"y":140,"wires":[["fd492199.dfaea"]]},{"id":"5716210f.80d6f","type":"function","z":"5f0d4ee4.54595","name":"Gen related device msgs","func":"// walk thru device list and set commands\ndevList = env.get(\"DEVICES\");\ndevices = devList.split(\",\");\ntopic = env.get(\"TOPIC\");\nlen = devices.length;\n\nvar icnt = 0;\ndevices.forEach( o => {\n        var dev = o.split(\"/\");\n        var hub = dev[0];\n        var devId = dev[1];\n\n        var parts = {\n            \"id\":topic,\n            \"index\": icnt,\n            \"count\": len,\n            \"type\":\"object\",\n            \"ch\":\"\",\n            \"key\": o,\n            \"len\":\"\"\n        }\n\n        var newPayld = {\n            \"name\": \"switch\",\n            \"value\": msg.command,\n            \"displayName\": topic,\n            \"deviceId\": devList,\n            \"descriptionText\": topic,\n            \"unit\": null,\n            \"type\": null,\n            \"data\": null\n        };\n\n        icnt++;\n        msg.parts = parts;\n        msg.deviceId = devId;\n        msg.payload = {\"deviceId\": devId};\n        msg.payload_send = newPayld;\n        msg.hub = hub;\n        \n        //node.warn(o)\n\n        node.send(msg);\n    }\n);\n\n\n\nreturn;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":470,"y":80,"wires":[["caefe429.207cc8"]]},{"id":"9e28a145.80b4c","type":"subflow","name":"HubGrpRequest","info":"","category":"","in":[{"x":80,"y":200,"wires":[{"id":"8ef7fcff.46751"}]}],"out":[{"x":1140,"y":200,"wires":[{"id":"9abab016.1391","port":0},{"id":"ec167371.9e589","port":0},{"id":"40eaa66d.4bd218","port":0},{"id":"ef08a287.f93b4","port":0},{"id":"368409fd.864856","port":0},{"id":"ee11f083.f9355","port":0}]}],"env":[],"color":"#DDAA99"},{"id":"9abab016.1391","type":"change","z":"9e28a145.80b4c","name":"hub = CTRL","rules":[{"t":"set","p":"hub","pt":"msg","to":"CTRL","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":850,"y":60,"wires":[[]]},{"id":"ec167371.9e589","type":"change","z":"9e28a145.80b4c","name":"hub = OMNF","rules":[{"t":"set","p":"hub","pt":"msg","to":"OMNF","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":850,"y":120,"wires":[[]]},{"id":"40eaa66d.4bd218","type":"change","z":"9e28a145.80b4c","name":"hub = OZIG","rules":[{"t":"set","p":"hub","pt":"msg","to":"OZIG","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":850,"y":180,"wires":[[]]},{"id":"ef08a287.f93b4","type":"change","z":"9e28a145.80b4c","name":"hub = OZWA","rules":[{"t":"set","p":"hub","pt":"msg","to":"OZWA","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":850,"y":240,"wires":[[]]},{"id":"ee11f083.f9355","type":"change","z":"9e28a145.80b4c","name":"hub = MNZW","rules":[{"t":"set","p":"hub","pt":"msg","to":"MNZW","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":850,"y":360,"wires":[[]]},{"id":"1f8cc23e.0b944e","type":"hubitat request","z":"9e28a145.80b4c","name":"Control Hub / CTRL","server":"bc9b2ba4.2458c8","path":"","x":570,"y":60,"wires":[["9abab016.1391"]]},{"id":"8ef7fcff.46751","type":"switch","z":"9e28a145.80b4c","name":"hub = CTRL \\n hub = OMNF \\n hub = OZIG \\n hub = OZWA \\n hub = OUPS \\n hub = MNZW","property":"hub","propertyType":"msg","rules":[{"t":"eq","v":"CTRL","vt":"str"},{"t":"eq","v":"OMNF","vt":"str"},{"t":"eq","v":"OZIG","vt":"str"},{"t":"eq","v":"OZWA","vt":"str"},{"t":"eq","v":"OUPS","vt":"str"},{"t":"eq","v":"MNZW","vt":"str"}],"checkall":"true","repair":false,"outputs":6,"x":290,"y":200,"wires":[["1f8cc23e.0b944e"],["ccd2f8bb.864ac8"],["c875db14.d98708"],["d62999a5.474738"],["ee51458c.5f4338"],["1ef39202.40cbbe"]]},{"id":"ccd2f8bb.864ac8","type":"hubitat request","z":"9e28a145.80b4c","name":"Main Hub / OMNF","server":"5664ca29.3af904","path":"","x":570,"y":120,"wires":[["ec167371.9e589"]]},{"id":"c875db14.d98708","type":"hubitat request","z":"9e28a145.80b4c","name":"Main Hub - Zigbee / OZIG","server":"623daead.b1d2b","path":"","x":590,"y":180,"wires":[["40eaa66d.4bd218"]]},{"id":"d62999a5.474738","type":"hubitat request","z":"9e28a145.80b4c","name":"Main Hub - Zwave / OZWA","server":"7631dfd4.02862","path":"","x":600,"y":240,"wires":[["ef08a287.f93b4"]]},{"id":"1ef39202.40cbbe","type":"hubitat request","z":"9e28a145.80b4c","name":"Main Hub C7 / MNZW","server":"106ae29b.a1d83d","path":"","x":580,"y":360,"wires":[["ee11f083.f9355"]]},{"id":"368409fd.864856","type":"change","z":"9e28a145.80b4c","name":"hub = OUPS","rules":[{"t":"set","p":"hub","pt":"msg","to":"OUPS","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":850,"y":300,"wires":[[]]},{"id":"ee51458c.5f4338","type":"hubitat request","z":"9e28a145.80b4c","name":"Upstairs Hub / OUPS","server":"925818a7.4a4018","path":"","x":580,"y":300,"wires":[["368409fd.864856"]]},{"id":"925818a7.4a4018","type":"hubitat config","name":"Upstairs Hub","usetls":false,"host":"0.0.0.0","port":"80","appId":"000","nodeRedServer":"http://0.0.0.0:1880","webhookPath":"/hubitat/webhook_upstairs","autoRefresh":true,"useWebsocket":false},{"id":"52da5ceb.f5efa4","type":"subflow","name":"HubGrpEvents","info":"","category":"","in":[],"out":[{"x":940,"y":180,"wires":[{"id":"fecb2a55.280378","port":0},{"id":"190e2933.bc97c7","port":0},{"id":"7f4e9570.890b4c","port":0},{"id":"8f1321f9.9cb4b","port":0},{"id":"fb90e9a9.67a1a8","port":0}]}],"env":[],"color":"#DDAA99"},{"id":"5ee947d2.aac928","type":"hubitat event","z":"52da5ceb.f5efa4","name":"Control Hub - CTRL","server":"bc9b2ba4.2458c8","x":190,"y":80,"wires":[["fecb2a55.280378"]]},{"id":"dd1d273.772d9d8","type":"hubitat event","z":"52da5ceb.f5efa4","name":"Main Hub / OMNF","server":"5664ca29.3af904","x":190,"y":140,"wires":[["190e2933.bc97c7"]]},{"id":"da0c1a72.241788","type":"hubitat event","z":"52da5ceb.f5efa4","name":"Main Hub - Zigbee / OZIG","server":"623daead.b1d2b","x":210,"y":200,"wires":[["7f4e9570.890b4c"]]},{"id":"226988d4.2fbc28","type":"hubitat event","z":"52da5ceb.f5efa4","name":"Main Hub - Zwave / OZWA","server":"7631dfd4.02862","x":210,"y":260,"wires":[["8f1321f9.9cb4b"]]},{"id":"2dada7ec.57be98","type":"hubitat event","z":"52da5ceb.f5efa4","name":"Main Hub C7 / MNZW","server":"106ae29b.a1d83d","x":200,"y":320,"wires":[["fb90e9a9.67a1a8"]]},{"id":"fecb2a55.280378","type":"change","z":"52da5ceb.f5efa4","name":"hub = CTRL","rules":[{"t":"set","p":"hub","pt":"msg","to":"CTRL","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":80,"wires":[[]]},{"id":"190e2933.bc97c7","type":"change","z":"52da5ceb.f5efa4","name":"hub = OMNF","rules":[{"t":"set","p":"hub","pt":"msg","to":"OMNF","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":140,"wires":[[]]},{"id":"7f4e9570.890b4c","type":"change","z":"52da5ceb.f5efa4","name":"hub = OZIG","rules":[{"t":"set","p":"hub","pt":"msg","to":"OZIG","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":200,"wires":[[]]},{"id":"8f1321f9.9cb4b","type":"change","z":"52da5ceb.f5efa4","name":"hub = OZWA","rules":[{"t":"set","p":"hub","pt":"msg","to":"OZWA","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":260,"wires":[[]]},{"id":"fb90e9a9.67a1a8","type":"change","z":"52da5ceb.f5efa4","name":"hub = MNZW","rules":[{"t":"set","p":"hub","pt":"msg","to":"MNZW","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":320,"wires":[[]]},{"id":"bc9b2ba4.2458c8","type":"hubitat config","name":"Control Hub","usetls":false,"host":"0.0.0.0","port":"80","appId":"000","nodeRedServer":"http://0.0.0.0:1880","webhookPath":"/hubitat/webhook_control","autoRefresh":false,"useWebsocket":false},{"id":"5664ca29.3af904","type":"hubitat config","name":"Main Hub","usetls":false,"host":"0.0.0.0","port":"80","appId":"000","nodeRedServer":"http://0.0.0.0:1880","webhookPath":"/hubitat/webhook","autoRefresh":true,"useWebsocket":false},{"id":"623daead.b1d2b","type":"hubitat config","name":"Main Hub - Zigbee","usetls":false,"host":"0.0.0.0","port":"80","appId":"000","nodeRedServer":"http://0.0.0.0:1880","webhookPath":"/hubitat/webhook_main_zigbee","autoRefresh":true,"useWebsocket":false},{"id":"7631dfd4.02862","type":"hubitat config","name":"Main Hub - Zwave","usetls":false,"host":"0.0.0.0","port":"80","appId":"000","nodeRedServer":"http://0.0.0.0:1880","webhookPath":"/hubitat/webhook_main_zwave","autoRefresh":true,"useWebsocket":false},{"id":"106ae29b.a1d83d","type":"hubitat config","name":"Main Hub C7","usetls":false,"host":"0.0.0.0","port":"80","appId":"000","nodeRedServer":"http://0.0.0.0:1880","webhookPath":"/hubitat/webhook_c7","autoRefresh":true,"useWebsocket":false},{"id":"7e71de96.77727","type":"subflow","name":"DevGrpEvent","info":"","category":"","in":[{"x":60,"y":120,"wires":[{"id":"2feace6b.d14dc2"}]}],"out":[{"x":1720,"y":200,"wires":[{"id":"db3390b.b70b57","port":0},{"id":"ee37dbfb.f47708","port":0}]},{"x":1720,"y":280,"wires":[{"id":"26ad91b7.ae866e","port":0}]}],"env":[{"name":"TOPIC","type":"str","value":"swGroupName"},{"name":"DEVICES","type":"str","value":""},{"name":"TYPE","type":"str","value":"switch"},{"name":"ACTIONS","type":"str","value":"on/off"},{"name":"ALL_ACTION1","type":"bool","value":"true"},{"name":"ALL_ACTION2","type":"bool","value":"true"},{"name":"SEND_EVENTS","type":"bool","value":"true"}],"color":"#DDAA99","status":{"x":1720,"y":360,"wires":[{"id":"26ad91b7.ae866e","port":0}]}},{"id":"fb5a0d32.35fce","type":"switch","z":"7e71de96.77727","name":"does event match specified deviceId?","property":"DEVICES","propertyType":"env","rules":[{"t":"cont","v":"hub & \"/\" & payload.deviceId","vt":"jsonata"}],"checkall":"true","repair":false,"outputs":1,"x":1070,"y":40,"wires":[["81abc8d5.998a58"]]},{"id":"778ec673.85ac28","type":"function","z":"7e71de96.77727","name":"Gen related device msgs","func":"// walk thru device list and set commands\ndevices = env.get(\"DEVICES\").split(\",\");\ntopic = env.get(\"TOPIC\");\nlen = devices.length;\nflow.set(\"State_MAX\", len);\n\n\nvar icnt = 0;\ndevices.forEach( o => {\n        var dev = o.split(\"/\");\n        var hub = dev[0];\n        var device = dev[1];\n        var path = \"/devices/\" + device;\n        var parts = {\n            \"id\":topic,\n            \"index\": icnt,\n            \"count\": len,\n            \"type\":\"object\",\n            \"ch\":\"\",\n            \"key\": o,\n            \"len\":\"\"\n        }\n        \n        icnt++;\n        msg.topic = topic;\n        msg.path = path;\n        msg.parts = parts;\n        msg.hub = hub\n\n        \n        node.send(msg);\n    }\n);\n\n\n\nreturn;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":150,"y":220,"wires":[["61c08ebe.0a8ba"]]},{"id":"61c08ebe.0a8ba","type":"delay","z":"7e71de96.77727","name":"","pauseType":"random","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"50","randomUnits":"milliseconds","drop":false,"x":360,"y":220,"wires":[["836e4fce.3b2e"]]},{"id":"c9807839.b005f8","type":"join","z":"7e71de96.77727","name":"","mode":"auto","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":970,"y":220,"wires":[["392ba79a.a06c58"]]},{"id":"81abc8d5.998a58","type":"change","z":"7e71de96.77727","name":"Initialize flow vars","rules":[{"t":"set","p":"State_1","pt":"flow","to":"0","tot":"jsonata"},{"t":"set","p":"State_2","pt":"flow","to":"0","tot":"jsonata"},{"t":"set","p":"State_MAX","pt":"flow","to":"0","tot":"jsonata"},{"t":"set","p":"devices","pt":"flow","to":"{\"devList\":[]}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":710,"y":120,"wires":[["778ec673.85ac28"]]},{"id":"392ba79a.a06c58","type":"change","z":"7e71de96.77727","name":"","rules":[{"t":"set","p":"state.State_1","pt":"msg","to":"State_1","tot":"flow"},{"t":"set","p":"state.State_2","pt":"msg","to":"State_2","tot":"flow"},{"t":"set","p":"state.State_MAX","pt":"msg","to":"State_MAX","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":780,"y":300,"wires":[["e0050d3.909bbf"]]},{"id":"b6398b5.f1c4978","type":"function","z":"7e71de96.77727","name":"accumulate stats","func":"\nvar state1 = flow.get(\"State_1\");\nvar state2 = flow.get(\"State_2\");\nvar devType = env.get(\"TYPE\");\nvar actions = env.get(\"ACTIONS\").split(\"/\");\nvar retMsg;\nvar hub = msg.hub;\nvar devId = hub + \"/\" + msg.payload.id;\nvar dev = flow.get(\"devices\");\n\n\nvar devList = [];\n\nif (dev) {\n    devList = dev.devList;\n}\n\n//node.warn(devList);\n\n\nif (!devList.includes(devId)) {\n    \n    devList.push(devId);\n    dev.devList = devList;\n    flow.set(\"devices\",dev);\n    \n    // set flow counting vars\n    var attr = msg.payload.attributes;\n    //node.warn(attr);\n    var osw = attr.find(od => od.name === devType );\n    msg.payload.value = osw.currentValue;\n    \n    if (osw.currentValue === actions[0]) {\n        state1++;\n        flow.set(\"State_1\",state1);\n    } else if (osw.currentValue === actions[1]) {\n        state2++;\n        flow.set(\"State_2\",state2);\n    }\n    \n    // strip \"path\"/\"hub\" for tidiness\n    delete msg.path;\n    delete msg.hub;\n    \n    retMsg = msg;\n}\n\n\nreturn retMsg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":790,"y":220,"wires":[["c9807839.b005f8"]]},{"id":"e0050d3.909bbf","type":"function","z":"7e71de96.77727","name":"Set payload","func":"var topic = env.get(\"TOPIC\");\nvar devices = env.get(\"DEVICES\");\nvar bAll1 = env.get(\"ALL_ACTION1\");\nvar bAll2 = env.get(\"ALL_ACTION2\");\nvar devType = env.get(\"TYPE\");\nvar actions = env.get(\"ACTIONS\").split(\"/\");\n\n\nvar cnt1 = msg.state.State_1;\nvar cnt2 = msg.state.State_2;\nvar cntNum = msg.state.State_MAX;\nvar calcVal = \"\";\n\nvar newPayld = {\n    \"name\": topic,\n    \"currentValue\": \"\",\n    \"value\": \"\",\n    \"displayName\": topic,\n    \"dataType\": \"ENUM\",\t\n    \"values\": {\"0\":actions[0],\"1\":actions[1]},\n    \"deviceId\": devices\n};\n\nif ( bAll1 && bAll2 ){\n    if (cnt1 === cntNum){\n        calcVal = actions[0];\n    } else if (cnt2 === cntNum){\n        calcVal = actions[1];\n    } else {\n        calcVal = \"pending\";\n    }\n}\nelse if ( bAll1 && !bAll2 ){\n    if (cnt1 === cntNum){\n        calcVal = actions[0];\n    } else {\n        calcVal = actions[1];\n    }\n    \n}\nelse if ( !bAll1 && bAll2 ){\n    if (cnt2 === cntNum){\n        calcVal = actions[1];\n    } else {\n        calcVal = actions[0];\n    }\n    \n}\nelse{\n    calcVal = \"undefined\";\n}\n\nnewPayld.value = calcVal\nnewPayld.currentValue = calcVal\n\nmsg.topic = topic\nmsg.payload = newPayld\n\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":990,"y":300,"wires":[["26ad91b7.ae866e","ee37dbfb.f47708"]]},{"id":"e82be6d9.b86718","type":"switch","z":"7e71de96.77727","name":"SEND_EVENTS = true?","property":"SEND_EVENTS","propertyType":"env","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":390,"y":40,"wires":[["bc8384ad.287788"]]},{"id":"db3390b.b70b57","type":"rbe","z":"7e71de96.77727","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload.value","x":1530,"y":260,"wires":[[]]},{"id":"f79df937.2dc538","type":"switch","z":"7e71de96.77727","name":"value != pending and != undefined","property":"true","propertyType":"jsonata","rules":[{"t":"eq","v":"payload.value != \"pending\" and payload.value != \"undefined\"","vt":"jsonata"}],"checkall":"true","repair":false,"outputs":1,"x":1300,"y":260,"wires":[["db3390b.b70b57"]]},{"id":"26ad91b7.ae866e","type":"function","z":"7e71de96.77727","name":"set status payload","func":"/*\n\n{\n\"fill\": (payload.value = \"on\" ? \"green\" : (payload.value = \"off\" ? \"blue\" : \"black\")),\n\"shape\":\"dot\",\n\"text\":'Status: \"' & payload.value & '\"'\n}\n\n*/\n\n\nvar devType = env.get(\"TYPE\");\nvar actions = env.get(\"ACTIONS\").split(\"/\");\n\nvar payload = {\n\"fill\": (msg.payload.value === actions[0] ? \"green\" : (msg.payload.value === actions[1] ? \"blue\" : \"black\")),\n\"shape\":\"dot\",\n\"text\":'Status: \"' + msg.payload.value + '\"'\n};\n\nmsg.payload = payload;\n\n\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1250,"y":360,"wires":[[]]},{"id":"ee37dbfb.f47708","type":"switch","z":"7e71de96.77727","name":"override = true/false","property":"override","propertyType":"flow","rules":[{"t":"true"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":1260,"y":200,"wires":[[],["f79df937.2dc538"]]},{"id":"2feace6b.d14dc2","type":"change","z":"7e71de96.77727","name":"override = true","rules":[{"t":"set","p":"override","pt":"flow","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":280,"y":120,"wires":[["81abc8d5.998a58"]]},{"id":"bc8384ad.287788","type":"change","z":"7e71de96.77727","name":"override = false","rules":[{"t":"set","p":"override","pt":"flow","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":700,"y":40,"wires":[["fb5a0d32.35fce"]]},{"id":"ff11f9ac.a1dc08","type":"subflow:52da5ceb.f5efa4","z":"7e71de96.77727","name":"","x":120,"y":40,"wires":[["e82be6d9.b86718"]]},{"id":"836e4fce.3b2e","type":"subflow:9e28a145.80b4c","z":"7e71de96.77727","name":"","x":540,"y":220,"wires":[["b6398b5.f1c4978"]]},{"id":"29102dd4.c88fb2","type":"debug","z":"af91369d.586338","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":670,"y":500,"wires":[]},{"id":"9b30373e.7864f8","type":"inject","z":"af91369d.586338","name":"On","props":[{"p":"command","v":"on","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":110,"y":480,"wires":[["f1c84278.5de4b"]]},{"id":"33147b0b.f47114","type":"inject","z":"af91369d.586338","name":"Off","props":[{"p":"command","v":"off","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":110,"y":520,"wires":[["f1c84278.5de4b"]]},{"id":"520a03bd.66998c","type":"debug","z":"af91369d.586338","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":670,"y":420,"wires":[]},{"id":"220cdb4f.808114","type":"subflow:7e71de96.77727","z":"af91369d.586338","name":"","env":[{"name":"TOPIC","value":"OfficeLights","type":"str"},{"name":"DEVICES","value":"OZIG/1773,OZIG/1774","type":"str"},{"name":"SEND_EVENTS","value":"false","type":"bool"}],"x":380,"y":420,"wires":[["520a03bd.66998c"],[]]},{"id":"f1c84278.5de4b","type":"subflow:5f0d4ee4.54595","z":"af91369d.586338","name":"","env":[{"name":"TOPIC","value":"OfficeLights","type":"str"},{"name":"DEVICES","value":"OZIG/1773,OZIG/1774","type":"str"}],"x":390,"y":500,"wires":[["29102dd4.c88fb2"]]},{"id":"70412c3c.829824","type":"debug","z":"af91369d.586338","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":670,"y":560,"wires":[]},{"id":"dff81a81.d917c8","type":"subflow:7e71de96.77727","z":"af91369d.586338","name":"","env":[{"name":"TOPIC","value":"OfficeLights","type":"str"},{"name":"DEVICES","value":"OZIG/1773,OZIG/1774","type":"str"}],"x":380,"y":560,"wires":[["70412c3c.829824"],[]]},{"id":"2d55ccab.9fa964","type":"inject","z":"af91369d.586338","name":"nothing","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"nothing","payloadType":"str","x":110,"y":420,"wires":[["220cdb4f.808114"]]}]
Groupings in NR - Further tweaks and updates. 11/30/20

[{"id":"4e1e6fde.a5bbf","type":"subflow","name":"HubGrpCommand","info":"","category":"","in":[{"x":40,"y":40,"wires":[{"id":"b47983a7.7b5f7"}]}],"out":[{"x":1220,"y":180,"wires":[{"id":"e076de00.f88b6","port":0},{"id":"320acf5d.6b427","port":0},{"id":"b706dd3b.cf87a","port":0},{"id":"47e952f6.d8d37c","port":0}]}],"env":[],"color":"#FC7A5E"},{"id":"2a44d5ee.875b7a","type":"hubitat command","z":"4e1e6fde.a5bbf","name":"Main Hub / OLDMAIN","server":"5664ca29.3af904","deviceId":"","command":"","commandArgs":"","x":520,"y":120,"wires":[["e076de00.f88b6"]]},{"id":"448a391d.a21278","type":"hubitat command","z":"4e1e6fde.a5bbf","name":"Main Hub - Zigbee / OLDZIGB","server":"623daead.b1d2b","deviceId":"","command":"","commandArgs":"","x":550,"y":180,"wires":[["320acf5d.6b427"]]},{"id":"e65b768b.ab1f68","type":"hubitat command","z":"4e1e6fde.a5bbf","name":"Main Hub C7 / MAIN","server":"106ae29b.a1d83d","deviceId":"","command":"","commandArgs":"","x":520,"y":300,"wires":[["47e952f6.d8d37c"]]},{"id":"ddcc8d55.8b128","type":"hubitat command","z":"4e1e6fde.a5bbf","name":"Upstairs Hub / UPSTAIRS","server":"925818a7.4a4018","deviceId":"","command":"","commandArgs":"","x":530,"y":240,"wires":[["b706dd3b.cf87a"]]},{"id":"e076de00.f88b6","type":"change","z":"4e1e6fde.a5bbf","name":"hub = OLDMAIN","rules":[{"t":"set","p":"hub","pt":"msg","to":"OLDMAIN","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":840,"y":120,"wires":[[]]},{"id":"320acf5d.6b427","type":"change","z":"4e1e6fde.a5bbf","name":"hub = OLDZIGB","rules":[{"t":"set","p":"hub","pt":"msg","to":"OLDZIGB","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":840,"y":180,"wires":[[]]},{"id":"47e952f6.d8d37c","type":"change","z":"4e1e6fde.a5bbf","name":"hub = MAIN","rules":[{"t":"set","p":"hub","pt":"msg","to":"MAIN","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":830,"y":300,"wires":[[]]},{"id":"b47983a7.7b5f7","type":"switch","z":"4e1e6fde.a5bbf","name":"hub = OLDMAIN \\n hub = OLDZIGB \\n hub = UPSTAIRS \\n hub = MAIN","property":"hub","propertyType":"msg","rules":[{"t":"eq","v":"OLDMAIN","vt":"str"},{"t":"eq","v":"OLDZIGB","vt":"str"},{"t":"eq","v":"UPSTAIRS","vt":"str"},{"t":"eq","v":"MAIN","vt":"str"}],"checkall":"true","repair":false,"outputs":4,"x":210,"y":200,"wires":[["2a44d5ee.875b7a"],["448a391d.a21278"],["ddcc8d55.8b128"],["e65b768b.ab1f68"]]},{"id":"b706dd3b.cf87a","type":"change","z":"4e1e6fde.a5bbf","name":"hub = UPSTAIRS","rules":[{"t":"set","p":"hub","pt":"msg","to":"UPSTAIRS","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":850,"y":240,"wires":[[]]},{"id":"5f0d4ee4.54595","type":"subflow","name":"DevGrpCommand","info":"","category":"","in":[{"x":20,"y":80,"wires":[{"id":"12bc27d.a7615d8"}]}],"out":[{"x":1520,"y":140,"wires":[{"id":"5033935.2de806c","port":0}]}],"env":[{"name":"TOPIC","type":"str","value":"swGroupName"},{"name":"DEVICES","type":"str","value":""},{"name":"TYPE","type":"str","value":"switch"},{"name":"ACTION","type":"str","value":"on/off"}],"color":"#FC7A5E","icon":"node-red-contrib-hubitat/command.svg","status":{"x":1520,"y":220,"wires":[{"id":"eb697deb.09311","port":0}]}},{"id":"12bc27d.a7615d8","type":"switch","z":"5f0d4ee4.54595","name":"does msg.command exist \\n and exists within ACTION?","property":"$exists(command) ? \t    ($contains($env(\"ACTION\"),command) ? true : false )\t: false\t\t","propertyType":"jsonata","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":200,"y":80,"wires":[["5716210f.80d6f"],[]]},{"id":"fd492199.dfaea","type":"join","z":"5f0d4ee4.54595","name":"","mode":"auto","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":790,"y":140,"wires":[["5033935.2de806c"]]},{"id":"5033935.2de806c","type":"change","z":"5f0d4ee4.54595","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload_send","tot":"msg"},{"t":"delete","p":"deviceId","pt":"msg"},{"t":"delete","p":"payload_send","pt":"msg"},{"t":"delete","p":"response","pt":"msg"},{"t":"set","p":"topic","pt":"msg","to":"TOPIC","tot":"env"}],"action":"","property":"","from":"","to":"","reg":false,"x":1000,"y":140,"wires":[["eb697deb.09311"]]},{"id":"eb697deb.09311","type":"change","z":"5f0d4ee4.54595","name":"payload = payload.value","rules":[{"t":"set","p":"payload","pt":"msg","to":"\t{\t\"fill\": (payload.value = \"on\" ? \"green\" : (payload.value = \"off\" ? \"blue\" : \"black\")),\t\"shape\":\"dot\",\t\"text\":'Command: \"' & payload.value & '\"'\t}\t","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1270,"y":220,"wires":[[]]},{"id":"caefe429.207cc8","type":"subflow:4e1e6fde.a5bbf","z":"5f0d4ee4.54595","name":"","env":[],"x":510,"y":140,"wires":[["fd492199.dfaea"]]},{"id":"5716210f.80d6f","type":"function","z":"5f0d4ee4.54595","name":"Gen related device msgs","func":"// walk thru device list and set commands\n\nvar topic = env.get(\"TOPIC\");\nvar devList = env.get(\"DEVICES\");\n//var devices = devList.split(\",\");\n// devices = env.get(\"DEVICES\").split(\",\");\n\n// if passing devices via deviceId \nif (msg.deviceId) {\n    devList = msg.deviceId;\n}\n\nvar devices;\nvar isString;\nif (typeof devList === \"string\") {\n    isString = true;\n    devices = devList.split(\",\");\n} else {\n    isString = false;\n    devices = devList;\n}\n\nvar len = devices.length;\n\nvar icnt = 0;\ndevices.forEach( o => {\n\n    // var dev = o.split(\"/\");\n    // var hub = dev[0];\n    // var devId = dev[1];\n    var hub;\n    var devId;\n    var key;\n\n\n    if( isString ) { \n        var dev = o.split(\"/\");\n        hub = dev[0];\n        devId = dev[1];\n        key = o;\n    } else {\n        hub = o.hub;\n        devId = o.deviceId;\n        key = o.hub + \"/\" + o.deviceId;\n    }\n\n\n    var parts = {\n        \"id\":topic,\n        \"index\": icnt,\n        \"count\": len,\n        \"type\":\"object\",\n        \"ch\":\"\",\n        \"key\": key,\n        \"len\":\"\"\n    }\n\n    var newPayld = {\n        \"name\": \"switch\",\n        \"value\": msg.command,\n        \"displayName\": topic,\n        \"deviceId\": devList,\n        \"descriptionText\": topic,\n        \"unit\": null,\n        \"type\": null,\n        \"data\": null\n    };\n\n    icnt++;\n    msg.parts = parts;\n    msg.deviceId = devId;\n    msg.payload = {\"deviceId\": devId};\n    msg.payload_send = newPayld;\n    msg.hub = hub;\n    \n    //node.warn(o)\n\n    node.send(msg);\n}\n);\n\n\n\nreturn;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":530,"y":80,"wires":[["caefe429.207cc8"]]},{"id":"9e28a145.80b4c","type":"subflow","name":"HubGrpRequest","info":"","category":"","in":[{"x":80,"y":200,"wires":[{"id":"8ef7fcff.46751"}]}],"out":[{"x":1140,"y":200,"wires":[{"id":"ec167371.9e589","port":0},{"id":"40eaa66d.4bd218","port":0},{"id":"368409fd.864856","port":0},{"id":"ee11f083.f9355","port":0}]}],"env":[],"color":"#FC7A5E"},{"id":"ec167371.9e589","type":"change","z":"9e28a145.80b4c","name":"hub = OLDMAIN","rules":[{"t":"set","p":"hub","pt":"msg","to":"OLDMAIN","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":860,"y":120,"wires":[[]]},{"id":"40eaa66d.4bd218","type":"change","z":"9e28a145.80b4c","name":"hub = OLDZIGB","rules":[{"t":"set","p":"hub","pt":"msg","to":"OLDZIGB","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":860,"y":180,"wires":[[]]},{"id":"ee11f083.f9355","type":"change","z":"9e28a145.80b4c","name":"hub = MAIN","rules":[{"t":"set","p":"hub","pt":"msg","to":"MAIN","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":850,"y":300,"wires":[[]]},{"id":"8ef7fcff.46751","type":"switch","z":"9e28a145.80b4c","name":"hub = OLDMAIN \\n hub = OLDZIGB \\n hub = UPSTAIRS \\n hub = MAIN","property":"hub","propertyType":"msg","rules":[{"t":"eq","v":"OLDMAIN","vt":"str"},{"t":"eq","v":"OLDZIGB","vt":"str"},{"t":"eq","v":"UPSTAIRS","vt":"str"},{"t":"eq","v":"MAIN","vt":"str"}],"checkall":"false","repair":false,"outputs":4,"x":310,"y":200,"wires":[["ccd2f8bb.864ac8"],["c875db14.d98708"],["ee51458c.5f4338"],["1ef39202.40cbbe"]]},{"id":"ccd2f8bb.864ac8","type":"hubitat request","z":"9e28a145.80b4c","name":"Main Hub / OLDMAIN","server":"5664ca29.3af904","path":"","x":580,"y":120,"wires":[["ec167371.9e589"]]},{"id":"c875db14.d98708","type":"hubitat request","z":"9e28a145.80b4c","name":"Main Hub - Zigbee / OLDZIGB","server":"623daead.b1d2b","path":"","x":610,"y":180,"wires":[["40eaa66d.4bd218"]]},{"id":"1ef39202.40cbbe","type":"hubitat request","z":"9e28a145.80b4c","name":"Main Hub C7 / MAIN","server":"106ae29b.a1d83d","path":"","x":580,"y":300,"wires":[["ee11f083.f9355"]]},{"id":"368409fd.864856","type":"change","z":"9e28a145.80b4c","name":"hub = UPSTAIRS","rules":[{"t":"set","p":"hub","pt":"msg","to":"UPSTAIRS","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":870,"y":240,"wires":[[]]},{"id":"ee51458c.5f4338","type":"hubitat request","z":"9e28a145.80b4c","name":"Upstairs Hub / UPSTAIRS","server":"925818a7.4a4018","path":"","x":590,"y":240,"wires":[["368409fd.864856"]]},{"id":"52da5ceb.f5efa4","type":"subflow","name":"HubGrpEvents","info":"","category":"","in":[],"out":[{"x":940,"y":180,"wires":[{"id":"190e2933.bc97c7","port":0},{"id":"7f4e9570.890b4c","port":0},{"id":"fb90e9a9.67a1a8","port":0},{"id":"3360de68.b23be2","port":0}]}],"env":[],"color":"#FC7A5E"},{"id":"dd1d273.772d9d8","type":"hubitat event","z":"52da5ceb.f5efa4","name":"Main Hub / OLDMAIN","server":"5664ca29.3af904","x":200,"y":140,"wires":[["190e2933.bc97c7"]]},{"id":"da0c1a72.241788","type":"hubitat event","z":"52da5ceb.f5efa4","name":"Main Hub - Zigbee / OLDZIGB","server":"623daead.b1d2b","x":220,"y":200,"wires":[["7f4e9570.890b4c"]]},{"id":"2dada7ec.57be98","type":"hubitat event","z":"52da5ceb.f5efa4","name":"Main Hub C7 / MAIN","server":"106ae29b.a1d83d","x":190,"y":260,"wires":[["fb90e9a9.67a1a8"]]},{"id":"190e2933.bc97c7","type":"change","z":"52da5ceb.f5efa4","name":"hub = OLDMAIN","rules":[{"t":"set","p":"hub","pt":"msg","to":"OLDMAIN","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":140,"wires":[[]]},{"id":"7f4e9570.890b4c","type":"change","z":"52da5ceb.f5efa4","name":"hub = OLDZIGB","rules":[{"t":"set","p":"hub","pt":"msg","to":"OLDZIGB","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":200,"wires":[[]]},{"id":"fb90e9a9.67a1a8","type":"change","z":"52da5ceb.f5efa4","name":"hub = MAIN","rules":[{"t":"set","p":"hub","pt":"msg","to":"MAIN","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":260,"wires":[[]]},{"id":"74b24021.1e4e4","type":"hubitat event","z":"52da5ceb.f5efa4","name":"Upstairs Hub / UPSTAIRS","server":"925818a7.4a4018","x":210,"y":80,"wires":[["3360de68.b23be2"]]},{"id":"3360de68.b23be2","type":"change","z":"52da5ceb.f5efa4","name":"hub = UPSTAIRS","rules":[{"t":"set","p":"hub","pt":"msg","to":"UPSTAIRS","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":530,"y":80,"wires":[[]]},{"id":"5664ca29.3af904","type":"hubitat config","name":"Main Hub","usetls":false,"host":"0.0.0.0","port":"80","appId":"000","nodeRedServer":"http://0.0.0.0:1880","webhookPath":"/hubitat/webhook","autoRefresh":true,"useWebsocket":false},{"id":"623daead.b1d2b","type":"hubitat config","name":"Main Hub - Zigbee","usetls":false,"host":"0.0.0.0","port":"80","appId":"000","nodeRedServer":"http://0.0.0.0:1880","webhookPath":"/hubitat/webhook_main_zigbee","autoRefresh":true,"useWebsocket":false},{"id":"106ae29b.a1d83d","type":"hubitat config","name":"Main Hub C7","usetls":false,"host":"0.0.0.0","port":"80","appId":"000","nodeRedServer":"http://0.0.0.0:1880","webhookPath":"/hubitat/webhook_c7","autoRefresh":true,"useWebsocket":false},{"id":"925818a7.4a4018","type":"hubitat config","name":"Upstairs Hub","usetls":false,"host":"0.0.0.0","port":"80","appId":"000","nodeRedServer":"http://0.0.0.0:1880","webhookPath":"/hubitat/webhook_upstairs","autoRefresh":true,"useWebsocket":false},{"id":"7e71de96.77727","type":"subflow","name":"DevGrpEvent","info":"","category":"","in":[{"x":60,"y":120,"wires":[{"id":"2feace6b.d14dc2"}]}],"out":[{"x":1740,"y":240,"wires":[{"id":"db3390b.b70b57","port":0},{"id":"ee37dbfb.f47708","port":0},{"id":"497e1185.1ce5b","port":0}]},{"x":1740,"y":340,"wires":[{"id":"26ad91b7.ae866e","port":0}]}],"env":[{"name":"TOPIC","type":"str","value":"swGroupName"},{"name":"DEVICES","type":"str","value":""},{"name":"TYPE","type":"str","value":"switch"},{"name":"ACTIONS","type":"str","value":"on/off"},{"name":"ALL_ACTION1","type":"bool","value":"true"},{"name":"ALL_ACTION2","type":"bool","value":"true"},{"name":"SEND_EVENTS","type":"bool","value":"true"},{"name":"RETURN_ALL_MSGS","type":"bool","value":"false"}],"color":"#FC7A5E","outputLabels":["Event Result","Event Status"],"icon":"node-red-contrib-hubitat/device.svg","status":{"x":1740,"y":400,"wires":[{"id":"26ad91b7.ae866e","port":0}]}},{"id":"778ec673.85ac28","type":"function","z":"7e71de96.77727","name":"Gen related device msgs","func":"// walk thru device list and set commands\nvar topic = env.get(\"TOPIC\");\nvar devList = env.get(\"DEVICES\");\nvar activeVal = ( msg.payload.value ? msg.payload.value : \"\" );\n//var devices = devList.split(\",\");\n\n//node.warn(devList);\n\n// devices = env.get(\"DEVICES\").split(\",\");\nvar devices;\nvar isString;\nif (typeof devList === \"string\") {\n    isString = true;\n    devices = devList.split(\",\");\n} else {\n    isString = false;\n    devices = devList;\n}\n\n\n//node.warn(devices);\n\nvar len = devices.length;\n\nflow.set(\"State_MAX\", len);\n\nvar icnt = 0;\ndevices.forEach( o => {\n\n    //var dev = o.split(\"/\");\n    //var hub = dev[0];\n    //var device = dev[1];\n    var hub;\n    var devId;\n    var key;\n\n    if( isString ) { \n        var dev = o.split(\"/\");\n        hub = dev[0];\n        devId = dev[1];\n        key = o;\n    } else {\n        hub = o.hub;\n        devId = o.deviceId;\n        key = o.hub + \"/\" + o.deviceId;\n    }\n\n    //var hub = dev.hub;\n    //var devId = dev.deviceId;\n\n        \n    var path = \"/devices/\" + devId;\n    var parts = {\n        \"id\":topic,\n        \"index\": icnt,\n        \"count\": len,\n        \"type\":\"object\",\n        \"ch\":\"\",\n        \"key\": key,\n        \"len\":\"\"\n    }\n    \n    icnt++;\n    msg.topic = topic;\n    msg.path = path;\n    msg.parts = parts;\n    msg.hub = hub\n    msg.activevalue = activeVal;\n    \n    node.send(msg);\n    node.done();\n}\n);\n\n\n\nreturn;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":930,"y":120,"wires":[["1c902085.1cf74f"]]},{"id":"c9807839.b005f8","type":"join","z":"7e71de96.77727","name":"","mode":"auto","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1210,"y":180,"wires":[["392ba79a.a06c58"]]},{"id":"81abc8d5.998a58","type":"change","z":"7e71de96.77727","name":"Initialize flow vars","rules":[{"t":"set","p":"State_1","pt":"flow","to":"0","tot":"jsonata"},{"t":"set","p":"State_2","pt":"flow","to":"0","tot":"jsonata"},{"t":"set","p":"State_MAX","pt":"flow","to":"0","tot":"jsonata"},{"t":"set","p":"devCheck","pt":"flow","to":"[]","tot":"json"},{"t":"set","p":"LstState_1","pt":"flow","to":"","tot":"str"},{"t":"set","p":"LstState_2","pt":"flow","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":650,"y":120,"wires":[["778ec673.85ac28"]]},{"id":"392ba79a.a06c58","type":"change","z":"7e71de96.77727","name":"","rules":[{"t":"set","p":"state.State_1","pt":"msg","to":"State_1","tot":"flow"},{"t":"set","p":"state.State_2","pt":"msg","to":"State_2","tot":"flow"},{"t":"set","p":"state.State_MAX","pt":"msg","to":"State_MAX","tot":"flow"},{"t":"set","p":"state.State1_devices","pt":"msg","to":"LstState_1","tot":"flow"},{"t":"set","p":"state.State2_devices","pt":"msg","to":"LstState_2","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":240,"wires":[["e0050d3.909bbf"]]},{"id":"b6398b5.f1c4978","type":"function","z":"7e71de96.77727","name":"accumulate stats","func":"\nvar state1 = flow.get(\"State_1\");\nvar state2 = flow.get(\"State_2\");\nvar devType = env.get(\"TYPE\");\nvar actions = env.get(\"ACTIONS\").split(\"/\");\nvar devices = env.get(\"DEVICES\");\n\n//var retMsg;\nvar hub = msg.hub;\nvar devId = hub + \"/\" + msg.payload.id;\n\n/*\nvar dev = flow.get(\"devs4stats\");\nvar devList = [];\n\nif (dev !== undefined ) {\n    devList = dev;\n}\n*/\n\n//if (!devList) {\n//    node.warn(\"No devices found for \" + hub);\n//    return\n//}\n\n//node.warn(devList);\n\n//node.warn(devList);\nvar devList = flow.get(\"devCheck\") ? flow.get(\"devCheck\") : [];\n\n\n// Note: these only show devices with the same action either State1 or State2 not both.\nvar devLstState1 = flow.get(\"LstState_1\") ? flow.get(\"LstState_1\") : \"\";\nvar devLstState2 = flow.get(\"LstState_2\") ? flow.get(\"LstState_2\") : \"\";\n\nif (!devList.includes(devId)) {\n    \n    //node.warn(devId);\n    \n    devList.push(devId);\n    //dev.devList = devList;\n    flow.set(\"devCheck\",devList);\n    \n    // set flow counting vars\n    var attr = msg.payload.attributes;\n    //node.warn(attr);\n    var osw = attr.find(od => od.name === devType );\n    msg.payload.value = osw.currentValue;\n    \n    var pos;\n    \n    if (osw.currentValue === actions[0]) {\n        state1++;\n        flow.set(\"State_1\",state1);\n\n        if (!devLstState1.includes(devId)){\n            devLstState1 += ( devLstState1 ? \",\" : \"\" ) + devId;\n        }\n        \n        pos = devLstState2.indexOf(devId)\n        if (pos > -1){\n            devLstState2 = devLstState2.replace( ( pos === 0 ? \"\" : \",\") + devId + ( pos === 0 ? \",\" : \"\"), \"\");\n        }\n        //devLstState2 = \"\";\n        \n    } else if (osw.currentValue === actions[1]) {\n        state2++;\n        flow.set(\"State_2\",state2);\n\n        if (!devLstState2.includes(devId)){\n            devLstState2 += ( devLstState2 ? \",\" : \"\" ) + devId;\n        }\n        pos = devLstState1.indexOf(devId)\n        if (pos > -1){\n            devLstState1 = devLstState1.replace( ( pos === 0 ? \"\" : \",\") + devId  + ( pos === 0 ? \",\" : \"\"), \"\");\n        }\n\n    }\n\n    flow.set(\"LstState_1\",devLstState1);\n    flow.set(\"LstState_2\",devLstState2);\n\n    \n    //node.warn(msg)\n    \n    // strip \"path\"/\"hub\" for tidiness\n    delete msg.path;\n    delete msg.hub;\n    \n    //retMsg = msg;\n    node.send(msg);\n    node.done();\n}\n\n\nreturn;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":910,"y":180,"wires":[["c9807839.b005f8"]]},{"id":"e0050d3.909bbf","type":"function","z":"7e71de96.77727","name":"Set payload","func":"var topic = env.get(\"TOPIC\");\nvar devices = env.get(\"DEVICES\");\nvar bAll1 = env.get(\"ALL_ACTION1\");\nvar bAll2 = env.get(\"ALL_ACTION2\");\nvar devType = env.get(\"TYPE\");\nvar actions = env.get(\"ACTIONS\").split(\"/\");\n\nvar cnt1 = msg.state.State_1;\nvar cnt2 = msg.state.State_2;\nvar cntNum = cnt1 + cnt2;\n//var cntNum = msg.state.State_MAX;\nvar calcVal = \"\";\n\nvar newPayld = {\n    \"name\": topic,\n    \"currentValue\": \"\",\n    \"value\": \"\",\n    \"displayName\": topic,\n    \"dataType\": \"ENUM\",\t\n    \"values\": {\"0\":actions[0],\"1\":actions[1]},\n    \"deviceId\": devices\n};\n\nif ( bAll1 && bAll2 ){\n    if (cnt1 === cntNum){\n        calcVal = actions[0];\n    } else if (cnt2 === cntNum){\n        calcVal = actions[1];\n    } else {\n        calcVal = \"pending\";\n    }\n}\nelse if ( bAll1 && !bAll2 ){\n    if (cnt1 === cntNum){\n        calcVal = actions[0];\n    } else {\n        calcVal = actions[1];\n    }\n    \n}\nelse if ( !bAll1 && bAll2 ){\n    if (cnt2 === cntNum){\n        calcVal = actions[1];\n    } else {\n        calcVal = actions[0];\n    }\n}\nelse{\n    calcVal = \"undefined\";\n}\n\nnewPayld.value = calcVal\nnewPayld.currentValue = calcVal\n\nmsg.topic = topic\nmsg.payload = newPayld\n\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":630,"y":240,"wires":[["ee37dbfb.f47708","26ad91b7.ae866e"]]},{"id":"e82be6d9.b86718","type":"switch","z":"7e71de96.77727","name":"SEND_EVENTS = true?","property":"SEND_EVENTS","propertyType":"env","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":390,"y":60,"wires":[["bc8384ad.287788"]]},{"id":"db3390b.b70b57","type":"rbe","z":"7e71de96.77727","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload.value","x":1550,"y":320,"wires":[[]]},{"id":"26ad91b7.ae866e","type":"function","z":"7e71de96.77727","name":"set status payload","func":"/*\n\n{\n\"fill\": (payload.value = \"on\" ? \"green\" : (payload.value = \"off\" ? \"blue\" : \"black\")),\n\"shape\":\"dot\",\n\"text\":'Status: \"' & payload.value & '\"'\n}\n\n*/\n\n\nvar devType = env.get(\"TYPE\");\nvar actions = env.get(\"ACTIONS\").split(\"/\");\n\nvar payload = {\n\"fill\": (msg.payload.value === actions[0] ? \"green\" : (msg.payload.value === actions[1] ? \"blue\" : \"black\")),\n\"shape\":\"dot\",\n\"text\":'Status: \"' + msg.payload.value + '\"'\n};\n\nmsg.payload = payload;\n\n\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":910,"y":360,"wires":[[]]},{"id":"ee37dbfb.f47708","type":"switch","z":"7e71de96.77727","name":"actiontype = passthrough/event","property":"actiontype","propertyType":"msg","rules":[{"t":"eq","v":"passthrough","vt":"str"},{"t":"eq","v":"event","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":950,"y":240,"wires":[[],["7aa39d92.51b7d4"]]},{"id":"2feace6b.d14dc2","type":"change","z":"7e71de96.77727","name":"override = true","rules":[{"t":"set","p":"override","pt":"flow","to":"true","tot":"bool"},{"t":"set","p":"actiontype","pt":"msg","to":"passthrough","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":120,"wires":[["81abc8d5.998a58"]]},{"id":"bc8384ad.287788","type":"change","z":"7e71de96.77727","name":"override = false","rules":[{"t":"set","p":"override","pt":"flow","to":"false","tot":"bool"},{"t":"set","p":"actiontype","pt":"msg","to":"event","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":640,"y":60,"wires":[["bbe4a1b7.76f8e"]]},{"id":"ff11f9ac.a1dc08","type":"subflow:52da5ceb.f5efa4","z":"7e71de96.77727","name":"","env":[],"x":120,"y":60,"wires":[["e82be6d9.b86718"]]},{"id":"836e4fce.3b2e","type":"subflow:9e28a145.80b4c","z":"7e71de96.77727","name":"","env":[],"x":640,"y":180,"wires":[["b6398b5.f1c4978"]]},{"id":"bbe4a1b7.76f8e","type":"function","z":"7e71de96.77727","name":"does event match specified deviceId?","func":"// walk thru device list and set commands\nvar topic = env.get(\"TOPIC\");\nvar devList = env.get(\"DEVICES\");\nvar isString;\nvar device;\nvar retMsg;\n\n//node.warn(\"Checking...\");\n//node.warn(devList);\n\nif (typeof devList === \"string\") {\n    device = msg.hub + \"/\" + msg.payload.deviceId;\n    if ( devList.includes(device)) {\n        retMsg = msg;\n        //node.warn(\"String ID = \" + device);\n    }\n    \n} else {\n    if (devList.find( device => { return device.hub === msg.hub && device.deviceId === msg.payload.deviceId })) {\n        //node.warn(\"Found match in JSON object.\");\n        retMsg = msg;    \n    } else {\n        //node.warn(\"Not Found!.\");\n        //node.warn(devList);\n        //node.warn(msg.payload);\n    }\n}\n\nreturn retMsg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":970,"y":60,"wires":[["81abc8d5.998a58"]]},{"id":"f352de63.ef662","type":"inject","z":"7e71de96.77727","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":90,"y":180,"wires":[["adc8b319.affa5"]]},{"id":"fb041b21.135ec8","type":"no-op","z":"7e71de96.77727","name":"","x":1430,"y":120,"wires":[["836e4fce.3b2e"]]},{"id":"1c902085.1cf74f","type":"delay","z":"7e71de96.77727","name":"","pauseType":"delay","timeout":"50","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"50","randomLast":"100","randomUnits":"milliseconds","drop":false,"x":1230,"y":120,"wires":[["fb041b21.135ec8"]]},{"id":"adc8b319.affa5","type":"change","z":"7e71de96.77727","name":"override = init","rules":[{"t":"set","p":"override","pt":"flow","to":"false","tot":"bool"},{"t":"set","p":"actiontype","pt":"msg","to":"init","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":180,"wires":[["81abc8d5.998a58"]]},{"id":"7aa39d92.51b7d4","type":"switch","z":"7e71de96.77727","name":"Return All Msgs?","property":"RETURN_ALL_MSGS","propertyType":"env","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":910,"y":300,"wires":[["497e1185.1ce5b"],["78629b73.6f3d74"]]},{"id":"78629b73.6f3d74","type":"switch","z":"7e71de96.77727","name":"value != pending and != undefined","property":"true","propertyType":"jsonata","rules":[{"t":"eq","v":"payload.value != \"pending\" and payload.value != \"undefined\"","vt":"jsonata"}],"checkall":"true","repair":false,"outputs":1,"x":1320,"y":320,"wires":[["db3390b.b70b57"]]},{"id":"497e1185.1ce5b","type":"change","z":"7e71de96.77727","name":"set payload.value to activevalue","rules":[{"t":"set","p":"payload.value","pt":"msg","to":"activevalue","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1310,"y":280,"wires":[[]]},{"id":"29102dd4.c88fb2","type":"debug","z":"af91369d.586338","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":670,"y":320,"wires":[]},{"id":"9b30373e.7864f8","type":"inject","z":"af91369d.586338","name":"On","props":[{"p":"command","v":"on","vt":"str"},{"p":"deviceId","v":"[{\"hub\":\"OLDZIGB\",\"deviceId\":\"1773\",\"desc\":\"Office Left Light\"},{\"hub\":\"OLDZIGB\",\"deviceId\":\"1774\",\"desc\":\"Office Right Light\"}]","vt":"json"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"str","x":110,"y":300,"wires":[["f1c84278.5de4b"]]},{"id":"33147b0b.f47114","type":"inject","z":"af91369d.586338","name":"Off","props":[{"p":"command","v":"off","vt":"str"},{"p":"deviceId","v":"[ \t{ \t\t\"hub\":\"OLDZIGB\", \t\t\"deviceId\":\"1773\", \t\t\"desc\":\"Office Left Light\" \t}, \t\t{ \t\t\"hub\":\"OLDZIGB\", \t\t\"deviceId\":\"1774\", \t\t\"desc\":\"Office Right Light\" \t} ]","vt":"json"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":110,"y":340,"wires":[["f1c84278.5de4b"]]},{"id":"520a03bd.66998c","type":"debug","z":"af91369d.586338","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":670,"y":260,"wires":[]},{"id":"220cdb4f.808114","type":"subflow:7e71de96.77727","z":"af91369d.586338","name":"","env":[{"name":"TOPIC","value":"OfficeLights","type":"str"},{"name":"DEVICES","value":"OLDZIGB/1773,OLDZIGB/1774","type":"str"},{"name":"SEND_EVENTS","value":"false","type":"bool"}],"x":380,"y":260,"wires":[["520a03bd.66998c"],[]]},{"id":"f1c84278.5de4b","type":"subflow:5f0d4ee4.54595","z":"af91369d.586338","name":"","env":[{"name":"TOPIC","value":"OfficeLights","type":"str"}],"x":390,"y":320,"wires":[["29102dd4.c88fb2"]]},{"id":"70412c3c.829824","type":"debug","z":"af91369d.586338","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":670,"y":380,"wires":[]},{"id":"dff81a81.d917c8","type":"subflow:7e71de96.77727","z":"af91369d.586338","name":"","env":[{"name":"TOPIC","value":"OfficeLights","type":"str"},{"name":"DEVICES","value":"[{\"hub\":\"OLDZIGB\",\"deviceId\":\"1773\",\"desc\":\"Office Left Light\"},{\"hub\":\"OLDZIGB\",\"deviceId\":\"1774\",\"desc\":\"Office Right Light\"}]","type":"json"},{"name":"ALL_ACTION1","value":"false","type":"bool"}],"x":380,"y":380,"wires":[["70412c3c.829824"],[]]},{"id":"2d55ccab.9fa964","type":"inject","z":"af91369d.586338","name":"nothing","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"nothing","payloadType":"str","x":110,"y":260,"wires":[["220cdb4f.808114"]]},{"id":"e3571bb5.35b4c8","type":"comment","z":"af91369d.586338","name":"Group Tests","info":"","x":120,"y":220,"wires":[]}]
3 Likes

Don't feel like the Lone Ranger.

1 Like