Node-Red Flow Samples/Sharing

In case someone is looking to capture and restore the state of an RGBW device (bulb, light strip etc), here's a flow that does it without using any function nodes.

RGBW device capture/restore
[{"id":"bd43a28e31299b4e","type":"join","z":"91a3133eb0da7fd1","name":"json join","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":",","joinerType":"str","accumulate":false,"timeout":"","count":"3","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"num","reduceFixup":"","x":900,"y":460,"wires":[["1a20d06b3e2b00de"]]},{"id":"33c87a8fe098f670","type":"change","z":"91a3133eb0da7fd1","name":"hue","rules":[{"t":"set","p":"topic","pt":"msg","to":"hue","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"nightstand_hue","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":690,"y":420,"wires":[["bd43a28e31299b4e"]]},{"id":"9e9ff88f8850ec97","type":"delay","z":"91a3133eb0da7fd1","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"x":775,"y":460,"wires":[["bd43a28e31299b4e"]],"l":false},{"id":"882f9aa4ccd461d8","type":"delay","z":"91a3133eb0da7fd1","name":"","pauseType":"delay","timeout":"2","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"x":775,"y":500,"wires":[["bd43a28e31299b4e"]],"l":false},{"id":"1a20d06b3e2b00de","type":"change","z":"91a3133eb0da7fd1","name":"setColor","rules":[{"t":"set","p":"command","pt":"msg","to":"setColor","tot":"str"},{"t":"set","p":"arguments","pt":"msg","to":"$string(payload)","tot":"jsonata"},{"t":"delete","p":"payload","pt":"msg"},{"t":"delete","p":"topic","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1060,"y":460,"wires":[["752c91c1499e6c0d"]]},{"id":"ebaff8760d384dad","type":"inject","z":"91a3133eb0da7fd1","name":"capture","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"str","x":190,"y":220,"wires":[["d493e99a42f7e962"]]},{"id":"b844cd04e44b82c2","type":"change","z":"91a3133eb0da7fd1","name":"sat","rules":[{"t":"set","p":"topic","pt":"msg","to":"saturation","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"nightstand_sat","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":670,"y":460,"wires":[["9e9ff88f8850ec97"]]},{"id":"a068ec247987c0a3","type":"change","z":"91a3133eb0da7fd1","name":"lvl","rules":[{"t":"set","p":"topic","pt":"msg","to":"level","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"nightstand_level","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":670,"y":500,"wires":[["882f9aa4ccd461d8"]]},{"id":"752c91c1499e6c0d","type":"hubitat command","z":"91a3133eb0da7fd1","deviceLabel":"Nightstand","name":"","server":"a22e0ea9.276dc8","deviceId":"1848","command":"","commandArgs":"","x":1230,"y":400,"wires":[[]]},{"id":"34509478991b20e0","type":"change","z":"91a3133eb0da7fd1","name":"setCT","rules":[{"t":"set","p":"command","pt":"msg","to":"setColorTemperature","tot":"str"},{"t":"set","p":"arguments","pt":"msg","to":"$string(payload)","tot":"jsonata"},{"t":"delete","p":"payload","pt":"msg"},{"t":"delete","p":"topic","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1070,"y":340,"wires":[["752c91c1499e6c0d"]]},{"id":"0b1d78c881efdaa9","type":"join","z":"91a3133eb0da7fd1","name":"string join","mode":"custom","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":",","joinerType":"str","accumulate":false,"timeout":"","count":"3","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"num","reduceFixup":"","x":900,"y":340,"wires":[["34509478991b20e0"]]},{"id":"3a6e9026443d9a4b","type":"change","z":"91a3133eb0da7fd1","name":"CT","rules":[{"t":"set","p":"topic","pt":"msg","to":"CT","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"nightstand_ct","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":690,"y":300,"wires":[["0b1d78c881efdaa9"]]},{"id":"fa09d8b57c2cae11","type":"delay","z":"91a3133eb0da7fd1","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"x":775,"y":340,"wires":[["0b1d78c881efdaa9"]],"l":false},{"id":"a172a41701dca630","type":"delay","z":"91a3133eb0da7fd1","name":"","pauseType":"delay","timeout":"2","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"x":775,"y":380,"wires":[["0b1d78c881efdaa9"]],"l":false},{"id":"a29e26c0b164ffaa","type":"inject","z":"91a3133eb0da7fd1","name":"restore","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"str","x":190,"y":400,"wires":[["d7d131b5316c0ae1"]]},{"id":"6c7591caf5a8ae1b","type":"change","z":"91a3133eb0da7fd1","name":"lvl","rules":[{"t":"set","p":"topic","pt":"msg","to":"level","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"nightstand_level","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":670,"y":340,"wires":[["fa09d8b57c2cae11"]]},{"id":"adc81e31e3a921e5","type":"change","z":"91a3133eb0da7fd1","name":"time","rules":[{"t":"set","p":"topic","pt":"msg","to":"time","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"0","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":670,"y":380,"wires":[["a172a41701dca630"]]},{"id":"d493e99a42f7e962","type":"hubitat device","z":"91a3133eb0da7fd1","deviceLabel":"Nightstand","name":"","server":"a22e0ea9.276dc8","deviceId":"1848","attribute":"","sendEvent":false,"x":350,"y":220,"wires":[["335faf55a5b1b2e2"]]},{"id":"335faf55a5b1b2e2","type":"change","z":"91a3133eb0da7fd1","name":"nightstand","rules":[{"t":"set","p":"nightstand_switch","pt":"flow","to":"payload.switch.value","tot":"msg"},{"t":"set","p":"nightstand_colorMode","pt":"flow","to":"payload.colorMode.value","tot":"msg"},{"t":"set","p":"nightstand_ct","pt":"flow","to":"payload.colorTemperature.value","tot":"msg"},{"t":"set","p":"nightstand_hue","pt":"flow","to":"payload.hue.value","tot":"msg"},{"t":"set","p":"nightstand_sat","pt":"flow","to":"payload.saturation.value","tot":"msg"},{"t":"set","p":"nightstand_level","pt":"flow","to":"payload.level.value","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":530,"y":220,"wires":[[]]},{"id":"d7d131b5316c0ae1","type":"switch","z":"91a3133eb0da7fd1","name":"on?","property":"nightstand_switch","propertyType":"flow","rules":[{"t":"eq","v":"on","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":330,"y":400,"wires":[["ae9b298edeef2436"]]},{"id":"ae9b298edeef2436","type":"switch","z":"91a3133eb0da7fd1","name":"CT or RGB","property":"nightstand_colorMode","propertyType":"flow","rules":[{"t":"eq","v":"CT","vt":"str"},{"t":"eq","v":"RGB","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":490,"y":400,"wires":[["3a6e9026443d9a4b","6c7591caf5a8ae1b","adc81e31e3a921e5"],["33c87a8fe098f670","b844cd04e44b82c2","a068ec247987c0a3"]]},{"id":"de897648d00e3312","type":"comment","z":"91a3133eb0da7fd1","name":"CAPTURE","info":"","x":180,"y":160,"wires":[]},{"id":"88864d62853db2d2","type":"comment","z":"91a3133eb0da7fd1","name":"RESTORE","info":"","x":180,"y":340,"wires":[]},{"id":"a22e0ea9.276dc8","type":"hubitat config","name":"HubitatM","usetls":false,"host":"192.168.1.46","port":"80","appId":"1522","nodeRedServer":"http://192.168.1.4:1880","webhookPath":"/hubitat/webhook","autoRefresh":true,"useWebsocket":false,"colorEnabled":true,"color":"#5dd049"}]
6 Likes

Title: Christmas Lights

Summary: Control Christmas lights, based on hub mode and enablement switches.

Description:

This is the flow that controls my Christmas lights, based on hub mode. To start with, I use five modes for my hub:

  • Late Night - midnight to 5:00AM
  • Early Morning - 5:00AM to 7:00AM or Sunrise (whichever is later)
  • Day - 7:00AM or Sunrise (whichever is later) to Sunset or 6:00PM (whichever is earlier)
  • Evening - Sunset or 6:00PM (whichever is earlier) to 9:00PM
  • Night - 9:00PM to Midnight

Additionally, I'm on the lazy side. I want to be able to tap a few switches on my dashboard and enable or disable the rule, so I have three enabler switches:

  • Enable Christmas Lights - Overall enabler switch
  • Enable Inside Christmas Lights All Day (Weekday) - Leave inside lights on all day Mon.-Fri.
  • Enable Inside Christmas Lights All Day (Weekend) - Leave inside lights on all day on Sat./Sun.

Flow:

Code
[{"id":"2f63e299838a554f","type":"tab","label":"Christmas Lights","disabled":false,"info":"","env":[]},{"id":"4f681d70b6fedee7","type":"hubitat mode","z":"2f63e299838a554f","name":"","server":"7655a118644027a5","sendEvent":true,"x":270,"y":320,"wires":[["3fbf334427cf954f"]]},{"id":"3fbf334427cf954f","type":"switch","z":"2f63e299838a554f","name":"Mode is","property":"payload.value","propertyType":"msg","rules":[{"t":"eq","v":"Late Night","vt":"str"},{"t":"eq","v":"Early Morning","vt":"str"},{"t":"eq","v":"Day","vt":"str"},{"t":"eq","v":"Evening","vt":"str"},{"t":"eq","v":"Night","vt":"str"}],"checkall":"true","repair":false,"outputs":5,"x":420,"y":320,"wires":[["61f8b8908e56522a","9c2d1e4a497ec98b"],["16d5754d0bc20d4a","dc196fca301b94e6"],["61f8b8908e56522a","c8bc9f173e6b2b4f"],["16d5754d0bc20d4a","dc196fca301b94e6"],["16d5754d0bc20d4a","dc196fca301b94e6"]]},{"id":"a4b0bed5c8fe96f3","type":"hubitat command","z":"2f63e299838a554f","deviceLabel":"Inside Christmas Lights","name":"Turn on Inside Christmas Lights","server":"7655a118644027a5","deviceId":"45","command":"on","commandArgs":"","x":1230,"y":80,"wires":[["8be708066b4ff70f"]]},{"id":"6dcef8a94c272a92","type":"hubitat command","z":"2f63e299838a554f","deviceLabel":"Inside Christmas Lights","name":"Turn off Inside Christmas Lights","server":"7655a118644027a5","deviceId":"45","command":"off","commandArgs":"","x":1230,"y":240,"wires":[["8be708066b4ff70f"]]},{"id":"24ee5de59b1db25a","type":"hubitat command","z":"2f63e299838a554f","deviceLabel":"Inside Christmas Lights","name":"Turn on Outside Christmas Lights","server":"7655a118644027a5","deviceId":"48","command":"on","commandArgs":"","x":1240,"y":820,"wires":[["8be708066b4ff70f"]]},{"id":"d0e4a2640bb7792a","type":"hubitat command","z":"2f63e299838a554f","deviceLabel":"Inside Christmas Lights","name":"Turn off Outside Christmas Lights","server":"7655a118644027a5","deviceId":"48","command":"off","commandArgs":"","x":1240,"y":980,"wires":[["8be708066b4ff70f"]]},{"id":"16d5754d0bc20d4a","type":"hubitat device","z":"2f63e299838a554f","deviceLabel":"Enable Christmas Lights","name":"","server":"7655a118644027a5","deviceId":"40","attribute":"switch","sendEvent":false,"x":730,"y":820,"wires":[["d7305ada73f9043c"]]},{"id":"d7305ada73f9043c","type":"switch","z":"2f63e299838a554f","name":"Is on","property":"payload.value","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":950,"y":820,"wires":[["86d3469488640d27"],["8be708066b4ff70f"]]},{"id":"61f8b8908e56522a","type":"hubitat device","z":"2f63e299838a554f","deviceLabel":"Outside Christmas Lights","name":"","server":"7655a118644027a5","deviceId":"48","attribute":"switch","sendEvent":false,"x":730,"y":980,"wires":[["8410b820258d50b3"]]},{"id":"8410b820258d50b3","type":"switch","z":"2f63e299838a554f","name":"Is on","property":"payload.value","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":950,"y":980,"wires":[["d0e4a2640bb7792a"],["8be708066b4ff70f"]]},{"id":"8be708066b4ff70f","type":"debug","z":"2f63e299838a554f","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1750,"y":340,"wires":[]},{"id":"86d3469488640d27","type":"hubitat device","z":"2f63e299838a554f","deviceLabel":"Outside Christmas Lights","name":"","server":"7655a118644027a5","deviceId":"48","attribute":"switch","sendEvent":false,"x":730,"y":900,"wires":[["4a0903f5dd841a80"]]},{"id":"4a0903f5dd841a80","type":"switch","z":"2f63e299838a554f","name":"Is on","property":"payload.value","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":950,"y":900,"wires":[["8be708066b4ff70f"],["24ee5de59b1db25a"]]},{"id":"dc196fca301b94e6","type":"hubitat device","z":"2f63e299838a554f","deviceLabel":"Enable Christmas Lights","name":"","server":"7655a118644027a5","deviceId":"40","attribute":"switch","sendEvent":false,"x":730,"y":80,"wires":[["f740e1e3901b2036"]]},{"id":"f740e1e3901b2036","type":"switch","z":"2f63e299838a554f","name":"Is on","property":"payload.value","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":950,"y":80,"wires":[["1eea891d1bf346b2"],["8be708066b4ff70f"]]},{"id":"1eea891d1bf346b2","type":"hubitat device","z":"2f63e299838a554f","deviceLabel":"Inside Christmas Lights","name":"","server":"7655a118644027a5","deviceId":"45","attribute":"switch","sendEvent":false,"x":730,"y":160,"wires":[["c8010e485999bddf"]]},{"id":"c8010e485999bddf","type":"switch","z":"2f63e299838a554f","name":"Is on","property":"payload.value","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":950,"y":160,"wires":[["8be708066b4ff70f"],["a4b0bed5c8fe96f3"]]},{"id":"9c2d1e4a497ec98b","type":"hubitat device","z":"2f63e299838a554f","deviceLabel":"Inside Christmas Lights","name":"","server":"7655a118644027a5","deviceId":"45","attribute":"switch","sendEvent":false,"x":730,"y":240,"wires":[["f9ef51b0b19f1de8"]]},{"id":"f9ef51b0b19f1de8","type":"switch","z":"2f63e299838a554f","name":"Is on","property":"payload.value","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":950,"y":240,"wires":[["6dcef8a94c272a92"],["8be708066b4ff70f"]]},{"id":"301fced593fda3ae","type":"switch","z":"2f63e299838a554f","name":"is on","property":"payload.value","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":350,"y":440,"wires":[["4f681d70b6fedee7"],["61f8b8908e56522a","9c2d1e4a497ec98b"]]},{"id":"8d2dcaddd07ea59e","type":"hubitat device","z":"2f63e299838a554f","deviceLabel":"Enable Christmas Lights","name":"","server":"7655a118644027a5","deviceId":"40","attribute":"switch","sendEvent":true,"x":150,"y":440,"wires":[["301fced593fda3ae"]]},{"id":"3a61a6dcdd058301","type":"comment","z":"2f63e299838a554f","name":"Turn lights on/off as mode changes or enable switch status changes","info":"","x":280,"y":240,"wires":[]},{"id":"26cec17f6ffb592f","type":"hubitat device","z":"2f63e299838a554f","deviceLabel":"Enable Inside Christmas Lights All Day (Weekday)","name":"","server":"7655a118644027a5","deviceId":"84","attribute":"switch","sendEvent":true,"x":230,"y":540,"wires":[["4f681d70b6fedee7"]]},{"id":"d7e1f0f494661021","type":"hubitat device","z":"2f63e299838a554f","deviceLabel":"Enable Inside Christmas Lights All Day (Weekend)","name":"","server":"7655a118644027a5","deviceId":"91","attribute":"switch","sendEvent":true,"x":230,"y":600,"wires":[["4f681d70b6fedee7"]]},{"id":"c8bc9f173e6b2b4f","type":"simpletime","z":"2f63e299838a554f","name":"Add timestamp","mydate":false,"myymd":false,"myyear":false,"mymonth":false,"mymonthn":false,"mydom":false,"mydoy":false,"myday":false,"myhourpm":false,"myhour":false,"mytime":false,"mytimes":false,"myminute":false,"myminutes":false,"mysecond":false,"mymillis":false,"myepoch":false,"myrawdate":true,"mypm":false,"x":700,"y":440,"wires":[["ea6e44527d57097b"]]},{"id":"ea6e44527d57097b","type":"moment","z":"2f63e299838a554f","name":"Set weekday","topic":"","input":"myrawdate","inputType":"msg","inTz":"ETC/UTC","adjAmount":0,"adjType":"days","adjDir":"add","format":"ddd","locale":"en-US","output":"payload.weekday","outputType":"msg","outTz":"America/Chicago","x":890,"y":440,"wires":[["7ffc4495c09c4ca4"]]},{"id":"7ffc4495c09c4ca4","type":"switch","z":"2f63e299838a554f","name":"Day is","property":"payload.weekday","propertyType":"msg","rules":[{"t":"eq","v":"Sun","vt":"str"},{"t":"eq","v":"Mon","vt":"str"},{"t":"eq","v":"Tue","vt":"str"},{"t":"eq","v":"Wed","vt":"str"},{"t":"eq","v":"Thu","vt":"str"},{"t":"eq","v":"Fri","vt":"str"},{"t":"eq","v":"Sat","vt":"str"}],"checkall":"true","repair":false,"outputs":7,"x":710,"y":520,"wires":[["b3091cc0736c1520"],["77fc5085128131dc"],["77fc5085128131dc"],["77fc5085128131dc"],["77fc5085128131dc"],["77fc5085128131dc"],["b3091cc0736c1520"]]},{"id":"b3091cc0736c1520","type":"hubitat device","z":"2f63e299838a554f","deviceLabel":"Enable Inside Christmas Lights All Day (Weekend)","name":"","server":"7655a118644027a5","deviceId":"91","attribute":"switch","sendEvent":false,"x":1010,"y":560,"wires":[["02710a0ca65eb28c"]]},{"id":"77fc5085128131dc","type":"hubitat device","z":"2f63e299838a554f","deviceLabel":"Enable Inside Christmas Lights All Day (Weekday)","name":"","server":"7655a118644027a5","deviceId":"84","attribute":"switch","sendEvent":false,"x":1010,"y":500,"wires":[["02710a0ca65eb28c"]]},{"id":"02710a0ca65eb28c","type":"switch","z":"2f63e299838a554f","name":"Is on","property":"payload.value","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":1310,"y":520,"wires":[["dc196fca301b94e6"],["9c2d1e4a497ec98b"]]},{"id":"29106bb5a68a830a","type":"comment","z":"2f63e299838a554f","name":"Leave inside lights on all day, if enabled","info":"","x":770,"y":380,"wires":[]},{"id":"7655a118644027a5","type":"hubitat config","name":"Home","usetls":false,"host":"172.27.201.5","port":"80","appId":"397","nodeRedServer":"http://172.27.201.1:1880","webhookPath":"/hubitat/webhook_","autoRefresh":true,"useWebsocket":false,"colorEnabled":false,"color":"#ace043"}]
5 Likes

Is there an attribute for either the Inovelli Red Switch or the GE/Jasco Z-wave smart switch that distinguishes when a light is turned on manually versus an automation?

What I want to do is when an automation turns off a light but I want it on for the time being, I'd like to manually switch it on and not have the automation turning it off again.

Thanks,

For the GE/Jasco, I use the "Type" attribute (physical/digital) to distinguish manual/automation. Not sure about Inovelli

2 Likes

I see the type in the events log for the switch but not as an option in Node-Red.

Screen Shot 2021-12-05 at 7.40.25 AM

I am using the GE device Type.

@douglaspitman

Here's how you do it:

  1. Evaluate on "switch"
  2. if "msg.payload.value == on", then evaluate if "msg.payload.type == physical".

I use this routinely in my flows with a variety of switches including Zooz, one GE, and multiple Caseta.

Type is not a command, so it will not show up as a command in node-red. It is an event, that shows up as msg.payload.type, if you look for events from "switch".

3 Likes

I found it. But... I am having trouble figuring out how to include it in a motion flow. Do you have an example you would be willing to share?

Thanks,

The way you do this is to set a global variable like "hallSwitchDisable" to true when you manually turn on the switch and false when you manually turn it off.. then in your motion sequence just test for "hallSwitchDisable" if it is true then ignore the auto shut off..

1 Like

Sure, I’ll try to put a sample together later today. Basically, my approach is similar to that described by @erktrek.

1 Like

Here's an example:

  1. My closet light is controlled by events from a motion sensor and a contact sensor.
  2. If the switch is turned on manually, then contact and motion events are not used to control the light.
  3. When the switch is turned off (by any means - physical or digital), after 30 seconds, control is restored to motion/contact events.

Sequence for import
[{"id":"a59873edf4b6c732","type":"switch","z":"387332bd262639e8","name":"physical","property":"payload.type","propertyType":"msg","rules":[{"t":"eq","v":"physical","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":680,"y":360,"wires":[["b944d6b5cf1ed913","189e58365736b00b","900932d992fc024b"]]},{"id":"b944d6b5cf1ed913","type":"change","z":"387332bd262639e8","name":"reset","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":815,"y":360,"wires":[["65a6a38de7df05f0"]],"l":false},{"id":"65a6a38de7df05f0","type":"delay","z":"387332bd262639e8","name":"30s","pauseType":"delay","timeout":"30","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"outputs":1,"x":815,"y":300,"wires":[["f717b2d07000d4f9"]],"l":false},{"id":"9278527930f6824d","type":"switch","z":"387332bd262639e8","name":"off/on","property":"payload.value","propertyType":"msg","rules":[{"t":"eq","v":"off","vt":"str"},{"t":"eq","v":"on","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":650,"y":300,"wires":[["65a6a38de7df05f0"],["a59873edf4b6c732"]]},{"id":"f2954135ed5ebc16","type":"hubitat device","z":"387332bd262639e8","deviceLabel":"Closet Light","name":"","server":"662851c4.3ccad","deviceId":"4197","attribute":"switch","sendEvent":true,"x":490,"y":300,"wires":[["9278527930f6824d"]]},{"id":"189e58365736b00b","type":"change","z":"387332bd262639e8","name":"g.physical_switch=true","rules":[{"t":"set","p":"physical_switch","pt":"global","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":980,"y":360,"wires":[[]]},{"id":"f717b2d07000d4f9","type":"change","z":"387332bd262639e8","name":"g.physical_switch=false","rules":[{"t":"set","p":"physical_switch","pt":"global","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":970,"y":300,"wires":[[]]},{"id":"9a511e9dda84aa32","type":"switch","z":"387332bd262639e8","name":"g.physical_switch=false","property":"physical_switch","propertyType":"global","rules":[{"t":"false"}],"checkall":"true","repair":false,"outputs":1,"x":430,"y":480,"wires":[["84351932e13b16a3"]]},{"id":"6d4841a811373d8c","type":"hubitat device","z":"387332bd262639e8","deviceLabel":"Motion - Closet","name":"","server":"a22e0ea9.276dc8","deviceId":"1977","attribute":"motion","sendEvent":true,"x":200,"y":520,"wires":[["9a511e9dda84aa32"]]},{"id":"d0893423e00178ea","type":"hubitat device","z":"387332bd262639e8","deviceLabel":"Contact - Closet Door","name":"","server":"a22e0ea9.276dc8","deviceId":"1974","attribute":"contact","sendEvent":true,"x":180,"y":440,"wires":[["9a511e9dda84aa32"]]},{"id":"84351932e13b16a3","type":"switch","z":"387332bd262639e8","name":"active|open / inactive|closed","property":"payload.value","propertyType":"msg","rules":[{"t":"regex","v":"active|open","vt":"str","case":false},{"t":"regex","v":"inactive|closed","vt":"str","case":false}],"checkall":"true","repair":false,"outputs":2,"x":700,"y":480,"wires":[["900932d992fc024b"],["477edd2a05b35a2c"]]},{"id":"900932d992fc024b","type":"change","z":"387332bd262639e8","name":"stop","rules":[{"t":"set","p":"payload","pt":"msg","to":"stop","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":910,"y":460,"wires":[["477edd2a05b35a2c","85a4800e17daf003"]]},{"id":"477edd2a05b35a2c","type":"stoptimer-varidelay","z":"387332bd262639e8","duration":"3","durationType":"num","units":"Minute","payloadtype":"num","payloadval":"0","name":"3 min","reporting":"last_minute_seconds","persist":true,"x":930,"y":520,"wires":[["68c6a6762f95e59c"],[],[]]},{"id":"85a4800e17daf003","type":"change","z":"387332bd262639e8","name":"setLevel","rules":[{"t":"set","p":"arguments","pt":"msg","to":"100,0","tot":"str"},{"t":"set","p":"command","pt":"msg","to":"setLevel","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1035,"y":460,"wires":[["f823567d37b92354"]],"l":false},{"id":"f823567d37b92354","type":"hubitat command","z":"387332bd262639e8","deviceLabel":"Closet Light","name":"","server":"662851c4.3ccad","deviceId":"4197","command":"","commandArgs":"","x":1190,"y":480,"wires":[[]]},{"id":"68c6a6762f95e59c","type":"change","z":"387332bd262639e8","name":"off","rules":[{"t":"set","p":"command","pt":"msg","to":"off","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1035,"y":520,"wires":[["f823567d37b92354"]],"l":false},{"id":"662851c4.3ccad","type":"hubitat config","name":"HubitatS","usetls":false,"host":"192.168.1.36","port":"80","appId":"4489","nodeRedServer":"http://192.168.1.4:1880","webhookPath":"/hubitat/webhook2","autoRefresh":true,"useWebsocket":false,"colorEnabled":true,"color":"#51b8f0"},{"id":"a22e0ea9.276dc8","type":"hubitat config","name":"HubitatM","usetls":false,"host":"192.168.1.46","port":"80","appId":"1522","nodeRedServer":"http://192.168.1.4:1880","webhookPath":"/hubitat/webhook","autoRefresh":true,"useWebsocket":false,"colorEnabled":true,"color":"#5dd049"}]
3 Likes

Here's my much more hasty, unoptimized, and likely fraught with errors take! :wink:

Note: I changed "hallSwitchDisable" to "hallMotionDisable" for clarity..

edit: yep, had some glitches.. updated and switched around a bit.

2 Likes

Here is another sample - I have a closet light that is triggered by a contact sensor or a motion sensor.

The flow is below:

[{"id":"7a679ded.632d3c","type":"group","z":"68be3b45.fb2464","style":{"stroke":"#999999","stroke-opacity":"1","fill":"none","fill-opacity":"1","label":true,"label-position":"nw","color":"#a4a4a4"},"nodes":["223f8f81.d081b","1cbbb6.5d09944b","bca58ba8.42b388","8fd5ceab.e22d8","3dad0999.738496","5c95557c.f2fa1c","efba6397.f64548","5fe04c4b.58c7cc","4f23536f.10b63c","8a24fd46.088ec8","69bba408.237eb4","9cc3f20a.e27598","7147e912.9d9508","a238abb2.ec5cc8","fa0a6e24.bc8568","c89fcf93.59d198","4bfaf310.5170a4"],"x":113.1666374206543,"y":4309.500192642212,"w":1495.0001106262207,"h":350.9998073577881},{"id":"223f8f81.d081b","type":"hubitat device","z":"68be3b45.fb2464","g":"7a679ded.632d3c","deviceLabel":"Bedroom Closet Motion","name":"","server":"2e073620.1f85c2","deviceId":"716","attribute":"motion","sendEvent":true,"x":266.6666564941406,"y":4535.6669921875,"wires":[["1cbbb6.5d09944b"]]},{"id":"1cbbb6.5d09944b","type":"switch","z":"68be3b45.fb2464","g":"7a679ded.632d3c","name":"Motion (Y/N)?","property":"payload.currentValue","propertyType":"msg","rules":[{"t":"eq","v":"active","vt":"str"},{"t":"eq","v":"inactive","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":482.6666488647461,"y":4535.4169664382935,"wires":[["bca58ba8.42b388","8fd5ceab.e22d8"],["3dad0999.738496"]],"outputLabels":["Active","Inactive"]},{"id":"bca58ba8.42b388","type":"change","z":"68be3b45.fb2464","g":"7a679ded.632d3c","name":"Reset Delay","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":647.6666107177734,"y":4474.666991233826,"wires":[["efba6397.f64548"]]},{"id":"8fd5ceab.e22d8","type":"hubitat device","z":"68be3b45.fb2464","g":"7a679ded.632d3c","deviceLabel":"Pantry Light","name":"Closet Light State","server":"2e073620.1f85c2","deviceId":"708","attribute":"switch","sendEvent":false,"x":877.3333129882812,"y":4528.33349609375,"wires":[["5fe04c4b.58c7cc"]]},{"id":"3dad0999.738496","type":"delay","z":"68be3b45.fb2464","g":"7a679ded.632d3c","name":"Delay 5 minute","pauseType":"delay","timeout":"5","timeoutUnits":"minutes","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":666.9166717529297,"y":4587.916993141174,"wires":[["8a24fd46.088ec8"]]},{"id":"5c95557c.f2fa1c","type":"switch","z":"68be3b45.fb2464","g":"7a679ded.632d3c","name":"Turned off manually?","property":"payload.type = 'physical'  and payload.currentValue = 'off'","propertyType":"jsonata","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":417.3332977294922,"y":4475,"wires":[["bca58ba8.42b388"]]},{"id":"efba6397.f64548","type":"link out","z":"68be3b45.fb2464","g":"7a679ded.632d3c","name":"Reset Delay (C) - Out","links":["4f23536f.10b63c"],"x":848.0832977294922,"y":4474.666991233826,"wires":[],"l":true},{"id":"5fe04c4b.58c7cc","type":"switch","z":"68be3b45.fb2464","g":"7a679ded.632d3c","name":"Light Off?","property":"payload.currentValue","propertyType":"msg","rules":[{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":1073.9999313354492,"y":4528.416991233826,"wires":[["9cc3f20a.e27598"]]},{"id":"4f23536f.10b63c","type":"link in","z":"68be3b45.fb2464","g":"7a679ded.632d3c","name":"Reset Delay (C) - In","links":["efba6397.f64548","4370e12d.0acc18"],"x":461.0832939147949,"y":4588.166940689087,"wires":[["3dad0999.738496"]],"l":true},{"id":"8a24fd46.088ec8","type":"hubitat device","z":"68be3b45.fb2464","g":"7a679ded.632d3c","deviceLabel":"Pantry Light","name":"Closet Light State","server":"2e073620.1f85c2","deviceId":"708","attribute":"switch","sendEvent":false,"x":881.6666870117188,"y":4587.33349609375,"wires":[["7147e912.9d9508"]]},{"id":"69bba408.237eb4","type":"hubitat device","z":"68be3b45.fb2464","g":"7a679ded.632d3c","deviceLabel":"Bedroom Closet Switch","name":"","server":"2e073620.1f85c2","deviceId":"708","attribute":"switch","sendEvent":true,"x":267.3333435058594,"y":4416.0000076293945,"wires":[["5c95557c.f2fa1c"]]},{"id":"9cc3f20a.e27598","type":"change","z":"68be3b45.fb2464","g":"7a679ded.632d3c","name":"Turn On","rules":[{"t":"set","p":"command","pt":"msg","to":"on","tot":"str"},{"t":"delete","p":"payload","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1250.416748046875,"y":4528.9169921875,"wires":[["a238abb2.ec5cc8"]]},{"id":"7147e912.9d9508","type":"switch","z":"68be3b45.fb2464","g":"7a679ded.632d3c","name":"Light On?","property":"payload.currentValue","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":1072.6666259765625,"y":4587.33349609375,"wires":[["fa0a6e24.bc8568"]]},{"id":"a238abb2.ec5cc8","type":"hubitat command","z":"68be3b45.fb2464","g":"7a679ded.632d3c","deviceLabel":"Bedroom Closet Switch","name":"","server":"2e073620.1f85c2","deviceId":"708","command":"","commandArgs":"","x":1472.166748046875,"y":4554.4169921875,"wires":[[]]},{"id":"fa0a6e24.bc8568","type":"change","z":"68be3b45.fb2464","g":"7a679ded.632d3c","name":"Turn Off","rules":[{"t":"set","p":"command","pt":"msg","to":"off","tot":"str"},{"t":"delete","p":"reset","pt":"msg"},{"t":"delete","p":"payload","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1247.9167022705078,"y":4587.4169921875,"wires":[["a238abb2.ec5cc8"]]},{"id":"c89fcf93.59d198","type":"comment","z":"68be3b45.fb2464","g":"7a679ded.632d3c","name":"Change Log","info":"2021-09-24: Created\n2021-09-24: Combined logic for turning off/on based on motion. Also added link from light turning on with contact sensor\n2021-10-10: Added steps to delete msg.payload and msg.reset when sending msg.command\n2021-11-27: Added code to handle case where switch is turned of manually","x":217.41664123535156,"y":4619.5,"wires":[]},{"id":"4bfaf310.5170a4","type":"comment","z":"68be3b45.fb2464","g":"7a679ded.632d3c","name":"Closet Light: Turn on/off if motion detected","info":"","x":309.1666374206543,"y":4350.500192642212,"wires":[]},{"id":"2e073620.1f85c2","type":"hubitat config","name":"Hubitat_Prod","usetls":false,"host":"192.168.1.113","port":"80","appId":"225","nodeRedServer":"http://192.168.1.82:1880","webhookPath":"/hubitat/webhook_","autoRefresh":true,"useWebsocket":false},{"id":"f7e698db.8e7188","type":"group","z":"68be3b45.fb2464","style":{"stroke":"#999999","stroke-opacity":"1","fill":"none","fill-opacity":"1","label":true,"label-position":"nw","color":"#a4a4a4"},"nodes":["bae51b4b.a976b8","1caffd07.c1a45b","bfcb6579.92d99","4c92f5e1.c8c30c","39a9f2d6.51cd46","522336b7.9ef018","a2d66cc7.60dad","4370e12d.0acc18"],"x":113,"y":4033.6670303344727,"w":934.9999694824219,"h":222.33349609375},{"id":"bae51b4b.a976b8","type":"hubitat device","z":"68be3b45.fb2464","g":"f7e698db.8e7188","deviceLabel":"Bedroom Closet Contact","name":"","server":"2e073620.1f85c2","deviceId":"710","attribute":"contact","sendEvent":true,"x":254,"y":4135.6669921875,"wires":[["1caffd07.c1a45b"]]},{"id":"1caffd07.c1a45b","type":"switch","z":"68be3b45.fb2464","g":"f7e698db.8e7188","name":"Open or Closed?","property":"payload.currentValue","propertyType":"msg","rules":[{"t":"eq","v":"open","vt":"str"},{"t":"eq","v":"closed","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":497,"y":4135.6669921875,"wires":[["bfcb6579.92d99"],["4c92f5e1.c8c30c"]]},{"id":"bfcb6579.92d99","type":"change","z":"68be3b45.fb2464","g":"f7e698db.8e7188","name":"Turn On","rules":[{"t":"set","p":"command","pt":"msg","to":"setLevel","tot":"str"},{"t":"set","p":"arguments","pt":"msg","to":"99,0","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":690,"y":4106.6669921875,"wires":[["39a9f2d6.51cd46","4370e12d.0acc18"]]},{"id":"4c92f5e1.c8c30c","type":"change","z":"68be3b45.fb2464","g":"f7e698db.8e7188","name":"Turn Off","rules":[{"t":"set","p":"command","pt":"msg","to":"off","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":691.333251953125,"y":4168.00048828125,"wires":[["4370e12d.0acc18"]]},{"id":"39a9f2d6.51cd46","type":"hubitat command","z":"68be3b45.fb2464","g":"f7e698db.8e7188","deviceLabel":"Hall Closet","name":"Bedroom Closet Light","server":"2e073620.1f85c2","deviceId":"708","command":"","commandArgs":"","x":911.9999694824219,"y":4107.6669921875,"wires":[[]]},{"id":"522336b7.9ef018","type":"comment","z":"68be3b45.fb2464","g":"f7e698db.8e7188","name":"Bedroom Closet Light: Turn on/off when door open/closed","info":"","x":359,"y":4074.6670303344727,"wires":[]},{"id":"a2d66cc7.60dad","type":"comment","z":"68be3b45.fb2464","g":"f7e698db.8e7188","name":"Change Log","info":"2021-09-21: Created\n2021-09-22: Changed on command to setLevel and 99,0 to handle if swtich was dimmed to 0 manually\n2021-09-25: Changed to turn off light 5 minutes after closet door is closed if no motion.","x":217.33331298828125,"y":4215.000526428223,"wires":[]},{"id":"4370e12d.0acc18","type":"link out","z":"68be3b45.fb2464","g":"f7e698db.8e7188","name":"Reset Delay (C) - Out","links":["4f23536f.10b63c"],"x":901.6665954589844,"y":4169.6669921875,"wires":[],"l":true}]

Hope this helps.

2 Likes

Yeah I skimmed too quickly and did not include the "contact sensor" bit.. sorry! :man_facepalming:

I wonder why you would need both for a closet though - I have motion sensors and a routine similar to the above. Contact sensor isn't necessary for my use-case unless I was worried about a door remaining open or enforcing lights off on a door close.

Thanks, I appreciate everyones thoughts on this, these give me some clarity on how to do it.

1 Like

It's to prevent the lights from turning off if someone is in the closet (walk in closet) and the door is closed. Also, there is a slight delay in the motion sensor registering motion but the contact sensor (on closet door open) reacts almost immediately.

EDIT: That was for my use case :wink: - I would never hear the end of it if the lights turned off when my wife was in there!

2 Likes

I wouldn't either (my wife not yours haha) she's already skeptical about my "experiments" - I added an extra delay in turning it off and have the motion sensor (also hacked for usb power!) facing back toward the door on a high shelf - this was before I discovered the ceiling style mounted devices like NYCE which probably would work great as well.

1 Like

I don't remember if it was here or elsewhere, but I saw something on these forums about setting the porch light to a different color for the holiday season.

I wanted a routine to set the color to red/green every 15 minutes, and to switch between the two of them. I set a boolean in the flow representing the color, and switch between red and green. I also wanted it to behave during the night so it's not too flashy all night long. The rest of the night the bulb gets its color assigned elsewhere.

Here's what I came up with. Enjoy!

[{"id":"b8dd13b1.797cb","type":"change","z":"f9337f21.0eab78","name":"Turn Off","rules":[{"t":"set","p":"command","pt":"msg","to":"off","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":460,"y":2380,"wires":[["89753df20ca7d578"]]},{"id":"5c9841f.19b74c","type":"change","z":"f9337f21.0eab78","name":"Turn On","rules":[{"t":"set","p":"command","pt":"msg","to":"on","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":460,"y":2340,"wires":[["89753df20ca7d578"]]},{"id":"1fbcdc78.00e81c","type":"comment","z":"f9337f21.0eab78","name":"Porch light","info":"","x":100,"y":2140,"wires":[]},{"id":"30aade80.91cb42","type":"within-time-switch","z":"f9337f21.0eab78","name":"sunset - sunrise","positionConfig":"96c207ac.2237a8","startTime":"sunsetEnd","startTimeType":"pdsTime","startOffset":0,"startOffsetType":"none","startOffsetMultiplier":60000,"endTime":"sunriseStart","endTimeType":"pdsTime","endOffset":0,"endOffsetType":"none","endOffsetMultiplier":60000,"timeRestrictions":"","timeRestrictionsType":"none","timeDays":"*","timeOnlyOddDays":false,"timeOnlyEvenDays":false,"timeOnlyOddWeeks":false,"timeOnlyEvenWeeks":false,"timeMonths":"*","timedatestart":"","timedateend":"","propertyStart":"","propertyStartType":"none","propertyStartCompare":"true","propertyStartThreshold":"","propertyStartThresholdType":"num","startTimeAlt":"","startTimeAltType":"entered","startOffsetAlt":0,"startOffsetAltType":"none","startOffsetAltMultiplier":60000,"propertyEnd":"","propertyEndType":"none","propertyEndCompare":"true","propertyEndThreshold":"","propertyEndThresholdType":"num","endTimeAlt":"","endTimeAltType":"entered","endOffsetAlt":0,"endOffsetAltType":"none","endOffsetAltMultiplier":60000,"withinTimeValue":"","withinTimeValueType":"msgInput","outOfTimeValue":"","outOfTimeValueType":"msgInput","tsCompare":"0","x":240,"y":2360,"wires":[["5c9841f.19b74c"],["b8dd13b1.797cb"]]},{"id":"76fddf4.66e0da","type":"inject","z":"f9337f21.0eab78","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":95,"y":2360,"wires":[["30aade80.91cb42"]],"l":false},{"id":"89ce2107.6a1858","type":"link in","z":"f9337f21.0eab78","name":"","links":["2837495c.ae2176"],"x":235,"y":2320,"wires":[["5c9841f.19b74c"]]},{"id":"35f56d8f.e1d64a","type":"link in","z":"f9337f21.0eab78","name":"","links":["4e636188.7f332"],"x":235,"y":2400,"wires":[["b8dd13b1.797cb"]]},{"id":"ba0630734df9353f","type":"hubitat command","z":"f9337f21.0eab78","deviceLabel":"Porch Bulb","name":"","server":"252d4ef4.c14b6a","deviceId":"66","command":"","commandArgs":"","x":690,"y":2360,"wires":[[]]},{"id":"2c07bcd4127d212c","type":"inject","z":"f9337f21.0eab78","name":"Every 15 minutes","props":[{"p":"payload","v":"","vt":"date"},{"p":"topic","v":"","vt":"string"}],"repeat":"900","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":170,"y":2240,"wires":[["ed59489e0b1aba05"]]},{"id":"89753df20ca7d578","type":"delay","z":"f9337f21.0eab78","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":575,"y":2360,"wires":[["ba0630734df9353f"]],"l":false},{"id":"ee0bd27a6442d9c0","type":"change","z":"f9337f21.0eab78","name":"is_red := false","rules":[{"t":"set","p":"is_red","pt":"flow","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":800,"y":2220,"wires":[["42ed4e7930637962"]]},{"id":"c63d476daa70e7fc","type":"switch","z":"f9337f21.0eab78","name":"is_red?","property":"is_red","propertyType":"flow","rules":[{"t":"true"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":620,"y":2240,"wires":[["ee0bd27a6442d9c0"],["1657120c75a44639"]]},{"id":"1657120c75a44639","type":"change","z":"f9337f21.0eab78","name":"is_red := true","rules":[{"t":"set","p":"is_red","pt":"flow","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":790,"y":2260,"wires":[["4505442f74bfd3ab"]]},{"id":"42ed4e7930637962","type":"change","z":"f9337f21.0eab78","name":"Make Green","rules":[{"t":"set","p":"arguments","pt":"msg","to":"{\"hue\": 31, \"saturation\": 55, \"level\": 100}","tot":"json"},{"t":"set","p":"arguments","pt":"msg","to":"$string(msg.arguments)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":990,"y":2220,"wires":[["338150d80eb38946"]]},{"id":"4505442f74bfd3ab","type":"change","z":"f9337f21.0eab78","name":"Make Red","rules":[{"t":"set","p":"arguments","pt":"msg","to":"{\"hue\": 1, \"saturation\": 64, \"level\": 100}","tot":"json"},{"t":"set","p":"arguments","pt":"msg","to":"$string(msg.arguments)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":990,"y":2260,"wires":[["338150d80eb38946"]]},{"id":"338150d80eb38946","type":"delay","z":"f9337f21.0eab78","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":1115,"y":2240,"wires":[["4abace46d88d5d82"]],"l":false},{"id":"4abace46d88d5d82","type":"hubitat command","z":"f9337f21.0eab78","deviceLabel":"Porch Bulb","name":"","server":"252d4ef4.c14b6a","deviceId":"66","command":"setColor","commandArgs":"","x":1230,"y":2240,"wires":[[]]},{"id":"7bbc68f86666af49","type":"inject","z":"f9337f21.0eab78","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":895,"y":2160,"wires":[["42ed4e7930637962"]],"l":false},{"id":"23abbe03a5af6625","type":"inject","z":"f9337f21.0eab78","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":895,"y":2320,"wires":[["4505442f74bfd3ab"]],"l":false},{"id":"ed59489e0b1aba05","type":"within-time-switch","z":"f9337f21.0eab78","name":"","positionConfig":"96c207ac.2237a8","startTime":"sunsetEnd","startTimeType":"pdsTime","startOffset":0,"startOffsetType":"none","startOffsetMultiplier":60000,"endTime":"23:00","endTimeType":"entered","endOffset":0,"endOffsetType":"none","endOffsetMultiplier":60000,"timeRestrictions":"","timeRestrictionsType":"none","timeDays":"*","timeOnlyOddDays":false,"timeOnlyEvenDays":false,"timeOnlyOddWeeks":false,"timeOnlyEvenWeeks":false,"timeMonths":"*","timedatestart":"","timedateend":"","propertyStart":"","propertyStartType":"none","propertyStartCompare":"true","propertyStartThreshold":"","propertyStartThresholdType":"num","startTimeAlt":"","startTimeAltType":"entered","startOffsetAlt":0,"startOffsetAltType":"none","startOffsetAltMultiplier":60000,"propertyEnd":"","propertyEndType":"none","propertyEndCompare":"true","propertyEndThreshold":"","propertyEndThresholdType":"num","endTimeAlt":"","endTimeAltType":"entered","endOffsetAlt":0,"endOffsetAltType":"none","endOffsetAltMultiplier":60000,"withinTimeValue":"","withinTimeValueType":"msgInput","outOfTimeValue":"","outOfTimeValueType":"msgInput","tsCompare":"0","x":390,"y":2240,"wires":[["c63d476daa70e7fc"],[]]},{"id":"96c207ac.2237a8","type":"position-config","name":"Home","isValide":"true","longitude":"0","latitude":"0","angleType":"deg","timeZoneOffset":"99","timeZoneDST":"0","stateTimeFormat":"3","stateDateFormat":"12"},{"id":"252d4ef4.c14b6a","type":"hubitat config","name":"Hubitat","usetls":false,"host":"172.16.0.5","port":"80","appId":"14","nodeRedServer":"http://172.16.0.25:1880","webhookPath":"/hubitat/webhook","autoRefresh":false,"useWebsocket":false,"colorEnabled":false,"color":"#000000"}]
4 Likes

Thanks for the ideas!!!

I'd like to offer my simple subflow that can handle a sequence of commands... You can either pass one message to the subflow with RUN_ALL set to "true" and it will automatically progress through the list of commands returning a joined result array message OR multiple times with RUN_ALL set to "false" which allows a step by step approach, with each new message progressing though the list and rolling over to the first command.

This is just the subflow with a bogus HE Config..

Simple Command Sequencer - heSequence (updated)

[{"id":"bd405dcfd9263255","type":"subflow","name":"heSequence","category":"","in":[{"x":50,"y":30,"wires":[{"id":"6ec468a9c0b0abf9"}]}],"out":[{"x":1140,"y":60,"wires":[{"id":"faa1f62b019404a1","port":1},{"id":"3b80fac98ba1259c","port":0}]}],"env":[{"name":"TOPIC","type":"str","value":"heSequence"},{"name":"COMMANDS","type":"json","value":"[{\"name\":\"green\",\"deviceId\":\"1773\",\"command\":\"setColor\",\"arguments\":{\"hue\":36,\"saturation\":100,\"level\":50},\"delaySecs\":5},{\"name\":\"red\",\"deviceId\":\"1773\",\"command\":\"setColor\",\"arguments\":{\"hex\":\"FF0000\"},\"delaySecs\":5}]"},{"name":"RUN_ALL","type":"bool","value":"true"}],"meta":{},"color":"#DDAA99","status":{"x":1140,"y":280,"wires":[{"id":"a840e3a34d7b74c5","port":0}]}},{"id":"be25f6810307808d","type":"function","z":"bd405dcfd9263255","name":"set device command","func":"//commands = msg.payload;\ntopic = env.get(\"TOPIC\");\ncommands = env.get(\"COMMANDS\");\n//node.warn(commands);\n\nvar len = commands.length;\n\nvar current = flow.get(\"current\");\nif (current === undefined ){\n    current = 0;\n}\nif( current < (len-1)) {\n    current++;\n} else {\n    current = 0;\n}\nflow.set(\"current\",current);\n\nvar command = commands[current];\n\nvar retMsg = {\n    \"topic\": env.get(\"TOPIC\")\n    ,\"name\": command.name\n    ,\"command\": command.command\n    ,\"delay\": command.delaySecs\n    ,\"deviceId\": command.deviceId\n}\n\nif (command.arguments!==\"\") {\n    var val = typeof command.arguments == \"object\" ? JSON.stringify(command.arguments) : command.arguments;\n    retMsg.arguments = val;\n}\n\nflow.set(\"statusMsg\", retMsg);\n\nreturn retMsg;\n\n/*\nvar keys = Object.keys(command);\nconst ignore = new Set([\"delaySecs\",\"name\",\"deviceId\"]);\n\nfor (var i=0;i<keys.length;i++){\n    var key = keys[i];\n    if( !ignore.has(key) ){\n\n        if (command[key]===\"\") {\n            retMsg = {\n              \"topic\": topic\n              ,\"command\": key\n              , \"payload\": \"\"\n              ,\"deviceId\": command.deviceId\n              ,\"delay\": delay\n            } \n        } else {\n            var val = typeof command[key] == \"object\" ? JSON.stringify(command[key]) : command[key];\n            \n            retMsg = {\n              \"topic\": topic\n              ,\"command\": key\n              ,\"arguments\": val\n              , \"payload\": \"\"\n              ,\"deviceId\": command.deviceId\n              ,\"delay\": delay\n            } \n            \n        }\n        \n        flow.set(\"statusMsg\", retMsg);\n        node.send(retMsg);\n        node.done();\n    }\n}\n\nreturn retMsg;\n*/\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":380,"y":140,"wires":[["eb6265f63788fd28"]]},{"id":"a840e3a34d7b74c5","type":"change","z":"bd405dcfd9263255","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"\t($flowContext(\"current\") + 1) & \" of \" & $count($env(\"COMMANDS\")) & \" - \" & $flowContext(\"statusMsg\").name\t& \" / \" & payload\t","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":920,"y":320,"wires":[[]]},{"id":"88ee93fe62787abb","type":"stoptimer-varidelay","z":"bd405dcfd9263255","duration":"5","durationType":"num","units":"Second","payloadtype":"num","payloadval":"0","name":"","reporting":"every_second","persist":false,"ignoretimerpass":false,"x":700,"y":220,"wires":[["faa1f62b019404a1"],[],["a840e3a34d7b74c5"]]},{"id":"faa1f62b019404a1","type":"switch","z":"bd405dcfd9263255","name":"$RUN_ALL?","property":"$env(\"RUN_ALL\")","propertyType":"jsonata","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":930,"y":140,"wires":[["99f2e3e687f1528d"],[]]},{"id":"99f2e3e687f1528d","type":"switch","z":"bd405dcfd9263255","name":"Not Done?","property":"( $count($env(\"COMMANDS\")) != ($flowContext(\"current\") + 1))\t","propertyType":"jsonata","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":350,"y":60,"wires":[["be25f6810307808d","0fd3311ee7ba1738"],["0fd3311ee7ba1738"]]},{"id":"0fd3311ee7ba1738","type":"join","z":"bd405dcfd9263255","name":"","mode":"auto","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":"false","timeout":"","count":"","reduceRight":false,"x":670,"y":60,"wires":[["3b80fac98ba1259c"]]},{"id":"eb6265f63788fd28","type":"hubitat command","z":"bd405dcfd9263255","deviceLabel":"","name":"","server":"623daead.b1d2b","deviceId":"","command":"","commandArgs":"","x":680,"y":140,"wires":[["78776570158e1106"]]},{"id":"78776570158e1106","type":"function","z":"bd405dcfd9263255","name":"set delay = flow.statusMsg.delay","func":"\nvar statusMsg = flow.get(\"statusMsg\");\nmsg.delay = statusMsg.delay;\n\nvar runAll = env.get(\"RUN_ALL\");\nvar current = flow.get(\"current\");\nvar key = current.toString() + \" - \" + statusMsg.name;\n\nif(runAll) {\n    \n    msg.payload = {\n        \"name\": statusMsg.name\n        ,\"deviceId\": msg.deviceId\n        ,\"command\": msg.command\n        ,\"arguments\": msg.arguments\n        ,\"response\": msg.response\n        ,\"requestCommand\": msg.requestCommand\n        ,\"requestArguments\": msg.requestArguments\n    }\n    \n    msg.parts = {\n        \"id\": env.get(\"TOPIC\"),\n        \"index\": current,\n        \"count\": env.get(\"COMMANDS\").length,\n        \"type\":\"object\",\n        \"ch\":\"\",\n        \"key\": key,\n        \"len\":\"\"\n    }\n}\n\n\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":410,"y":220,"wires":[["88ee93fe62787abb"]]},{"id":"3b80fac98ba1259c","type":"change","z":"bd405dcfd9263255","name":"cleanup msg","rules":[{"t":"delete","p":"command","pt":"msg"},{"t":"delete","p":"deviceId","pt":"msg"},{"t":"delete","p":"arguments","pt":"msg"},{"t":"delete","p":"response","pt":"msg"},{"t":"delete","p":"requestCommand","pt":"msg"},{"t":"delete","p":"requestArguments","pt":"msg"},{"t":"delete","p":"delay","pt":"msg"},{"t":"delete","p":"_timerpass","pt":"msg"},{"t":"delete","p":"name","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":930,"y":60,"wires":[[]]},{"id":"6ec468a9c0b0abf9","type":"switch","z":"bd405dcfd9263255","name":"payload != stop","property":"payload != \"stop\"","propertyType":"jsonata","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":120,"y":320,"wires":[["be25f6810307808d"],["014b9b4e013257f2"]]},{"id":"014b9b4e013257f2","type":"change","z":"bd405dcfd9263255","name":"","rules":[{"t":"set","p":"current","pt":"flow","to":"-1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":320,"wires":[["88ee93fe62787abb"]]},{"id":"623daead.b1d2b","type":"hubitat config","name":"YourHEHub","usetls":false,"host":"[your HE ip]","port":"80","appId":"[your appId]","nodeRedServer":"http://[your nr ip]:1880","webhookPath":"/hubitat/webhook_","autoRefresh":true,"useWebsocket":false,"colorEnabled":false,"color":"#000000"}]

Warning: still futzing around and there may be a bug or two left. Also notice that in the arguments field it handles the conversion to a JSON string.. When doing a "RUN_ALL" a joined array of command results is returned...

Further Notes:
Forgot to mention - this requires the node-red-contrib-stoptimer-varidelay node - I am using that instead of the "delay" node. Also to stop the the process midway send a msg.payload = "stop".

1 Like

Hoping for some help and direction with a flow and this seems like a good place to ask. I've gone to NodeRED for "Alexa aware" responses, i.e. responses from the Alexa you're speaking to and commands sent to appropriate devices in the same room. What I'd like to do in this situation is ask Alexa "which door is open" and have her respond with a canned answer (the back door is open), based on contact sensor status in hubitat. What's the best/easiest way to have NR check hubitat sensor status and route to the appropriate Alexa Speak Routine. I can handle the speaking part but I haven't used device nodes to route based on status yet. Thanks in advance.

That should be fairly easy to accomplish...

You'd need one of the Alexa nodes.. I use this one:

Then you would need to attach to your Amazon account and give permission in order to set up the configuration. Note: it will make you browse to a specific site on the NR server in order to do the Amazon login.. you might have to do some creative tunneling.

Once done, in Alexa you create a routine with the phrase like "which doors are open?" and have it do a "wait" action for like 5 seconds - nothing else is needed.

On the Node-RED side it's just a matter of looking for a particular phrase using the Alexa Event Node and "msg.payload.description.summary" and then testing the sensors to see which one(s) are active and speak the result using the Alexa Routine node.

1 Like