Stop the execution of a Function for 30 seconds after Event

Hi, I have a Flow where I Monitor my pv.
The pv Sends it's data every second.
If the grid feed is greater than x for 5 seconds, I Set a gpio pin to high. If I buy from the grid for more than 3 seconds the pin gets LOW.
This works.

What I strugle with:

after a state change of the pin, the state should not be able to change again within 30 seconds.

How can i do that?

Hi @Andi, welcome to the forum.

The delay node has a "Rate Limit" option which lets you pass no more than 1 message per 30 seconds. You probably want to set it to "Drop intermediate messages".

Wow thank you for your fast Response.
I will try it, as soon as i am at home.
Thank you :slight_smile:

hm i got the delay working as you said but now i think that this is not what i need.
im new to node-red and obviously i dont know where my problem actually is..

i rebuild my flow as a test where injection nodes replace the pv-measurements function which is connected to the two switches..

CODE:

[
    {
        "id": "eb386b679fa0c7d1",
        "type": "tab",
        "label": "Flow 5",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "e5fe2cf44070a6f9",
        "type": "switch",
        "z": "eb386b679fa0c7d1",
        "name": "Einspeise-Schwelle Überschritten",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "gte",
                "v": "1250",
                "vt": "num"
            },
            {
                "t": "lt",
                "v": "1250",
                "vt": "num"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 340,
        "y": 180,
        "wires": [
            [
                "94773eb50994da1f"
            ],
            [
                "baa13c7457b59439"
            ]
        ]
    },
    {
        "id": "d166d98b1d38f0d3",
        "type": "inject",
        "z": "eb386b679fa0c7d1",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "40",
        "payloadType": "num",
        "x": 90,
        "y": 200,
        "wires": [
            [
                "e5fe2cf44070a6f9"
            ]
        ]
    },
    {
        "id": "26e9d0c2a6dd38f2",
        "type": "inject",
        "z": "eb386b679fa0c7d1",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "1",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "1260",
        "payloadType": "num",
        "x": 90,
        "y": 160,
        "wires": [
            [
                "e5fe2cf44070a6f9"
            ]
        ]
    },
    {
        "id": "94773eb50994da1f",
        "type": "change",
        "z": "eb386b679fa0c7d1",
        "name": "Über Schwelle = true",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "true",
                "tot": "bool"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 700,
        "y": 160,
        "wires": [
            [
                "0747a1ab7cfaa406"
            ]
        ]
    },
    {
        "id": "baa13c7457b59439",
        "type": "change",
        "z": "eb386b679fa0c7d1",
        "name": "Unter Schwelle = false",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "false",
                "tot": "bool"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 700,
        "y": 200,
        "wires": [
            [
                "0747a1ab7cfaa406"
            ]
        ]
    },
    {
        "id": "0747a1ab7cfaa406",
        "type": "trigger",
        "z": "eb386b679fa0c7d1",
        "name": "Schwelle für mehr als 5s überschritten",
        "op1": "",
        "op2": "PIN_Einschalten",
        "op1type": "nul",
        "op2type": "str",
        "duration": "5",
        "extend": false,
        "overrideDelay": false,
        "units": "s",
        "reset": "false",
        "bytopic": "all",
        "topic": "topic",
        "outputs": 1,
        "x": 990,
        "y": 180,
        "wires": [
            [
                "c310147e3fa07e51"
            ]
        ]
    },
    {
        "id": "da781fc5827c82f2",
        "type": "switch",
        "z": "eb386b679fa0c7d1",
        "name": "Bezug Überschritten",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "gt",
                "v": "0",
                "vt": "num"
            },
            {
                "t": "lte",
                "v": "0",
                "vt": "num"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 300,
        "y": 380,
        "wires": [
            [
                "cd417d34b84206e4"
            ],
            [
                "c59fac69ffecb6f2"
            ]
        ]
    },
    {
        "id": "4c6a9a123608fae9",
        "type": "inject",
        "z": "eb386b679fa0c7d1",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "0",
        "payloadType": "num",
        "x": 90,
        "y": 400,
        "wires": [
            [
                "da781fc5827c82f2"
            ]
        ]
    },
    {
        "id": "a718e45a2b173860",
        "type": "inject",
        "z": "eb386b679fa0c7d1",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "10",
        "payloadType": "num",
        "x": 90,
        "y": 360,
        "wires": [
            [
                "da781fc5827c82f2"
            ]
        ]
    },
    {
        "id": "cd417d34b84206e4",
        "type": "change",
        "z": "eb386b679fa0c7d1",
        "name": "Über Schwelle = true",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "true",
                "tot": "bool"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 560,
        "y": 360,
        "wires": [
            [
                "515c04ac0168a86f"
            ]
        ]
    },
    {
        "id": "c59fac69ffecb6f2",
        "type": "change",
        "z": "eb386b679fa0c7d1",
        "name": "Unter Schwelle = false",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "false",
                "tot": "bool"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 560,
        "y": 400,
        "wires": [
            [
                "515c04ac0168a86f"
            ]
        ]
    },
    {
        "id": "515c04ac0168a86f",
        "type": "trigger",
        "z": "eb386b679fa0c7d1",
        "name": "Schwelle für mehr als 3s überschritten",
        "op1": "",
        "op2": "PIN_Abschalten",
        "op1type": "nul",
        "op2type": "str",
        "duration": "3",
        "extend": false,
        "overrideDelay": false,
        "units": "s",
        "reset": "false",
        "bytopic": "all",
        "topic": "topic",
        "outputs": 1,
        "x": 970,
        "y": 380,
        "wires": [
            [
                "a5466e47b8c28d9a"
            ]
        ]
    },
    {
        "id": "a5466e47b8c28d9a",
        "type": "debug",
        "z": "eb386b679fa0c7d1",
        "name": "AUS",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1510,
        "y": 380,
        "wires": []
    },
    {
        "id": "729249d51e624ae1",
        "type": "debug",
        "z": "eb386b679fa0c7d1",
        "name": "EIN",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1550,
        "y": 200,
        "wires": []
    },
    {
        "id": "c310147e3fa07e51",
        "type": "delay",
        "z": "eb386b679fa0c7d1",
        "name": "",
        "pauseType": "rate",
        "timeout": "5",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "30",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": true,
        "allowrate": false,
        "outputs": 1,
        "x": 1330,
        "y": 260,
        "wires": [
            [
                "729249d51e624ae1"
            ]
        ]
    }
]

When the upper debug is getting "fired", there should be a 30 seconds runoff where the lower one wont be able to get "fired"
the same thing do i need vice versa...

is maybe my approach not right?

Another possible option is the trigger node... set to pass the initial message then after x seconds pass the latest message - without extending the wait time.

hi dceejay, thanks for your answer, but sadly i dont understand how or where to implement a trigger node..

i will post a picture of the whole flow, maybe am i doing it completely wrong?

thank you for your help :slight_smile:

i have to connect the delay end to somewhere but no matter where, it wont act as i want..

if the "on" debug gets fired, it should lock the lower switch somehow for 30 seconds

ok i got it working..
but somehow it feels wrong..
can someone with experience in node-red tell me if its ok how i do it?

its for avtivating a heating rod, whenever my pv has enough grid feed. as soon as i have to take power from the grid the heating rod should get deactivated. the delay is to prevent the rod from getting switched on and off constantly

You will probably get more forum assistance, if you present your issue in a simplified flow, especially when your labels are not in English.
I've created such a flow, just using 2 inject nodes below.
Please try it, and see it it works for you.

[{"id":"f1c71290bde2ac68","type":"trigger","z":"1326aadbacf36704","name":"","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"30","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":330,"y":360,"wires":[["3e330ac26d3c19d7"]]},{"id":"4b2422620c4637bd","type":"inject","z":"1326aadbacf36704","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"ON","payloadType":"str","x":170,"y":360,"wires":[["f1c71290bde2ac68"]]},{"id":"24d30cd2ed50a4e2","type":"inject","z":"1326aadbacf36704","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"OFF","payloadType":"str","x":170,"y":420,"wires":[["3e330ac26d3c19d7","f1c71290bde2ac68"]]},{"id":"f21931e51bd64480","type":"debug","z":"1326aadbacf36704","name":"debug 45","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":720,"y":420,"wires":[]},{"id":"3e330ac26d3c19d7","type":"rbe","z":"1326aadbacf36704","name":"Block unless changes","func":"rbe","gap":"","start":"","inout":"out","septopics":false,"property":"payload","topi":"topic","x":520,"y":420,"wires":[["f21931e51bd64480"]]}]

Can you explain the purpose of these two seperate parts of the flow? What do the inject values represent? It might be explained by the labels but unfortunately I speak no German!

Hi, sorry for my confusion... i hope my brain is a bit less confused after sleeping :smiley:

So i get data from the sma Home manager and convert them.
This happens till the masuerments function.

Afterwards i check if 1. the grid feed is over 1250W for 5 seconds, if so it sets a GPIO to HIGH
and 2. if i buy from the grid for over 3 seconds, if so i set the pin to LOW again.
The delay is to ensure that the pin wont get switched on off constantely..

Is my way generally a good approach?
I fell like there is something wrong with it..