Flashing LED's on dashboard for kWh for High or Low rate is active

Hi

My kWh meter displays a low and a high rate (counters).

I have an MQTT connection to Node Red.

When the high rate is active, I would like an LED light on my dashboard to flash. And the same applies when the low rate is active.

I have tried to create a program that reads the high rate; when this high rate (counter) is active, the counter reading increases (when there is a load, of course).
But the program didn't work, what did I wrong?

[
    {
        "id": "5402ec8d1874bad7",
        "type": "function",
        "z": "0e30872a391bd11c",
        "name": "Low Rate Pulse",
        "func": "const message = msg.payload\nlet lrpulse = flow.get(\"pulselr\") || 0\nlet lowr = flow.get(\"lowrate\")\n\nif (message == 1)\n{\n    flow.set(\"lrtmphold\", lowr)\n    flow.set(\"pulselr\",0)\n    return\n}\n \nif (lowr == flow.get(\"lrtmphold\"))\n{\n    flow.set(\"pulselr\",0)\n    return\n}\n\nif (lowr > flow.get(\"lrtmphold\"))\n{\n    flow.set(\"pulslr\",1)\n    setTimeout(flow.set(\"lrtmphold\",lowr),1000)\n}\nreturn msg",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 300,
        "y": 460,
        "wires": [
            []
        ]
    },
    {
        "id": "d919a1f451322c97",
        "type": "change",
        "z": "0e30872a391bd11c",
        "name": "read pulse",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "#:(file)::pulselr",
                "tot": "flow"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 290,
        "y": 400,
        "wires": [
            [
                "46e24baf577e33b1"
            ]
        ]
    },
    {
        "id": "46e24baf577e33b1",
        "type": "debug",
        "z": "0e30872a391bd11c",
        "name": "debug 12",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 480,
        "y": 400,
        "wires": []
    },
    {
        "id": "343eadba06597da1",
        "type": "inject",
        "z": "0e30872a391bd11c",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "1",
        "payloadType": "num",
        "x": 90,
        "y": 460,
        "wires": [
            [
                "5402ec8d1874bad7",
                "d919a1f451322c97"
            ]
        ]
    }
]
  1. Precisely how does Node-red know when the active rate switches from low to high and vice versa?
  2. Are you using HomeAssistant?
  3. What dashboard add-on are you using, and how is the LED implemented?
  1. Node Red doesn't know when the active rate switches. I see the active rate because of the increasing counter.
  2. Domoticz has a connection with the kWh-meter (P1) and there a MQTT connection from Domoticz to Node Red.
  3. I am using Dashboard 2.0, the LED's are not yet implemented for this application.

I am not familiar with Domotiz so forgive me if my questions seem to make little sense.
I can't understand your use of context variables, nor what setTimeout brings to the party.

Domoticz publishes an MQTT message at intervals, which Node-red is subscribed to?
How frequently?
Can you give us an example of this mqtt message?
Please explain the mechanism by which you get from having a counter (count of what?) to knowing that High/Low rate is active.

I don't know exactly the message interval (about 1sec.)
Below the outcome from the MQTT regarding the high and low rate (filtered "by idx:1")


Below including comments

[
    {
        "id": "5402ec8d1874bad7",
        "type": "function",
        "z": "0e30872a391bd11c",
        "name": "Low Rate Pulse",
        "func": "const message = msg.payload\nlet lrpulse = flow.get(\"pulselr\") || 0 \n//Low Rate pulse \nlet lowr = flow.get(\"lowrate\")\n// Low rate come's from MQTT (svalue1)\n\nif (message == 1)\n{\n    flow.set(\"lrtmphold\", lowr)\n    // lrtmphold = Low rate temporary Hold\n    flow.set(\"pulselr\",0)\n    // pulselr, i use it for the flashing led\n    return\n}\n \nif (lowr == flow.get(\"lrtmphold\"))\n{\n    flow.set(\"pulselr\",0)\n    return\n}\n\nif (lowr > flow.get(\"lrtmphold\"))\n{\n    flow.set(\"pulselr\",1)\n    setTimeout(flow.set(\"lrtmphold\",lowr),1000)\n    // I try to use a delay to make the temporary hold the same ase the current low rate counter setting\n}\nreturn msg",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 300,
        "y": 460,
        "wires": [
            []
        ]
    },
    {
        "id": "343eadba06597da1",
        "type": "inject",
        "z": "0e30872a391bd11c",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "1",
        "payloadType": "num",
        "x": 90,
        "y": 460,
        "wires": [
            [
                "5402ec8d1874bad7",
                "d919a1f451322c97"
            ]
        ]
    },
    {
        "id": "d919a1f451322c97",
        "type": "change",
        "z": "0e30872a391bd11c",
        "name": "read pulse",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "#:(file)::pulselr",
                "tot": "flow"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 290,
        "y": 400,
        "wires": [
            []
        ]
    }
]