Node Red - Automate LZW45 pixel effect calculations via Subflow

That’s so weird, after testing it all morning mine started returning the same error haha. I changed up how it was done, and this one appears to be working. Let me know if this one works for you as well, if not I’ll look back into it :slight_smile:

It could be related to that update issue, I’m having the same problem on my end. That notification is driving me crazy!

[{"id":"9f38d792.8a5038","type":"subflow","name":"Set Pixel Effect","info":"","category":"","in":[{"x":120,"y":240,"wires":[{"id":"a1d83d1d.12d09"}]}],"out":[{"x":1220,"y":700,"wires":[{"id":"da77dc7.f17462","port":0},{"id":"ee825fe8.364d7","port":0},{"id":"ee825fe8.364d7","port":1}]}],"env":[{"name":"single_or_group","type":"str","value":"single"},{"name":"device_id","type":"str","value":""},{"name":"brightness","type":"num","value":""},{"name":"pixel_effect","type":"str","value":""},{"name":"total_time","type":"str","value":"30"},{"name":"measure_time","type":"str","value":"seconds"}],"meta":{},"color":"#C7E9C0"},{"id":"280c685d.6858b8","type":"function","z":"9f38d792.8a5038","name":"Throw Value Error","func":"throw(\"Invalid Brightness Intensity. Value must be a number between 1 and 99.\")\nreturn msg;","outputs":0,"noerr":0,"initialize":"","finalize":"","x":330,"y":600,"wires":[]},{"id":"4ffd875e.67b128","type":"function","z":"9f38d792.8a5038","name":"Throw Color Error","func":"throw(\"Invalid Pixel Effect. Value must be a number between 1 and 46.\")\nreturn msg;","outputs":0,"noerr":0,"initialize":"","finalize":"","x":650,"y":600,"wires":[]},{"id":"2237c494.10057c","type":"switch","z":"9f38d792.8a5038","name":"Check if Pixel Effect choice is valid","property":"pixel_effect","propertyType":"env","rules":[{"t":"btwn","v":"1","vt":"num","v2":"45","v2t":"num"},{"t":"eq","v":"random","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":3,"x":600,"y":540,"wires":[["13445159.b7ca9f"],["13445159.b7ca9f"],["4ffd875e.67b128"]]},{"id":"9d164d05.2a9a8","type":"switch","z":"9f38d792.8a5038","name":"Check if brightness is valid","property":"brightness","propertyType":"env","rules":[{"t":"btwn","v":"1","vt":"num","v2":"99","v2t":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":300,"y":540,"wires":[["2237c494.10057c"],["280c685d.6858b8"]]},{"id":"13445159.b7ca9f","type":"function","z":"9f38d792.8a5038","name":"Calculate pixel effect","func":"var pixelEffect = env.get(\"pixel_effect\");\nvar bright = parseInt(env.get(\"brightness\"));\nmsg.value = {};\n\nif (pixelEffect === 'random') {\n    msg.value = Math.floor(Math.random() * 45) + 1;\n    msg.bright = parseInt(bright);\n} else {\n    msg.value = parseInt(pixelEffect);\n    msg.bright = parseInt(bright);\n}\n\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":880,"y":540,"wires":[["3326de72.c17d12"]]},{"id":"4b770613.d72eb8","type":"comment","z":"9f38d792.8a5038","name":"Pull Pixel Effect, Brightness Values and Node Information","info":"","x":690,"y":100,"wires":[]},{"id":"813d369a.54f748","type":"ha-get-entities","z":"9f38d792.8a5038","server":"497693ef.d5e6bc","name":"Get all LED Strips","rules":[{"property":"entity_id","logic":"in_group","value":"group","valueType":"msg"}],"output_type":"array","output_empty_results":false,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":810,"y":400,"wires":[["665443b8.102d7c"]]},{"id":"665443b8.102d7c","type":"split","z":"9f38d792.8a5038","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":990,"y":400,"wires":[["b9ef34bd.527538"]]},{"id":"b9ef34bd.527538","type":"delay","z":"9f38d792.8a5038","name":"","pauseType":"rate","timeout":"2","timeoutUnits":"seconds","rate":"1","nbRateUnits":"0.25","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1150,"y":400,"wires":[["b10921b9.7f6a6"]]},{"id":"a1d83d1d.12d09","type":"change","z":"9f38d792.8a5038","name":"Set msg.singleorgroup","rules":[{"t":"set","p":"singleorgroup","pt":"msg","to":"{}","tot":"json"},{"t":"set","p":"singleorgroup","pt":"msg","to":"single_or_group","tot":"env"}],"action":"","property":"","from":"","to":"","reg":false,"x":280,"y":240,"wires":[["10123f23.1e4a41"]]},{"id":"aea70daa.c304f","type":"switch","z":"9f38d792.8a5038","name":"Is this a single node or group?","property":"singleorgroup","propertyType":"msg","rules":[{"t":"eq","v":"single","vt":"str"},{"t":"eq","v":"group","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":3,"x":310,"y":380,"wires":[["f66a9193.bf6fc"],["5656b264.7cc5bc"],["2fa25c42.8b3464"]]},{"id":"2fa25c42.8b3464","type":"function","z":"9f38d792.8a5038","name":"Throw node error","func":"throw(\"Invalid selection for single or group. Valid entries include either single, or group. You provided: \" + msg.singleorgroup)\nreturn msg;","outputs":0,"noerr":0,"initialize":"","finalize":"","x":350,"y":440,"wires":[]},{"id":"10123f23.1e4a41","type":"function","z":"9f38d792.8a5038","name":"Correct value for singleorgroup if needed","func":"msg.singleorgroup = msg.singleorgroup.trim().replace(/\\ /g, \"_\").toLowerCase();\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":580,"y":240,"wires":[["6f4b7998.7b1528"]]},{"id":"f66a9193.bf6fc","type":"change","z":"9f38d792.8a5038","name":"Set device ID","rules":[{"t":"set","p":"node","pt":"msg","to":"{}","tot":"json"},{"t":"set","p":"node","pt":"msg","to":"device_id","tot":"env"}],"action":"","property":"","from":"","to":"","reg":false,"x":590,"y":340,"wires":[["50eb1f81.3e079"]]},{"id":"50eb1f81.3e079","type":"switch","z":"9f38d792.8a5038","name":"Make sure there's a device defined","property":"node","propertyType":"msg","rules":[{"t":"istype","v":"string","vt":"string"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":840,"y":340,"wires":[["9d164d05.2a9a8"],["76a8ddca.a80a94"]]},{"id":"76a8ddca.a80a94","type":"function","z":"9f38d792.8a5038","name":"Throw device error","func":"throw(\"device_id cannot be 0 or blank if single_or_group is defined as single. Please either add in a device_id or change single_or_group to group and try again. Value provided was: \" + msg.node)\nreturn msg;","outputs":0,"noerr":0,"initialize":"","finalize":"","x":1170,"y":340,"wires":[]},{"id":"b10921b9.7f6a6","type":"change","z":"9f38d792.8a5038","name":"Set entity ID","rules":[{"t":"set","p":"node","pt":"msg","to":"{}","tot":"json"},{"t":"set","p":"node","pt":"msg","to":"payload.entity_id","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1330,"y":400,"wires":[["9d164d05.2a9a8"]]},{"id":"3326de72.c17d12","type":"api-call-service","z":"9f38d792.8a5038","name":"ZWaveJS Set Pixel Effect","server":"497693ef.d5e6bc","version":1,"debugenabled":false,"service_domain":"zwave_js","service":"bulk_set_partial_config_parameters","entityId":"","data":"{\t   \"entity_id\":msg.node,\t   \"parameter\":31,\t    \"value\": {\t        \"0xff\": msg.value,\t        \"0x7f00\": msg.brightness\t    }}","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1130,"y":540,"wires":[["ee825fe8.364d7"]]},{"id":"33cf76bb.74ee2a","type":"delay","z":"9f38d792.8a5038","name":"Configurable Delay Node","pauseType":"delayv","timeout":"30","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":830,"y":740,"wires":[["da77dc7.f17462"]]},{"id":"5656b264.7cc5bc","type":"change","z":"9f38d792.8a5038","name":"Set msg.group","rules":[{"t":"set","p":"group","pt":"msg","to":"{}","tot":"json"},{"t":"set","p":"group","pt":"msg","to":"device_id","tot":"env"}],"action":"","property":"","from":"","to":"","reg":false,"x":600,"y":400,"wires":[["813d369a.54f748"]]},{"id":"708e83bd.f9c7dc","type":"function","z":"9f38d792.8a5038","name":"Calculate light timeout amount","func":"var amount = parseInt(env.get(\"total_time\"));\n\nvar measure = msg.measuretime;\n\nmsg.delay = {};\n\nif (measure === 'seconds') {\n\n    msg.delay = parseInt(amount);\n\n} else if (measure === 'minutes') { //convert minutes to seconds\n\n    if (amount === 1) {\n        msg.delay = parseInt(amount * 60);\n    } else {\n        msg.delay = parseInt(amount + 60);\n    }\n\n} else if (measure === 'hours') { //convert hours to seconds\n\n    if (amount === 1) {\n        msg.delay = parseInt(amount * 120);\n    } else {\n        msg.delay = parseInt(amount + 120);\n    }\n\n}\n\nmsg.delay = parseInt(msg.delay * 1000); //convert seconds to ms\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":550,"y":740,"wires":[["33cf76bb.74ee2a"]]},{"id":"6f4b7998.7b1528","type":"change","z":"9f38d792.8a5038","name":"Set msg.measuretime","rules":[{"t":"set","p":"measuretime","pt":"msg","to":"{}","tot":"json"},{"t":"set","p":"measuretime","pt":"msg","to":"measure_time","tot":"env"}],"action":"","property":"","from":"","to":"","reg":false,"x":880,"y":240,"wires":[["fc6b0793.8262b8"]]},{"id":"fc6b0793.8262b8","type":"function","z":"9f38d792.8a5038","name":"Correct value for measuretime if needed","func":"msg.measuretime = msg.measuretime.trim().replace(/\\ /g, \"_\").toLowerCase();\n\nvar measure = (msg.measuretime);\n\nif (measure === 'second'){\nmsg.measuretime = measure.replace(/second/g,'seconds');\n}\n\nelse if (measure === 'minute'){\nmsg.measuretime = measure.replace(/minute/g,'minutes');\n}\n\nelse if (measure === 'hour'){\nmsg.measuretime = measure.replace(/hour/g,'hours');\n}\n\nelse if (measure === 'infinite'){\nmsg.measuretime = measure.replace(/infinite/g,'forever');\n}\n\n//else {\n//return msg;\n//}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1180,"y":240,"wires":[["aea70daa.c304f"]]},{"id":"da77dc7.f17462","type":"api-call-service","z":"9f38d792.8a5038","name":"Turn off LEDs","server":"497693ef.d5e6bc","version":1,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"","data":"{\t   \"entity_id\": msg.node\t}","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1060,"y":740,"wires":[[]]},{"id":"ee825fe8.364d7","type":"switch","z":"9f38d792.8a5038","name":"Is a timeout defined?","property":"measuretime","propertyType":"msg","rules":[{"t":"eq","v":"forever","vt":"str"},{"t":"empty"},{"t":"else"}],"checkall":"true","repair":false,"outputs":3,"x":280,"y":700,"wires":[[],[],["708e83bd.f9c7dc"]]},{"id":"f94ca32c.71d2a","type":"function","z":"9f38d792.8a5038","name":"Calculate pixel effect","func":"var pixelEffect = env.get(\"pixel_effect\");\nvar brightness = parseInt(env.get(\"brightness\"));\nmsg.value = {};\n\nif (pixelEffect === 'random') {\n    var rand = Math.floor(Math.random() * 45) + 1;\n    msg.value = parseInt(((brightness * 256) + rand));\n} else {\n    msg.value = parseInt(((brightness * 256) + pixelEffect));\n}\n\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":840,"y":900,"wires":[[]]},{"id":"497693ef.d5e6bc","type":"server","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true},{"id":"6e26bc11.f27b44","type":"subflow:9f38d792.8a5038","z":"f1e1b905.e9a56","name":"","env":[{"name":"device_id","value":"light.lzw45_light_strip_level_2","type":"str"},{"name":"brightness","value":"99","type":"str"},{"name":"pixel_effect","value":"45","type":"str"},{"name":"total_time","value":"5","type":"str"},{"name":"zwave","value":"zwavejs","type":"str"}],"x":1120,"y":300,"wires":[["99a362eb.6c00c"]]},{"id":"ce9cc4a2.2da688","type":"inject","z":"f1e1b905.e9a56","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":940,"y":300,"wires":[["6e26bc11.f27b44"]]},{"id":"99a362eb.6c00c","type":"debug","z":"f1e1b905.e9a56","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1290,"y":300,"wires":[]}]
1 Like