# Repeat X times in ms or second

**URL:** <https://discourse.nodered.org/t/repeat-x-times-in-ms-or-second/50359>\
**Category:** General\
**Created:** [29 August 2021 19:07 UTC](https://discourse.nodered.org/t/repeat-x-times-in-ms-or-second/50359 "2021-08-29T19:07:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![greenb8](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/greenb8/32/47191_2.png) [@greenb8](https://discourse.nodered.org/u/greenb8)\
**Post date:** [29 August 2021 19:07 UTC](https://discourse.nodered.org/t/repeat-x-times-in-ms-or-second/50359/1 "2021-08-29T19:07:08Z")

</div>

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

> **[Pentair-IntelliBrite-LED-Manual.pdf](https://desertspringspools.com/files/Pentair-IntelliBrite-LED-Manual.pdf)**
>
> 2.15 MB

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [29 August 2021 20:22 UTC](https://discourse.nodered.org/t/repeat-x-times-in-ms-or-second/50359/2 "2021-08-29T20:22:46Z")

</div>

Hello ..

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/6/f6efebe018423eef2064e77785566e84810c309d.png)

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

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/4/b48176f4b0fb2f138167c3e9767287fd13facc06.png)

`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:**

```auto
[{"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

---

<div class="post-metadata">

**Author:** ![greenb8](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/greenb8/32/47191_2.png) [@greenb8](https://discourse.nodered.org/u/greenb8)\
**Post date:** [29 August 2021 22:52 UTC](https://discourse.nodered.org/t/repeat-x-times-in-ms-or-second/50359/3 "2021-08-29T22:52:04Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [30 August 2021 11:21 UTC](https://discourse.nodered.org/t/repeat-x-times-in-ms-or-second/50359/4 "2021-08-30T11:21:32Z")

</div>

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:

```auto
[{"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](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/1/21dc9c1f0a30f9879078532d6df5cff2cd9e714c.png)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [29 October 2021 11:22 UTC](https://discourse.nodered.org/t/repeat-x-times-in-ms-or-second/50359/5 "2021-10-29T11:22:32Z")

</div>

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