Ok, so I’ve been testing some more things and I got to a functional sequence.
[{"id":"bca80967f4f1a957","type":"tab","label":"Flow 1","disabled":false,"info":"","env":[]},{"id":"0987493507089543","type":"server-state-changed","z":"bca80967f4f1a957","name":"All Blinds Switch On","server":"8a86b0cc.b2bac","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"light.all_blinds","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":110,"y":60,"wires":[["24c0a6fe3c245216"],["5fe5f814443b0b89"]]},{"id":"650d88ad7aefa937","type":"function","z":"bca80967f4f1a957","name":"currentLevel vs targetLevel abs difference Delay","func":"msg.delay=(Math.abs(msg.currentLevel.attributes.brightness - msg.targetLevel));\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":220,"y":260,"wires":[["a6bb553dce7a4691"]]},{"id":"cf07bee13747fe24","type":"api-current-state","z":"bca80967f4f1a957","name":"Get targetDevice currentLevel","server":"8a86b0cc.b2bac","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"{{device}}","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"currentLevel","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":210,"y":220,"wires":[["650d88ad7aefa937","05b27f5b2c0a3c44"]]},{"id":"a6bb553dce7a4691","type":"range","z":"bca80967f4f1a957","minin":"1","maxin":"252","minout":"1","maxout":"24000","action":"scale","round":true,"property":"delay","name":"Delay 255 to 24000ms","x":180,"y":300,"wires":[["250e9a6fb1d0259a"]]},{"id":"1eea5e19604c24cd","type":"delay","z":"bca80967f4f1a957","name":"Delay","pauseType":"delayv","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":590,"y":260,"wires":[["3476e20331054d5e","cca2ac9d8bb39317"]]},{"id":"250e9a6fb1d0259a","type":"api-call-service","z":"bca80967f4f1a957","name":"Set targetDevice at targetLevel","server":"8a86b0cc.b2bac","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":[],"entityId":["{{device}}"],"data":"{\"brightness\":msg.targetLevel}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":210,"y":340,"wires":[["1eea5e19604c24cd"]]},{"id":"3476e20331054d5e","type":"debug","z":"bca80967f4f1a957","name":"complete message","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":830,"y":220,"wires":[]},{"id":"5a687bedce84df5a","type":"inject","z":"bca80967f4f1a957","name":"Start","props":[{"p":"device","v":"[\"light.1_living\", \"light.2_bathroom\", \"light.3_bedroom\"]","vt":"json"},{"p":"targetLevel","v":"90","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":110,"y":120,"wires":[["a8fe252cc5626978"]]},{"id":"90475f454f2542da","type":"function","z":"bca80967f4f1a957","name":"for each item","func":"if (msg.items == undefined) msg.items = msg.device;\nif (msg.i == undefined) msg.i = 0;\nmsg.device = msg.items[msg.i];\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":590,"y":140,"wires":[["cf07bee13747fe24"]]},{"id":"cca2ac9d8bb39317","type":"function","z":"bca80967f4f1a957","name":"msg.i +1","func":"if((msg.i +=1) < 3)\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":420,"y":400,"wires":[["90475f454f2542da"]]},{"id":"05b27f5b2c0a3c44","type":"debug","z":"bca80967f4f1a957","name":"currentLevel debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"currentLevel.attributes.brightness","targetType":"msg","statusVal":"","statusType":"auto","x":830,"y":180,"wires":[]},{"id":"5fe5f814443b0b89","type":"change","z":"bca80967f4f1a957","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":300,"y":160,"wires":[["1eea5e19604c24cd"]]},{"id":"bf556889f7ea034e","type":"inject","z":"bca80967f4f1a957","name":"Stop","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":110,"y":160,"wires":[["5fe5f814443b0b89"]]},{"id":"a8fe252cc5626978","type":"range","z":"bca80967f4f1a957","minin":"1","maxin":"100","minout":"1","maxout":"252","action":"scale","round":true,"property":"targetLevel","name":"targetLevel 100 to 252","x":320,"y":120,"wires":[["90475f454f2542da"]]},{"id":"35f6c3d243754680","type":"change","z":"bca80967f4f1a957","name":"All Blinds Level to targetLevel, string","rules":[{"t":"set","p":"device","pt":"msg","to":"[\"light.1_living\", \"light.2_bathroom\", \"light.3_bedroom\"]","tot":"json"},{"t":"set","p":"targetLevel","pt":"msg","to":"targetLevel.attributes.brightness","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":630,"y":60,"wires":[["3476e20331054d5e","90475f454f2542da","5b8047a9b95f062b"]]},{"id":"24c0a6fe3c245216","type":"api-current-state","z":"bca80967f4f1a957","name":"Get All Blinds Level","server":"8a86b0cc.b2bac","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"light.all_blinds","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"targetLevel","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":350,"y":60,"wires":[["35f6c3d243754680","5b8047a9b95f062b"]]},{"id":"5b8047a9b95f062b","type":"debug","z":"bca80967f4f1a957","name":"complete message","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":830,"y":140,"wires":[]},{"id":"8a86b0cc.b2bac","type":"server","name":"Home Assistant","addon":true}]
I was able to link my “All Blinds” dimmer (the one that is activated for opening the blinds) to this sequence, it creates an array of the three devices (in the order I want them to be opened) and activates one by one.
The purpose of this “All Blinds” dimmer switch is to turn it on to 100% when I want the blinds to be opened fully, but when the sequence ends and all the blinds are open, I want this switch to be turned off. So if I want the blinds to be at 50%, I’ll then set it to 50% and it will start the sequence again.
What’s the best method to have this switch turned off after the sequence ends?
I copied the “for each item” and “msg.i +1” functions from a video so I don’t understand it fully, and I’m having an issue: It expects to have 3 items in the array and always repeat 3 times. If I send a list of only 2 blinds it will work and then return an error. Can anyone help me get the script right so it identifies the amount of times it has to loop based on the amount of items in the list
Thanks!
Rodrigo
EDIT: Forgot to mention that the reason why I didn’t use the “Wait for” node is because these controllers aren’t precise at reporting the final position, and sometimes they get “stuck” in a previous value (not the physical position itself which always reaches its desired place, but sometimes the final value doesn’t match).