# Help with timing messages being sent

**URL:** <https://discourse.nodered.org/t/help-with-timing-messages-being-sent/81447>\
**Category:** General\
**Created:** [20 September 2023 09:01 UTC](https://discourse.nodered.org/t/help-with-timing-messages-being-sent/81447 "2023-09-20T09:01:15Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [20 September 2023 09:01 UTC](https://discourse.nodered.org/t/help-with-timing-messages-being-sent/81447/1 "2023-09-20T09:01:15Z")

</div>

I am a bit stuck for words - so I guess that is why I am not getting any progress - how to explain this exactly, but here goes:

Scenario:  
5 second time frame.  
There are 5 _messages_ to send depending on input.

Say `1` is _active_ and `0` is _clear_.

All conditions are clear.  
Some confusion on how to handle this. Constantly send 5 _clear_ messages over and over, or sent 5 _clear_ messages once and if they are still clear: just wait.

If any of the messages are _active_ that message's place is set to _active_ and so the messages are repeatedly sent.

eg: say _number 1_ is active the output would look like:  
1,0,0,0,0 (five seconds) 1,0,0,0,0 (five seconds) 1,0,0,0,0

Then if _number 3_ also becomes active the output would change to:  
1,0,1,0,0 (five seconds) 1,0,1,0,0 (five seconds) 1,0,1,0,0

Clear? 🤷

Now, the `1` shown in the example would not be a simple `1`.  
It is an `rgb` message. But to get the idea I simplified it to just a simple `1`.

What's going on and why?  
Well I have an RGB LED and want it to show up to 5 notifications.  
If the LED just shone constantly with a colour (depending on the condition) and another condition becomes active, how would I show this?  
Adding the colours together can be problematic.  
So I thought if I allocated `5` seconds (could be 4, but....) then it sends the RGB message to set that colour for that condition for 1/5'th of the time, then for the other parts (which are either off or active) those different messages are sent for their 1/5'th of the time, the LED would _blink_ the different colours.

## It's going to get bigger too.

Yes, that is ONE of the RGB LEDs.  
There are a few of them and they ALL have this possibility.  
So it needs to be modular (self contained) so each LED would have it's own table of which condition is active and which isn't.  
Then, as mentioned at the start, if all are _clear_ does it send one cycle of turning all LEDs off then stop?

Someone - please?  
But please keep me in the loop when doing it as I am sure I didn't explain it the best and if you do it all, something I didn't explain could throw a spanner in the works.

---

<div class="post-metadata">

**Author:** ![gregorius](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gregorius/32/73816_2.png) [@gregorius](https://discourse.nodered.org/u/gregorius)\
**Post date:** [20 September 2023 10:55 UTC](https://discourse.nodered.org/t/help-with-timing-messages-being-sent/81447/2 "2023-09-20T10:55:57Z")

</div>

Why not use flow/global/node context to store the current value and have node sending that value every second (or five seconds).

The context can be updated by another node but the context is the common storage between the updater node and the sender node.

Something like this:

```auto
[{"id":"43905019054932ec","type":"inject","z":"17a72a6e9f406d3c","name":"","props":[{"p":"payload"}],"repeat":"1","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"value","payloadType":"flow","x":613,"y":221,"wires":[["940af715304b4d5c"]]},{"id":"940af715304b4d5c","type":"debug","z":"17a72a6e9f406d3c","name":"current value","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":986,"y":218,"wires":[]},{"id":"cc8987e0645d4491","type":"inject","z":"17a72a6e9f406d3c","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":391,"y":288,"wires":[["f56ab29f48807d95"]]},{"id":"f56ab29f48807d95","type":"change","z":"17a72a6e9f406d3c","name":"","rules":[{"t":"set","p":"value","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":675,"y":285,"wires":[[]]},{"id":"dc3a9ec23eb51f7f","type":"inject","z":"17a72a6e9f406d3c","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"2","payloadType":"num","x":392,"y":349,"wires":[["f56ab29f48807d95"]]},{"id":"d72497b3972ba4df","type":"inject","z":"17a72a6e9f406d3c","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"3","payloadType":"num","x":395,"y":396,"wires":[["f56ab29f48807d95"]]},{"id":"25cc07a91e3715d2","type":"inject","z":"17a72a6e9f406d3c","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"4","payloadType":"num","x":397,"y":444,"wires":[["f56ab29f48807d95"]]}]

```

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [20 September 2023 11:06 UTC](https://discourse.nodered.org/t/help-with-timing-messages-being-sent/81447/3 "2023-09-20T11:06:54Z")

</div>

Ok, I didn't explain it clear enough.

I'll skip your flow doesn't have an _off_ (`0`) value.

But if I click on your `1`, I ONLY get `1` spat out.

If I then press `2` I ONLY get `2` as an output.

I was wanting `1`,`2`,_blank_ then repeat. `1`,`2`,_blank_.

Then if the third one is set I get:  
`1`,`2`,`3` `1`,`2`,`3` `1`,`2`,`3`

Clearer?

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [20 September 2023 12:25 UTC](https://discourse.nodered.org/t/help-with-timing-messages-being-sent/81447/4 "2023-09-20T12:25:47Z")

</div>

This is something I've bashed together as a starting point.

(foreign node: `node-red-contrib-counter` )

```auto
[
    {
        "id": "d351ccaf154f2fdf",
        "type": "inject",
        "z": "7bd90e87b3e8c8bf",
        "name": "Stop",
        "props": [
            {
                "p": "reset",
                "v": "true",
                "vt": "bool"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 2460,
        "y": 100,
        "wires": [
            [
                "a8e02b52f9c89fd3",
                "edca42a80d4c53de"
            ]
        ]
    },
    {
        "id": "dd49e2c0e040fd68",
        "type": "inject",
        "z": "7bd90e87b3e8c8bf",
        "name": "Go",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 2460,
        "y": 140,
        "wires": [
            [
                "a8e02b52f9c89fd3"
            ]
        ]
    },
    {
        "id": "8738884cb4ae17a5",
        "type": "switch",
        "z": "7bd90e87b3e8c8bf",
        "name": "",
        "property": "count",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "0",
                "vt": "num"
            },
            {
                "t": "eq",
                "v": "1",
                "vt": "num"
            },
            {
                "t": "eq",
                "v": "2",
                "vt": "num"
            },
            {
                "t": "eq",
                "v": "3",
                "vt": "num"
            },
            {
                "t": "eq",
                "v": "4",
                "vt": "num"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 5,
        "x": 2980,
        "y": 140,
        "wires": [
            [
                "8fe027f72bb9a6cc"
            ],
            [
                "d129965813943a20"
            ],
            [
                "63d73a716f18ac77"
            ],
            [
                "b8ba97c4afd556f0"
            ],
            [
                "a46b796896f172bf"
            ]
        ]
    },
    {
        "id": "edca42a80d4c53de",
        "type": "change",
        "z": "7bd90e87b3e8c8bf",
        "name": "Reset",
        "rules": [
            {
                "t": "set",
                "p": "reset",
                "pt": "msg",
                "to": "true",
                "tot": "bool"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 2660,
        "y": 180,
        "wires": [
            [
                "eb6045154ed7906c"
            ]
        ]
    },
    {
        "id": "a8e02b52f9c89fd3",
        "type": "trigger",
        "z": "7bd90e87b3e8c8bf",
        "name": "",
        "op1": "foo",
        "op2": "0",
        "op1type": "str",
        "op2type": "str",
        "duration": "-1",
        "extend": false,
        "overrideDelay": false,
        "units": "s",
        "reset": "",
        "bytopic": "all",
        "topic": "topic",
        "outputs": 1,
        "x": 2630,
        "y": 140,
        "wires": [
            [
                "eb6045154ed7906c"
            ]
        ]
    },
    {
        "id": "eb6045154ed7906c",
        "type": "counter",
        "z": "7bd90e87b3e8c8bf",
        "name": "",
        "init": "0",
        "step": "1",
        "lower": null,
        "upper": null,
        "mode": "increment",
        "outputs": "1",
        "x": 2840,
        "y": 140,
        "wires": [
            [
                "8738884cb4ae17a5"
            ]
        ]
    },
    {
        "id": "a46b796896f172bf",
        "type": "delay",
        "z": "7bd90e87b3e8c8bf",
        "name": "Rate limit",
        "pauseType": "rate",
        "timeout": "5",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "allowrate": false,
        "outputs": 1,
        "x": 2565,
        "y": 180,
        "wires": [
            [
                "edca42a80d4c53de"
            ]
        ],
        "l": false
    },
    {
        "id": "e97a0bf3117a2094",
        "type": "trigger",
        "z": "7bd90e87b3e8c8bf",
        "name": "",
        "op1": "1",
        "op2": "0",
        "op1type": "str",
        "op2type": "str",
        "duration": "500",
        "extend": false,
        "overrideDelay": false,
        "units": "ms",
        "reset": "",
        "bytopic": "all",
        "topic": "topic",
        "outputs": 1,
        "x": 3135,
        "y": 70,
        "wires": [
            []
        ],
        "l": false
    },
    {
        "id": "d129965813943a20",
        "type": "trigger",
        "z": "7bd90e87b3e8c8bf",
        "name": "",
        "op1": "1",
        "op2": "0",
        "op1type": "str",
        "op2type": "str",
        "duration": "500",
        "extend": false,
        "overrideDelay": false,
        "units": "ms",
        "reset": "",
        "bytopic": "all",
        "topic": "topic",
        "outputs": 1,
        "x": 3175,
        "y": 110,
        "wires": [
            []
        ],
        "l": false
    },
    {
        "id": "63d73a716f18ac77",
        "type": "trigger",
        "z": "7bd90e87b3e8c8bf",
        "name": "",
        "op1": "1",
        "op2": "0",
        "op1type": "str",
        "op2type": "str",
        "duration": "500",
        "extend": false,
        "overrideDelay": false,
        "units": "ms",
        "reset": "",
        "bytopic": "all",
        "topic": "topic",
        "outputs": 1,
        "x": 3215,
        "y": 150,
        "wires": [
            []
        ],
        "l": false
    },
    {
        "id": "b8ba97c4afd556f0",
        "type": "trigger",
        "z": "7bd90e87b3e8c8bf",
        "name": "",
        "op1": "1",
        "op2": "0",
        "op1type": "str",
        "op2type": "str",
        "duration": "500",
        "extend": false,
        "overrideDelay": false,
        "units": "ms",
        "reset": "",
        "bytopic": "all",
        "topic": "topic",
        "outputs": 1,
        "x": 3255,
        "y": 180,
        "wires": [
            []
        ],
        "l": false
    },
    {
        "id": "8fe027f72bb9a6cc",
        "type": "change",
        "z": "7bd90e87b3e8c8bf",
        "name": "",
        "rules": [
            {
                "t": "delete",
                "p": "reset",
                "pt": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 3085,
        "y": 70,
        "wires": [
            [
                "e97a0bf3117a2094"
            ]
        ],
        "l": false
    }
]

```

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [20 September 2023 13:16 UTC](https://discourse.nodered.org/t/help-with-timing-messages-being-sent/81447/5 "2023-09-20T13:16:45Z")

</div>

Let's say you only have 1 LED and 5 possible notifications, of which the first and third are currently "active".

Do you want to send eg at 1s intervals "red", "off", "blue", "off", "off"?  
Should this sequence repeat immediately and indefinitely?

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [20 September 2023 20:39 UTC](https://discourse.nodered.org/t/help-with-timing-messages-being-sent/81447/6 "2023-09-20T20:39:26Z")

</div>

Correct

Each individual colour is sent to the LED for 1 second (5 seconds in total for all 5 conditions) and repeats.

I think what I posted will work.

The _option_ of it stopping if/when all 5 are _off_ is more trouble that it is worth, as the code to determine that is going to basically be the same as the code it is going to stop.

---

<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:** [19 November 2023 20:39 UTC](https://discourse.nodered.org/t/help-with-timing-messages-being-sent/81447/7 "2023-11-19T20:39:56Z")

</div>

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