Repeat X times in ms or second

Hey all, First time poster here. I have a pentair pool light I am trying to control through home assistant. I have the entity set up and am able to control the light with on/of manual presses.

My main goal here is to be able to toggle the light power simulating the flip of a switch x number of times. for instance to make the light blue you need to toggle power 8 times. To change to "romance mode" would be 3 power cycles on/off/on/off/on/off rapidly I'm not sure of exact timing yet but its in ms...

any suggestions on how this could be completed would be greatly appreciated!

heres the instruction manual

Hello ..

  1. you can create a msg with the following fields
    (possibly through a Dashboard form ... for the example we use an Inject node)

image

msg.lightMode sets the color mode for the light
msg.rate defines the rate limit between msgs, used by the Delay node (in milliseconds)

  1. the msg is passed to a Function node that creates x amount of off/on msgs
  2. delay node rate limits the msgs as defined in step 1

Test flow:

[{"id":"c8e60de07b087df2","type":"inject","z":"4895ea10b4ee9ead","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"},{"p":"lightMode","v":"5","vt":"num"},{"p":"rate","v":"2000","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"lightControl","payloadType":"date","x":200,"y":1340,"wires":[["813c73a9cfc5780e","e09d6f33c0aa0804"]]},{"id":"813c73a9cfc5780e","type":"function","z":"4895ea10b4ee9ead","name":"","func":"\nlet lightMode = msg.lightMode   // how many times to switch on/off\nlet rate = msg.rate   // rate between msgs .. needed property for Rate Limit Trigger node\n\nfor (let i = 0; i < lightMode; i++) {\n\n        node.send({ payload: \"OFF\", rate })\n        node.send({ payload: \"ON\", rate })\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":420,"y":1340,"wires":[["090f46dde86a5c60"]]},{"id":"c68a52fac94e3887","type":"debug","z":"4895ea10b4ee9ead","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":790,"y":1340,"wires":[]},{"id":"090f46dde86a5c60","type":"delay","z":"4895ea10b4ee9ead","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":true,"x":590,"y":1340,"wires":[["c68a52fac94e3887"]]},{"id":"e09d6f33c0aa0804","type":"debug","z":"4895ea10b4ee9ead","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":400,"y":1240,"wires":[]}]

** take care of how low you set the rate because the relay may not be able to handle fast switching

I'm not at home to try it yet but I appreciate ur response!

It looks like that will work, are you familiar with how i might be able to integrate this into home assistant or another dashboard so i can select say blue and run the flow to get blue? does that make sense?

sorry, i dont know anything about home assistant but im sure you can get some help on this forum regarding the Node-red Dashboard.

Use a ui Dropdown node to create the list of light mode selections. For Example:

[{"id":"688f09d20f631e3c","type":"ui_dropdown","z":"4895ea10b4ee9ead","name":"","label":"Select Color Mode","tooltip":"","place":"Select option","group":"7e5c46b81d3328d7","order":0,"width":0,"height":0,"passthru":true,"multiple":false,"options":[{"label":"SAm Mode","value":1,"type":"num"},{"label":"Party Mode","value":2,"type":"num"},{"label":"Romance Mode","value":3,"type":"num"},{"label":"Caribbean Mode","value":4,"type":"num"},{"label":"American Mode","value":5,"type":"num"},{"label":"California Sunset Mode","value":6,"type":"num"},{"label":"Royal Mode","value":7,"type":"num"},{"label":"Blue","value":8,"type":"num"},{"label":"Green","value":9,"type":"num"}],"payload":"","topic":"topic","topicType":"msg","x":500,"y":840,"wires":[["9cdfa722c543c287"]]},{"id":"9cdfa722c543c287","type":"debug","z":"4895ea10b4ee9ead","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":760,"y":840,"wires":[]},{"id":"7e5c46b81d3328d7","type":"ui_group","name":"Default","tab":"a084018de3161310","order":1,"disp":true,"width":"6","collapse":false},{"id":"a084018de3161310","type":"ui_tab","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

image

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.