Help with timing messages being sent

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? :person_shrugging:

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.

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:

[{"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"]]}]

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?

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

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

[
    {
        "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
    }
]

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?

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.

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