Enable/Disable flow with ui-switch

Hi,

i have a beginner question regarding the ui-switch node. I'd like to implement a simple switch on my dashboard, that enables or disables my flow.

I have installed node-red-dashboard and the node-red-contrib-simple-gate, but somehow I don't understand how to combine them for my purpose.

Here is my minimalistic example:

[
    {
        "id": "9a8553e14bb1cc9d",
        "type": "tab",
        "label": "Flow 2",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "b9e5085e15f1babf",
        "type": "ui_switch",
        "z": "9a8553e14bb1cc9d",
        "name": "",
        "label": "switch",
        "tooltip": "",
        "group": "964cdbdcb3249390",
        "order": 4,
        "width": 0,
        "height": 0,
        "passthru": true,
        "decouple": "false",
        "topic": "topic",
        "topicType": "msg",
        "style": "",
        "onvalue": "open",
        "onvalueType": "str",
        "onicon": "",
        "oncolor": "",
        "offvalue": "close",
        "offvalueType": "str",
        "officon": "",
        "offcolor": "",
        "animate": false,
        "className": "",
        "x": 230,
        "y": 280,
        "wires": [
            [
                "88246deac1f51cae"
            ]
        ]
    },
    {
        "id": "88246deac1f51cae",
        "type": "gate",
        "z": "9a8553e14bb1cc9d",
        "name": "",
        "controlTopic": "control",
        "defaultState": "open",
        "openCmd": "open",
        "closeCmd": "close",
        "toggleCmd": "toggle",
        "defaultCmd": "default",
        "statusCmd": "status",
        "persist": false,
        "storeName": "memory",
        "x": 370,
        "y": 280,
        "wires": [
            [
                "9f7fad418f51df8b"
            ]
        ]
    },
    {
        "id": "b2d8499f2336d2c2",
        "type": "inject",
        "z": "9a8553e14bb1cc9d",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 100,
        "y": 280,
        "wires": [
            [
                "b9e5085e15f1babf"
            ]
        ]
    },
    {
        "id": "9f7fad418f51df8b",
        "type": "debug",
        "z": "9a8553e14bb1cc9d",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 550,
        "y": 280,
        "wires": []
    },
    {
        "id": "964cdbdcb3249390",
        "type": "ui_group",
        "name": "Test",
        "tab": "8d1f136120e3ada3",
        "order": 1,
        "disp": true,
        "width": "6",
        "collapse": false,
        "className": ""
    },
    {
        "id": "8d1f136120e3ada3",
        "type": "ui_tab",
        "name": "Testme",
        "icon": "dashboard",
        "disabled": false,
        "hidden": false
    }
]

Expected behaviour

  • Switch is off: Nothing is sent to the debug node
  • Switch is on: the timestamp is sent to the debug node
  • When the switch is "triggered": nothing is sent to the debug node

Actual behaviour

  • When I flip the switch to "on", I get "open" at the debug node
  • When I flip the switch to "off", I get "close" at the debug node
  • When I inject the timestamp, I get the current state of the gate node

I feel like this is a very easy thing to do, but I can't get my head around it.

In my productive flow, the inject node is a http-post node. So, I'd like to control if http-post messages are processed or not by using a flip switch on my dashboard.

Thanks for any hints
Michael;

The switch node should have a topic set control in this case, and should be on its own wire
e.g

[{"id":"b9e5085e15f1babf","type":"ui_switch","z":"9a8553e14bb1cc9d","name":"","label":"switch","tooltip":"","group":"964cdbdcb3249390","order":4,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"control","topicType":"str","style":"","onvalue":"open","onvalueType":"str","onicon":"","oncolor":"","offvalue":"close","offvalueType":"str","officon":"","offcolor":"","animate":false,"className":"","x":250,"y":200,"wires":[["88246deac1f51cae"]]},{"id":"88246deac1f51cae","type":"gate","z":"9a8553e14bb1cc9d","name":"","controlTopic":"control","defaultState":"open","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","statusCmd":"status","persist":false,"storeName":"memory","x":370,"y":280,"wires":[["9f7fad418f51df8b"]]},{"id":"b2d8499f2336d2c2","type":"inject","z":"9a8553e14bb1cc9d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":100,"y":280,"wires":[["88246deac1f51cae"]]},{"id":"9f7fad418f51df8b","type":"debug","z":"9a8553e14bb1cc9d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":550,"y":280,"wires":[]},{"id":"964cdbdcb3249390","type":"ui_group","name":"Test","tab":"8d1f136120e3ada3","order":1,"disp":true,"width":"6","collapse":false,"className":""},{"id":"8d1f136120e3ada3","type":"ui_tab","name":"Testme","icon":"dashboard","disabled":false,"hidden":false}]

Then when switch on the injected timestamp should pass, and when off blocked.

Yep, that was the solution. Thanks a lot!

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