2-step countdown (loop)

Hello,

I ve reated a 2 step countdown (with the help of this forum). Means: 1 countdown runs down and at the end it triggers another countdown, which triggers at the end the first one again.

I am using this to control my pump. The pump runs for x-time (first countdown) and stops for x-time (second countdown). Maybe someone can use it.

To start and stop it i am using a switch-dashboard

I am still struggling a bit to complete it.

  1. I can start the whole countdown-process but cant find an elegant way to stop it. Has someone an idea?
[
    {
        "id": "3daf5c5af8d6b1d3",
        "type": "debug",
        "z": "a9ed4fd40ab38e2f",
        "name": "Continue with flow",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": true,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 4110,
        "y": 3520,
        "wires": []
    },
    {
        "id": "de9b3c406b1a913d",
        "type": "switch",
        "z": "a9ed4fd40ab38e2f",
        "name": "reached 0?",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "0",
                "vt": "num"
            },
            {
                "t": "else"
            }
        ],
        "checkall": "false",
        "repair": false,
        "outputs": 2,
        "x": 3870,
        "y": 3560,
        "wires": [
            [
                "3daf5c5af8d6b1d3",
                "81ac4a849519c638"
            ],
            [
                "ca5bb44b69c0a099"
            ]
        ]
    },
    {
        "id": "ca5bb44b69c0a099",
        "type": "debug",
        "z": "a9ed4fd40ab38e2f",
        "name": "Show count down value",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": true,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 4110,
        "y": 3600,
        "wires": []
    },
    {
        "id": "8317c04cd3ea0f21",
        "type": "trigger",
        "z": "a9ed4fd40ab38e2f",
        "name": "heartbeat",
        "op1": "",
        "op2": "",
        "op1type": "nul",
        "op2type": "payl",
        "duration": "1",
        "extend": false,
        "overrideDelay": false,
        "units": "s",
        "reset": "0",
        "bytopic": "all",
        "topic": "topic",
        "outputs": 1,
        "x": 3480,
        "y": 3560,
        "wires": [
            [
                "827e17c2de5cc00e",
                "4ed20e284176d0af"
            ]
        ],
        "outputLabels": [
            "send \"fail\" if not feeded"
        ]
    },
    {
        "id": "4e0a1a5af22af0a5",
        "type": "link out",
        "z": "a9ed4fd40ab38e2f",
        "name": "link out 5",
        "mode": "link",
        "links": [
            "d4aa79b97717c57b"
        ],
        "x": 3725,
        "y": 3660,
        "wires": []
    },
    {
        "id": "d4aa79b97717c57b",
        "type": "link in",
        "z": "a9ed4fd40ab38e2f",
        "name": "link in 5",
        "links": [
            "4e0a1a5af22af0a5"
        ],
        "x": 3465,
        "y": 3660,
        "wires": [
            [
                "8317c04cd3ea0f21"
            ]
        ]
    },
    {
        "id": "827e17c2de5cc00e",
        "type": "change",
        "z": "a9ed4fd40ab38e2f",
        "name": "payload -1",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "payload - 1",
                "tot": "jsonata"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 3670,
        "y": 3560,
        "wires": [
            [
                "4e0a1a5af22af0a5",
                "de9b3c406b1a913d"
            ]
        ]
    },
    {
        "id": "81ac4a849519c638",
        "type": "function",
        "z": "a9ed4fd40ab38e2f",
        "name": "set waitTime",
        "func": "msg.payload = global.get(\"waitTime\")\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 3270,
        "y": 3800,
        "wires": [
            [
                "5a69deb10113265e"
            ]
        ]
    },
    {
        "id": "1a797e1430bf8152",
        "type": "debug",
        "z": "a9ed4fd40ab38e2f",
        "name": "Continue with flow",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": true,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 4130,
        "y": 3780,
        "wires": []
    },
    {
        "id": "ab99d24c3cce1555",
        "type": "switch",
        "z": "a9ed4fd40ab38e2f",
        "name": "reached 0?",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "0",
                "vt": "num"
            },
            {
                "t": "else"
            }
        ],
        "checkall": "false",
        "repair": false,
        "outputs": 2,
        "x": 3890,
        "y": 3800,
        "wires": [
            [
                "1a797e1430bf8152",
                "7d5ceb1b60d0bc62"
            ],
            [
                "d853516304c72b7c"
            ]
        ]
    },
    {
        "id": "d853516304c72b7c",
        "type": "debug",
        "z": "a9ed4fd40ab38e2f",
        "name": "Show count down value",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": true,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 4130,
        "y": 3840,
        "wires": []
    },
    {
        "id": "5a69deb10113265e",
        "type": "trigger",
        "z": "a9ed4fd40ab38e2f",
        "name": "heartbeat",
        "op1": "",
        "op2": "",
        "op1type": "nul",
        "op2type": "payl",
        "duration": "1",
        "extend": false,
        "overrideDelay": false,
        "units": "s",
        "reset": "0",
        "bytopic": "all",
        "topic": "topic",
        "outputs": 1,
        "x": 3480,
        "y": 3800,
        "wires": [
            [
                "4bb4554c7c972a86"
            ]
        ],
        "outputLabels": [
            "send \"fail\" if not feeded"
        ]
    },
    {
        "id": "de38aba1c1945392",
        "type": "link out",
        "z": "a9ed4fd40ab38e2f",
        "name": "link out 6",
        "mode": "link",
        "links": [
            "b9bab22747a42069"
        ],
        "x": 3715,
        "y": 3920,
        "wires": []
    },
    {
        "id": "b9bab22747a42069",
        "type": "link in",
        "z": "a9ed4fd40ab38e2f",
        "name": "link in 6",
        "links": [
            "de38aba1c1945392"
        ],
        "x": 3425,
        "y": 3920,
        "wires": [
            [
                "5a69deb10113265e"
            ]
        ]
    },
    {
        "id": "4bb4554c7c972a86",
        "type": "change",
        "z": "a9ed4fd40ab38e2f",
        "name": "payload-1",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "payload - 1",
                "tot": "jsonata"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 3660,
        "y": 3800,
        "wires": [
            [
                "de38aba1c1945392",
                "ab99d24c3cce1555"
            ]
        ]
    },
    {
        "id": "7d5ceb1b60d0bc62",
        "type": "function",
        "z": "a9ed4fd40ab38e2f",
        "name": "set dosingTime",
        "func": "msg.payload = global.get(\"dosingTime\")\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 3260,
        "y": 3560,
        "wires": [
            [
                "8317c04cd3ea0f21"
            ]
        ]
    },
    {
        "id": "346fe55eb17a8653",
        "type": "rbe",
        "z": "a9ed4fd40ab38e2f",
        "name": "",
        "func": "rbe",
        "gap": "",
        "start": "",
        "inout": "out",
        "septopics": true,
        "property": "payload",
        "topi": "topic",
        "x": 3170,
        "y": 3720,
        "wires": [
            [
                "7d5ceb1b60d0bc62"
            ]
        ]
    },
    {
        "id": "4ed20e284176d0af",
        "type": "debug",
        "z": "a9ed4fd40ab38e2f",
        "name": "debug 13",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 3660,
        "y": 3500,
        "wires": []
    },
    {
        "id": "b253130c6f8cee01",
        "type": "group",
        "z": "a9ed4fd40ab38e2f",
        "name": "Autotimer",
        "style": {
            "label": true
        },
        "nodes": [
            "b66fbbcb8c41d637",
            "b818f41a48b921f4",
            "248fb7ef4d723514",
            "bcf8d2cc1a27696d",
            "534c19b940d37914",
            "36d8dcdc7be1bc5c",
            "5fade2ffa8740411",
            "6f49e1d19bedc2d0",
            "24a028056455694e",
            "4e37b7047fd44050",
            "2e94315d15790424",
            "17b6ddf9ce4c964f",
            "011c39a44fc33165",
            "3493b06c7231ed5d",
            "cbdcde0f16615730",
            "16cc1b6087639514",
            "963d3820ded9ed33",
            "df24b9d8d5a91c14",
            "a3cdf07ae19762d8"
        ],
        "x": 2134,
        "y": 3459,
        "w": 972,
        "h": 442
    },
    {
        "id": "b66fbbcb8c41d637",
        "type": "ui_text",
        "z": "a9ed4fd40ab38e2f",
        "g": "b253130c6f8cee01",
        "group": "4368da8fe6ddbe0c",
        "order": 43,
        "width": 3,
        "height": 1,
        "name": "Run for",
        "label": "",
        "format": "Run for",
        "layout": "row-spread",
        "className": "",
        "style": false,
        "font": "",
        "fontSize": 16,
        "color": "#000000",
        "x": 2480,
        "y": 3540,
        "wires": []
    },
    {
        "id": "b818f41a48b921f4",
        "type": "ui_text_input",
        "z": "a9ed4fd40ab38e2f",
        "g": "b253130c6f8cee01",
        "name": "dose",
        "label": "",
        "tooltip": "",
        "group": "4368da8fe6ddbe0c",
        "order": 44,
        "width": 3,
        "height": 1,
        "passthru": true,
        "mode": "number",
        "delay": 300,
        "topic": "topic",
        "sendOnBlur": true,
        "className": "",
        "topicType": "msg",
        "x": 2630,
        "y": 3540,
        "wires": [
            [
                "17b6ddf9ce4c964f"
            ]
        ]
    },
    {
        "id": "248fb7ef4d723514",
        "type": "ui_text",
        "z": "a9ed4fd40ab38e2f",
        "g": "b253130c6f8cee01",
        "group": "4368da8fe6ddbe0c",
        "order": 45,
        "width": 1,
        "height": 1,
        "name": "sec_dose",
        "label": "",
        "format": "sec.",
        "layout": "row-left",
        "className": "",
        "style": false,
        "font": "",
        "fontSize": 16,
        "color": "#000000",
        "x": 2780,
        "y": 3540,
        "wires": []
    },
    {
        "id": "bcf8d2cc1a27696d",
        "type": "ui_text",
        "z": "a9ed4fd40ab38e2f",
        "g": "b253130c6f8cee01",
        "group": "4368da8fe6ddbe0c",
        "order": 51,
        "width": 3,
        "height": 1,
        "name": "Stop for",
        "label": "",
        "format": "Stop for",
        "layout": "row-left",
        "className": "",
        "style": false,
        "font": "",
        "fontSize": 16,
        "color": "#000000",
        "x": 2480,
        "y": 3660,
        "wires": []
    },
    {
        "id": "534c19b940d37914",
        "type": "ui_text_input",
        "z": "a9ed4fd40ab38e2f",
        "g": "b253130c6f8cee01",
        "name": "wait",
        "label": "",
        "tooltip": "",
        "group": "4368da8fe6ddbe0c",
        "order": 52,
        "width": 3,
        "height": 1,
        "passthru": true,
        "mode": "number",
        "delay": 300,
        "topic": "topic",
        "sendOnBlur": true,
        "className": "",
        "topicType": "msg",
        "x": 2630,
        "y": 3660,
        "wires": [
            [
                "cbdcde0f16615730"
            ]
        ]
    },
    {
        "id": "36d8dcdc7be1bc5c",
        "type": "ui_text",
        "z": "a9ed4fd40ab38e2f",
        "g": "b253130c6f8cee01",
        "group": "4368da8fe6ddbe0c",
        "order": 53,
        "width": 1,
        "height": 1,
        "name": "sec_wait",
        "label": "",
        "format": "sec.",
        "layout": "row-left",
        "className": "",
        "style": false,
        "font": "",
        "fontSize": 16,
        "color": "#000000",
        "x": 2780,
        "y": 3660,
        "wires": []
    },
    {
        "id": "5fade2ffa8740411",
        "type": "ui_switch",
        "z": "a9ed4fd40ab38e2f",
        "g": "b253130c6f8cee01",
        "name": "",
        "label": "",
        "tooltip": "",
        "group": "4368da8fe6ddbe0c",
        "order": 59,
        "width": 1,
        "height": 1,
        "passthru": true,
        "decouple": "false",
        "topic": "topic",
        "topicType": "msg",
        "style": "",
        "onvalue": "true",
        "onvalueType": "bool",
        "onicon": "",
        "oncolor": "",
        "offvalue": "false",
        "offvalueType": "bool",
        "officon": "",
        "offcolor": "",
        "animate": false,
        "className": "",
        "x": 2510,
        "y": 3820,
        "wires": [
            [
                "6f49e1d19bedc2d0"
            ]
        ]
    },
    {
        "id": "6f49e1d19bedc2d0",
        "type": "switch",
        "z": "a9ed4fd40ab38e2f",
        "g": "b253130c6f8cee01",
        "name": "",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "true"
            },
            {
                "t": "false"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 2670,
        "y": 3820,
        "wires": [
            [
                "df24b9d8d5a91c14",
                "346fe55eb17a8653"
            ],
            [
                "24a028056455694e"
            ]
        ]
    },
    {
        "id": "24a028056455694e",
        "type": "change",
        "z": "a9ed4fd40ab38e2f",
        "g": "b253130c6f8cee01",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "timerOnOff",
                "pt": "global",
                "to": "payload",
                "tot": "msg"
            },
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "Deactivated",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 2850,
        "y": 3860,
        "wires": [
            [
                "4e37b7047fd44050"
            ]
        ]
    },
    {
        "id": "4e37b7047fd44050",
        "type": "ui_text",
        "z": "a9ed4fd40ab38e2f",
        "g": "b253130c6f8cee01",
        "group": "4368da8fe6ddbe0c",
        "order": 60,
        "width": 3,
        "height": 1,
        "name": "",
        "label": "",
        "format": "{{msg.payload}}",
        "layout": "col-center",
        "className": "",
        "style": false,
        "font": "",
        "fontSize": 16,
        "color": "#000000",
        "x": 3030,
        "y": 3820,
        "wires": []
    },
    {
        "id": "2e94315d15790424",
        "type": "ui_ui_control",
        "z": "a9ed4fd40ab38e2f",
        "g": "b253130c6f8cee01",
        "name": "",
        "events": "all",
        "x": 2340,
        "y": 3820,
        "wires": [
            [
                "a3cdf07ae19762d8"
            ]
        ]
    },
    {
        "id": "17b6ddf9ce4c964f",
        "type": "change",
        "z": "a9ed4fd40ab38e2f",
        "g": "b253130c6f8cee01",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "dosingTime",
                "pt": "global",
                "to": "payload",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 2830,
        "y": 3500,
        "wires": [
            []
        ]
    },
    {
        "id": "011c39a44fc33165",
        "type": "ui_ui_control",
        "z": "a9ed4fd40ab38e2f",
        "g": "b253130c6f8cee01",
        "name": "",
        "events": "all",
        "x": 2240,
        "y": 3540,
        "wires": [
            [
                "3493b06c7231ed5d"
            ]
        ]
    },
    {
        "id": "3493b06c7231ed5d",
        "type": "change",
        "z": "a9ed4fd40ab38e2f",
        "g": "b253130c6f8cee01",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "dosingTime",
                "tot": "global"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 2470,
        "y": 3500,
        "wires": [
            [
                "b818f41a48b921f4"
            ]
        ]
    },
    {
        "id": "cbdcde0f16615730",
        "type": "change",
        "z": "a9ed4fd40ab38e2f",
        "g": "b253130c6f8cee01",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "waitTime",
                "pt": "global",
                "to": "payload",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 2800,
        "y": 3620,
        "wires": [
            []
        ]
    },
    {
        "id": "16cc1b6087639514",
        "type": "ui_ui_control",
        "z": "a9ed4fd40ab38e2f",
        "g": "b253130c6f8cee01",
        "name": "",
        "events": "all",
        "x": 2220,
        "y": 3660,
        "wires": [
            [
                "963d3820ded9ed33"
            ]
        ]
    },
    {
        "id": "963d3820ded9ed33",
        "type": "change",
        "z": "a9ed4fd40ab38e2f",
        "g": "b253130c6f8cee01",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "waitTime",
                "tot": "global"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 2490,
        "y": 3620,
        "wires": [
            [
                "534c19b940d37914"
            ]
        ]
    },
    {
        "id": "df24b9d8d5a91c14",
        "type": "change",
        "z": "a9ed4fd40ab38e2f",
        "g": "b253130c6f8cee01",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "timerOnOff",
                "pt": "global",
                "to": "payload",
                "tot": "msg"
            },
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "Activated",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 2850,
        "y": 3780,
        "wires": [
            [
                "4e37b7047fd44050"
            ]
        ]
    },
    {
        "id": "a3cdf07ae19762d8",
        "type": "change",
        "z": "a9ed4fd40ab38e2f",
        "g": "b253130c6f8cee01",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "timerOnOff",
                "tot": "global"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 2350,
        "y": 3760,
        "wires": [
            [
                "5fade2ffa8740411"
            ]
        ]
    },
    {
        "id": "4368da8fe6ddbe0c",
        "type": "ui_group",
        "name": "CONTROLPANEL",
        "tab": "4ad3c40739cbf998",
        "order": 2,
        "disp": true,
        "width": 15,
        "collapse": false,
        "className": ""
    },
    {
        "id": "4ad3c40739cbf998",
        "type": "ui_tab",
        "name": "Pump 1 | Petrosid | TOP",
        "icon": "fa-tasks",
        "order": 2,
        "disabled": false,
        "hidden": false
    }
]

thank you

Hi @Manuel_o

It is 22:42 here and I've not had a good day.
(you may have seen a couple of my posts here a while back today like 2 or so hours ago.)

So you want to start/stop this with only 1 button.
I'll say that like that because I don't like importing flows with dashboard stuff that isn't crucial to the workings.

I had a quick look at it.
Why are you using GLOBAL variables?
FLOW should suffice unless the variables are used elsewhere.

Thank you for the answer,

Hope tomorrow follows a better day!

I need the global becauce i want to ensure if my server restarts, every value will my stored.

i use a switch to start and stop (hopefully) my loop

best regards

This may be what you want:

Very slight mod to your flow.

[{"id":"4bb4554c7c972a86","type":"change","z":"7bd90e87b3e8c8bf","name":"payload-1","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload - 1","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1530,"y":520,"wires":[["de38aba1c1945392","ab99d24c3cce1555"]]},{"id":"5a69deb10113265e","type":"trigger","z":"7bd90e87b3e8c8bf","name":"heartbeat","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"1","extend":false,"overrideDelay":false,"units":"s","reset":"0","bytopic":"all","topic":"topic","outputs":1,"x":1350,"y":520,"wires":[["4bb4554c7c972a86"]],"outputLabels":["send \"fail\" if not feeded"]},{"id":"de38aba1c1945392","type":"link out","z":"7bd90e87b3e8c8bf","name":"link out 6","mode":"link","links":["b9bab22747a42069"],"x":1585,"y":640,"wires":[]},{"id":"ab99d24c3cce1555","type":"switch","z":"7bd90e87b3e8c8bf","name":"reached 0?","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"else"}],"checkall":"false","repair":false,"outputs":2,"x":1760,"y":520,"wires":[["1a797e1430bf8152","7d5ceb1b60d0bc62"],["d853516304c72b7c"]]},{"id":"81ac4a849519c638","type":"function","z":"7bd90e87b3e8c8bf","name":"set waitTime","func":"msg.payload = global.get(\"waitTime\")\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1140,"y":520,"wires":[["5a69deb10113265e"]]},{"id":"b9bab22747a42069","type":"link in","z":"7bd90e87b3e8c8bf","name":"link in 6","links":["de38aba1c1945392"],"x":1295,"y":640,"wires":[["5a69deb10113265e"]]},{"id":"1a797e1430bf8152","type":"debug","z":"7bd90e87b3e8c8bf","name":"Continue with flow","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":2000,"y":500,"wires":[]},{"id":"7d5ceb1b60d0bc62","type":"function","z":"7bd90e87b3e8c8bf","name":"set dosingTime","func":"msg.payload = global.get(\"dosingTime\")\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1130,"y":280,"wires":[["8317c04cd3ea0f21"]]},{"id":"d853516304c72b7c","type":"debug","z":"7bd90e87b3e8c8bf","name":"Show count down value","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":2000,"y":560,"wires":[]},{"id":"6891795a639d99ae","type":"switch","z":"7bd90e87b3e8c8bf","name":"This is the fix","property":"timerOnOff","propertyType":"global","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":1750,"y":380,"wires":[["81ac4a849519c638"]]},{"id":"346fe55eb17a8653","type":"rbe","z":"7bd90e87b3e8c8bf","name":"","func":"rbe","gap":"","start":"","inout":"out","septopics":true,"property":"payload","topi":"topic","x":1040,"y":440,"wires":[["7d5ceb1b60d0bc62"]]},{"id":"8317c04cd3ea0f21","type":"trigger","z":"7bd90e87b3e8c8bf","name":"heartbeat","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"1","extend":false,"overrideDelay":false,"units":"s","reset":"0","bytopic":"all","topic":"topic","outputs":1,"x":1350,"y":280,"wires":[["827e17c2de5cc00e","4ed20e284176d0af"]],"outputLabels":["send \"fail\" if not feeded"]},{"id":"de9b3c406b1a913d","type":"switch","z":"7bd90e87b3e8c8bf","name":"reached 0?","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"else"}],"checkall":"false","repair":false,"outputs":2,"x":1740,"y":280,"wires":[["3daf5c5af8d6b1d3","6891795a639d99ae"],["ca5bb44b69c0a099"]]},{"id":"6f49e1d19bedc2d0","type":"switch","z":"7bd90e87b3e8c8bf","g":"b253130c6f8cee01","name":"","property":"payload","propertyType":"msg","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":540,"y":540,"wires":[["df24b9d8d5a91c14","346fe55eb17a8653"],["24a028056455694e"]]},{"id":"d4aa79b97717c57b","type":"link in","z":"7bd90e87b3e8c8bf","name":"link in 5","links":["4e0a1a5af22af0a5"],"x":1335,"y":380,"wires":[["8317c04cd3ea0f21"]]},{"id":"827e17c2de5cc00e","type":"change","z":"7bd90e87b3e8c8bf","name":"payload -1","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload - 1","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1540,"y":280,"wires":[["4e0a1a5af22af0a5","de9b3c406b1a913d"]]},{"id":"4ed20e284176d0af","type":"debug","z":"7bd90e87b3e8c8bf","name":"debug 13","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1530,"y":220,"wires":[]},{"id":"3daf5c5af8d6b1d3","type":"debug","z":"7bd90e87b3e8c8bf","name":"Continue with flow","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1980,"y":240,"wires":[]},{"id":"ca5bb44b69c0a099","type":"debug","z":"7bd90e87b3e8c8bf","name":"Show count down value","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1980,"y":320,"wires":[]},{"id":"5fade2ffa8740411","type":"ui_switch","z":"7bd90e87b3e8c8bf","g":"b253130c6f8cee01","name":"","label":"","tooltip":"","group":"4368da8fe6ddbe0c","order":59,"width":1,"height":1,"passthru":true,"decouple":"false","topic":"topic","topicType":"msg","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","animate":false,"className":"","x":380,"y":540,"wires":[["6f49e1d19bedc2d0"]]},{"id":"df24b9d8d5a91c14","type":"change","z":"7bd90e87b3e8c8bf","g":"b253130c6f8cee01","name":"","rules":[{"t":"set","p":"timerOnOff","pt":"global","to":"payload","tot":"msg"},{"t":"set","p":"payload","pt":"msg","to":"Activated","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":720,"y":500,"wires":[["4e37b7047fd44050"]]},{"id":"24a028056455694e","type":"change","z":"7bd90e87b3e8c8bf","g":"b253130c6f8cee01","name":"","rules":[{"t":"set","p":"timerOnOff","pt":"global","to":"payload","tot":"msg"},{"t":"set","p":"payload","pt":"msg","to":"Deactivated","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":720,"y":580,"wires":[["4e37b7047fd44050"]]},{"id":"4e0a1a5af22af0a5","type":"link out","z":"7bd90e87b3e8c8bf","name":"link out 5","mode":"link","links":["d4aa79b97717c57b"],"x":1595,"y":380,"wires":[]},{"id":"a3cdf07ae19762d8","type":"change","z":"7bd90e87b3e8c8bf","g":"b253130c6f8cee01","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"timerOnOff","tot":"global"}],"action":"","property":"","from":"","to":"","reg":false,"x":220,"y":480,"wires":[["5fade2ffa8740411"]]},{"id":"4e37b7047fd44050","type":"ui_text","z":"7bd90e87b3e8c8bf","g":"b253130c6f8cee01","group":"4368da8fe6ddbe0c","order":60,"width":3,"height":1,"name":"","label":"","format":"{{msg.payload}}","layout":"col-center","className":"","x":900,"y":540,"wires":[]},{"id":"2e94315d15790424","type":"ui_ui_control","z":"7bd90e87b3e8c8bf","g":"b253130c6f8cee01","name":"","events":"all","x":210,"y":540,"wires":[["a3cdf07ae19762d8"]]},{"id":"4368da8fe6ddbe0c","type":"ui_group","name":"CONTROLPANEL","tab":"4ad3c40739cbf998","order":2,"disp":true,"width":15,"collapse":false,"className":""},{"id":"4ad3c40739cbf998","type":"ui_tab","name":"Pump 1 | Petrosid | TOP","icon":"fa-tasks","order":2,"disabled":false,"hidden":false}]

EDIT!

Oh, something I just considered:

Where I put the This is the fix could also be just as easily put on the other wire going back in/on the other way.

Which may be better. But I am not really sure. The hamster is getting tired upstairs. :wink:
(I'm tired)

I do hope it was helpful though.

I fear you have a misconception of what GLOBAL means as compared to FLOW.
Maybe study persistent context being stored in the file system.

The switch is ok to use.
But I can/could offer a little subroutine I wrote that gives you a push button toggle.

Here is an offer to help you with the button.

No promises.

[{"id":"402169a8.8a791","type":"subflow","name":"B Toggle 2","info":"Toggle output at receipt of message.\nConfigurable output and message to send back to button node.\n(2022 12 16)\n\nIf `msg.payload == 0` (number) the output is forced to the OFF condition.\n\nIf `msg.payload == 1` (number) the output is forced to the ON condition.\n\nAny other input toggles the output.\n\n## ENV variables:\n```\nStartMode - set start condition (`0` off `1` on).\nOnCLR - the colour when ON condition active.\nOnTXT - the text when ON condition active.\nOffCLR - the colour when OFF condition active.\nOffTXT - the text when OFF conditin active.\nON - payload when ON condition active.\nOFF - payload when OFF condition active.\nCTOPIC - the topic of the output message.\n```\n\nOutputs:\n - 1 $OFF for OFF and $ON for ON.\n - 2 $ON for OFF and $OFF for ON.  (Opposite of 1)\n - 3 to be sent back to button with `msg.colour` to set buttons colour and `msg.txt` for the text to be displayed.\n","category":"","in":[{"x":80,"y":190,"wires":[{"id":"69ae694095adea75"}]}],"out":[{"x":670,"y":180,"wires":[{"id":"5a9848b4303ef8d2","port":0},{"id":"8c41e6c213bcdefe","port":0}]},{"x":670,"y":280,"wires":[{"id":"3a564786d2308bdd","port":0},{"id":"a2ec504194f78107","port":0}]},{"x":670,"y":380,"wires":[{"id":"f14d0daf4ad33691","port":0},{"id":"aff48be4199bcfab","port":0}]}],"env":[{"name":"StartMode","type":"num","value":"","ui":{"type":"input","opts":{"types":["num"]}}},{"name":"OffTXT","type":"str","value":"","ui":{"type":"input","opts":{"types":["str","num"]}}},{"name":"OffCLR","type":"str","value":"","ui":{"type":"input","opts":{"types":["str"]}}},{"name":"OnTXT","type":"str","value":"","ui":{"type":"input","opts":{"types":["str","num"]}}},{"name":"OnCLR","type":"str","value":"","ui":{"type":"input","opts":{"types":["str"]}}},{"name":"OFF","type":"str","value":""},{"name":"ON","type":"str","value":""},{"name":"CTOPIC","type":"str","value":""}],"meta":{},"color":"#D8BFD8","outputLabels":["Normal output","Inverted output","To button"],"icon":"node-red-dashboard/ui_switch.png"},{"id":"69ae694095adea75","type":"function","z":"402169a8.8a791","name":"toggle","func":"var x = context.get(\"counter\") || 0;\nif (msg.payload == 0)\n{\n    context.set(\"counter\",0);\n    msg.payload = 0;\n    return msg;\n}\nif (msg.payload == 1)\n{\n    context.set(\"counter\",1);\n    msg.payload = 1;\n    return msg;\n}\n\nif (x === 0)\n{\n    msg.payload = 1;\n} else\nif (x === 1)\n{\n    msg.payload = 0;\n}\n\nx = (x + 1) % 2;\n\ncontext.set(\"counter\",x);\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":210,"y":190,"wires":[["63da8f2c6a34b348","0db7c2da3958ea2c"]],"info":"##  Outputs `1` or `0` for ON/OFF and `msg.colour` to send to button."},{"id":"63da8f2c6a34b348","type":"switch","z":"402169a8.8a791","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"eq","v":"1","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":350,"y":380,"wires":[["f14d0daf4ad33691"],["aff48be4199bcfab"]]},{"id":"f14d0daf4ad33691","type":"change","z":"402169a8.8a791","name":"OFF","rules":[{"t":"set","p":"colour","pt":"msg","to":"OffCLR","tot":"env"},{"t":"set","p":"txt","pt":"msg","to":"OffTXT","tot":"env"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":350,"wires":[[]]},{"id":"aff48be4199bcfab","type":"change","z":"402169a8.8a791","name":"ON","rules":[{"t":"set","p":"colour","pt":"msg","to":"OnCLR","tot":"env"},{"t":"set","p":"txt","pt":"msg","to":"OnTXT","tot":"env"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":410,"wires":[[]]},{"id":"0db7c2da3958ea2c","type":"switch","z":"402169a8.8a791","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"eq","v":"1","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":350,"y":190,"wires":[["5a9848b4303ef8d2","3a564786d2308bdd"],["8c41e6c213bcdefe","a2ec504194f78107"]]},{"id":"5a9848b4303ef8d2","type":"change","z":"402169a8.8a791","name":"OFF","rules":[{"t":"set","p":"payload","pt":"msg","to":"OFF","tot":"env"},{"t":"set","p":"topic","pt":"msg","to":"CTOPIC","tot":"env"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":160,"wires":[[]]},{"id":"8c41e6c213bcdefe","type":"change","z":"402169a8.8a791","name":"ON","rules":[{"t":"set","p":"payload","pt":"msg","to":"ON","tot":"env"},{"t":"set","p":"topic","pt":"msg","to":"CTOPIC","tot":"env"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":210,"wires":[[]]},{"id":"a2ec504194f78107","type":"change","z":"402169a8.8a791","name":"OFF","rules":[{"t":"set","p":"payload","pt":"msg","to":"OFF","tot":"env"},{"t":"set","p":"topic","pt":"msg","to":"CTOPIC","tot":"env"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":300,"wires":[[]]},{"id":"3a564786d2308bdd","type":"change","z":"402169a8.8a791","name":"ON","rules":[{"t":"set","p":"payload","pt":"msg","to":"ON","tot":"env"},{"t":"set","p":"topic","pt":"msg","to":"CTOPIC","tot":"env"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":250,"wires":[[]]},{"id":"a035346e85f036ba","type":"inject","z":"402169a8.8a791","name":"Start Mode","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":"0.2","topic":"","payload":"StartMode","payloadType":"env","x":130,"y":140,"wires":[["69ae694095adea75"]]},{"id":"6cf385ba2226d927","type":"switch","z":"7bd90e87b3e8c8bf","name":"","property":"payload","propertyType":"msg","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":540,"y":790,"wires":[["a806b68ceb28c7e6"],["5d665e5c17f5fdcb"]]},{"id":"572cc70defa822ad","type":"subflow:402169a8.8a791","z":"7bd90e87b3e8c8bf","name":"","env":[{"name":"StartMode","value":"0","type":"num"},{"name":"OffTXT","value":"OFF","type":"str"},{"name":"OffCLR","value":"green","type":"str"},{"name":"OnTXT","value":"ON","type":"str"},{"name":"OnCLR","value":"blue","type":"str"},{"name":"OFF","value":"false","type":"bool"},{"name":"ON","value":"true","type":"bool"}],"x":360,"y":800,"wires":[["6cf385ba2226d927"],[],["8df579d48bd6ff7e"]]},{"id":"a806b68ceb28c7e6","type":"change","z":"7bd90e87b3e8c8bf","name":"","rules":[{"t":"set","p":"timerOnOff","pt":"global","to":"payload","tot":"msg"},{"t":"set","p":"payload","pt":"msg","to":"Activated","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":720,"y":750,"wires":[["529c168371577cc2"]]},{"id":"5d665e5c17f5fdcb","type":"change","z":"7bd90e87b3e8c8bf","name":"","rules":[{"t":"set","p":"timerOnOff","pt":"global","to":"payload","tot":"msg"},{"t":"set","p":"payload","pt":"msg","to":"Deactivated","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":720,"y":830,"wires":[["529c168371577cc2"]]},{"id":"8df579d48bd6ff7e","type":"ui_button","z":"7bd90e87b3e8c8bf","name":"","group":"4368da8fe6ddbe0c","order":8,"width":0,"height":0,"passthru":false,"label":"{{msg.txt}}","tooltip":"","color":"{{msg.fontclr}}","bgcolor":"{{msg.colour}}","className":"","icon":"","payload":"X","payloadType":"str","topic":"topic","topicType":"msg","x":360,"y":730,"wires":[["572cc70defa822ad"]]},{"id":"529c168371577cc2","type":"ui_text","z":"7bd90e87b3e8c8bf","group":"4368da8fe6ddbe0c","order":60,"width":3,"height":1,"name":"","label":"","format":"{{msg.payload}}","layout":"col-center","className":"","x":900,"y":790,"wires":[]},{"id":"4368da8fe6ddbe0c","type":"ui_group","name":"CONTROLPANEL","tab":"4ad3c40739cbf998","order":2,"disp":true,"width":15,"collapse":false,"className":""},{"id":"4ad3c40739cbf998","type":"ui_tab","name":"Pump 1 | Petrosid | TOP","icon":"fa-tasks","order":2,"disabled":false,"hidden":false}]

Small part of your flow included to show you where it goes.

I'm not sure with the input.
But it shouldn't be too hard to work out.

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