Confirmation button before sending out data

How would you do this:

You select your data via a dropdown, textfield or whatever and when you are finished you have like a submit button, so like a confirmation before you send data further in the flow.

Should you go for a button node, a form, a template,.... ?

The issue is when I select data from a dropdown list now it immediately sends the data further up the flow (In my case an SNMP set node) But if you select the wrong value in the list you could really screw up. So like a "confirmation/send button" would be practical.

Are you talking about the node-red-dashboard or a node you are creating?

Node-red dashboard. So within the pre-defined tools of the palette.
As a beginner I have to stick to that.

So I have moved this into the channel that is just for the #dashboard

Have your drop-downs and text fields feed into change nodes that store there payloads into flow context e.g flow.mib etc.

Then have a button that performs the operation you want after all fields are complete.

You could even have the button feed into a function node to verify users input.

Simple function node code that may give you some ideas....

var mib = flow.get("mib")
var val=flow.get("val");
if(!mib){
  node.error("mib is empty");
  return null;// halt flow / don't pass msg to next node
}
if(!val){
  node.error("val is empty");
  return null;// halt flow / don't pass msg to next node
}
msg.payload ={
  mib : mib, val : val
}
return msg;

Give it a try then if you get stuck, post your progress and issue here and someone will help.

1 Like

So if I use a flow instead off msg a button will work ?
I just added the change node to set msg.payload to flow.mib and I believe the function has a problem already.

[{"id":"7d9a835b.ba0d1c","type":"ui_dropdown","z":"3b93f73c.7a4e48","name":"","label":"","tooltip":"","place":"Select option","group":"ee8b6e07.f565e","order":11,"width":0,"height":0,"passthru":true,"options":[{"label":"14200","value":"14200000000","type":"str"},{"label":"14300","value":"14300000000","type":"str"},{"label":"14400","value":"14400000000","type":"str"},{"label":"14412","value":"1441200000","type":"str"}],"payload":"","topic":"","x":220,"y":480,"wires":[["f832d303.08759"]]},{"id":"96e10326.5b816","type":"function","z":"3b93f73c.7a4e48","name":"","func":"msg.payload = flow.mib;\nmsg.varbinds = [\n    {\n        \"host\": \"192.168.0.34\",\n        \"version\": \"1\",\n        \"oid\":   \"1.3.6.1.4.1.5835.3.1.3.1.38.1.1\",\n        \"type\":  \"OctetString\",\n         \"value\": \"\"+msg.payload+\"\"\n    }\n]\nreturn msg;","outputs":1,"noerr":0,"x":510,"y":480,"wires":[["b6a29476.7dd068"]]},{"id":"b6a29476.7dd068","type":"snmp set","z":"3b93f73c.7a4e48","host":"192.168.0.34","community":"public","version":"1","varbinds":"","timeout":5,"name":"","x":800,"y":480,"wires":[]},{"id":"f832d303.08759","type":"change","z":"3b93f73c.7a4e48","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"mib","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":380,"y":580,"wires":[["96e10326.5b816"]]},{"id":"ee8b6e07.f565e","type":"ui_group","z":"","name":"SET","tab":"f0a3f99c.51e178","disp":true,"width":"6","collapse":false},{"id":"f0a3f99c.51e178","type":"ui_tab","z":"","name":"Test","icon":"dashboard","order":6,"disabled":false,"hidden":false}]

not quite. You have several issues in your flow.

  1. Dont use flow.mib. Use flow.get("mib") as per my example code
  2. You have the change node the wrong way around
  3. You are still feeding the dropdown directly into the SNMP function (i.e. there is no button)

Look at this example...

Here is the flow...

[{"id":"fbd40f86.852f8","type":"ui_dropdown","z":"4d4cd124.3da23","name":"","label":"","tooltip":"","place":"Select option","group":"c8d83136.ccafb","order":2,"width":0,"height":0,"passthru":true,"options":[{"label":"14200","value":"14200000000","type":"str"},{"label":"14300","value":"14300000000","type":"str"},{"label":"14400","value":"14400000000","type":"str"},{"label":"14412","value":"1441200000","type":"str"}],"payload":"","topic":"","x":120,"y":160,"wires":[["19557639.77855a"]]},{"id":"1a413224.98f57e","type":"function","z":"4d4cd124.3da23","name":"Check user input and construct varbinds","func":"var host = flow.get(\"host\");\nvar mib = flow.get(\"mib\");\nif(!host){\n    node.error(\"host is empty\",msg)\n    return null; //halt flow\n}\nif(!mib){\n    node.error(\"mib is empty\",msg)\n    return null; //halt flow\n}\n\nmsg.varbinds = [\n    {\n        \"host\": host,\n        \"version\": \"1\",\n        \"oid\":   \"1.3.6.1.4.1.5835.3.1.3.1.38.1.1\",\n        \"type\":  \"OctetString\",\n         \"value\": mib\n    }\n]\n//temporary debug - set payload with string version for demo notification\n\nmsg.payload = \"All fields OK. This is what varbinds contains...\\n\" +  JSON.stringify(msg.varbinds);\nreturn msg;","outputs":1,"noerr":0,"x":360,"y":340,"wires":[["c1cb63eb.75689","542e8ba8.3278b4"]]},{"id":"19557639.77855a","type":"change","z":"4d4cd124.3da23","name":"","rules":[{"t":"set","p":"mib","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":270,"y":160,"wires":[[]]},{"id":"a363a4de.2942a8","type":"ui_text_input","z":"4d4cd124.3da23","name":"","label":"Host","tooltip":"","group":"c8d83136.ccafb","order":1,"width":0,"height":0,"passthru":true,"mode":"text","delay":"200","topic":"val","x":110,"y":220,"wires":[["3d7d36c3.cf654a"]]},{"id":"3d7d36c3.cf654a","type":"change","z":"4d4cd124.3da23","name":"","rules":[{"t":"set","p":"host","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":270,"y":220,"wires":[[]]},{"id":"3545c6e2.03732a","type":"ui_button","z":"4d4cd124.3da23","name":"","group":"c8d83136.ccafb","order":3,"width":0,"height":0,"passthru":false,"label":"button","tooltip":"","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"","x":110,"y":340,"wires":[["1a413224.98f57e"]]},{"id":"c1cb63eb.75689","type":"debug","z":"4d4cd124.3da23","name":"To SNMP (view result in debug window)","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":460,"y":420,"wires":[]},{"id":"542e8ba8.3278b4","type":"ui_toast","z":"4d4cd124.3da23","position":"top right","displayTime":"4","highlight":"green","sendall":true,"outputs":0,"ok":"OK","cancel":"","topic":"","name":"","x":530,"y":300,"wires":[]},{"id":"fb1faea6.69f62","type":"catch","z":"4d4cd124.3da23","name":"","scope":null,"uncaught":false,"x":120,"y":520,"wires":[["e72e4047.df5bf"]]},{"id":"4f9d7d2d.ea0244","type":"ui_toast","z":"4d4cd124.3da23","position":"top right","displayTime":"4","highlight":"red","sendall":true,"outputs":0,"ok":"OK","cancel":"","topic":"","name":"","x":470,"y":520,"wires":[]},{"id":"e72e4047.df5bf","type":"change","z":"4d4cd124.3da23","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"error.message","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":280,"y":520,"wires":[["4f9d7d2d.ea0244"]]},{"id":"c8d83136.ccafb","type":"ui_group","z":"","name":"SET","tab":"f04ca30d.9a3d7","disp":true,"width":"6","collapse":false},{"id":"f04ca30d.9a3d7","type":"ui_tab","z":"","name":"Test","icon":"dashboard","order":6,"disabled":false,"hidden":false}]

Shameless self-promotion: node-red-contrib-queue-gate has a feature designed for almost exactly this case. It can be configured to retain the most recent message and release it when it receives a trigger. (This is described in the README.) If you try it and have any difficulty, please ask.

Hi,

this is my solution for a switch

[
    {
        "id": "1ecd74793421c246",
        "type": "mqtt out",
        "z": "9af33632a58e2885",
        "name": "",
        "topic": "cmnd/Trockner/POWER",
        "qos": "",
        "retain": "",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "1e6b0fe9ec3d64aa",
        "x": 950,
        "y": 1060,
        "wires": []
    },
    {
        "id": "077433b02f00bb40",
        "type": "ui_switch",
        "z": "9af33632a58e2885",
        "name": "Strom",
        "label": "Strom an:",
        "tooltip": "",
        "group": "05c27adb2472b756",
        "order": 14,
        "width": 0,
        "height": 0,
        "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": 710,
        "y": 980,
        "wires": [
            [
                "501b3a83378182ca"
            ]
        ]
    },
    {
        "id": "3304137bb0312a3d",
        "type": "mqtt in",
        "z": "9af33632a58e2885",
        "name": "",
        "topic": "tele/Trockner/STATE",
        "qos": "2",
        "datatype": "json",
        "broker": "1e6b0fe9ec3d64aa",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 210,
        "y": 980,
        "wires": [
            [
                "0e28b727b3406c2a",
                "456642fa78bc5939"
            ]
        ]
    },
    {
        "id": "0e28b727b3406c2a",
        "type": "debug",
        "z": "9af33632a58e2885",
        "name": "State",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 510,
        "y": 920,
        "wires": []
    },
    {
        "id": "456642fa78bc5939",
        "type": "function",
        "z": "9af33632a58e2885",
        "name": "",
        "func": "if (msg.payload.POWER === \"OFF\") {msg.payload = false;}\nelse  {msg.payload = true;}\nflow.set(\"PowerSwitch\",msg.payload)\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 520,
        "y": 980,
        "wires": [
            [
                "077433b02f00bb40"
            ]
        ]
    },
    {
        "id": "65dad93492fdcb98",
        "type": "ui_toast",
        "z": "9af33632a58e2885",
        "position": "dialog",
        "displayTime": "3",
        "highlight": "",
        "sendall": true,
        "outputs": 1,
        "ok": "OK",
        "cancel": "Cancel",
        "raw": false,
        "className": "",
        "topic": "",
        "name": "Deploy?",
        "x": 540,
        "y": 1060,
        "wires": [
            [
                "bafe239da63c437e"
            ]
        ]
    },
    {
        "id": "bafe239da63c437e",
        "type": "function",
        "z": "9af33632a58e2885",
        "name": "Confirm",
        "func": "var newMsg = { payload: flow.get(\"PowerSwitchTemp\")};\n//only accept OK msg's\nif (msg.payload == 'OK') {\n    //msg.payload = \"Stop\";\n    flow.set(\"PowerSwitch\",newMsg.payload)\n    return[newMsg, newMsg];\n}\nnewMsg.payload = !newMsg.payload\n flow.set(\"PowerSwitch\",newMsg.payload)\n return[ newMsg, null]",
        "outputs": 2,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 720,
        "y": 1060,
        "wires": [
            [
                "077433b02f00bb40"
            ],
            [
                "1ecd74793421c246",
                "83ada66a7e43600b"
            ]
        ]
    },
    {
        "id": "501b3a83378182ca",
        "type": "function",
        "z": "9af33632a58e2885",
        "name": "",
        "func": "if(flow.get(\"PowerSwitch\") != msg.payload )\n{\n//node.warn(\"PowerSwitch = \" + flow.get(\"PowerSwitch\") )     \nflow.set(\"PowerSwitch\",msg.payload)\nflow.set(\"PowerSwitchTemp\",msg.payload)\n//node.warn(\"PowerSwitch = \" + flow.get(\"PowerSwitch\") )  \nif (msg.payload) {msg.payload = \"Wolen Sie wirklich einschalten ?\" }\nelse {msg.payload = \"Wolen Sie wirklich ausschalten ?\" }\n\nreturn msg;\n}\nreturn null",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 900,
        "y": 980,
        "wires": [
            [
                "65dad93492fdcb98"
            ]
        ]
    },
    {
        "id": "b030c851bd80051d",
        "type": "inject",
        "z": "9af33632a58e2885",
        "name": "OFF",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "{\"Time\":\"2022-05-04T15:58:20\",\"Uptime\":\"7T06:42:17\",\"UptimeSec\":628937,\"Heap\":26,\"SleepMode\":\"Dynamic\",\"Sleep\":50,\"LoadAvg\":19,\"MqttCount\":18,\"POWER\":\"OFF\",\"Wifi\":{\"AP\":1,\"SSId\":\"ELVA\",\"BSSId\":\"34:81:C4:B8:D6:8C\",\"Channel\":1,\"Mode\":\"11n\",\"RSSI\":100,\"Signal\":-38,\"LinkCount\":17,\"Downtime\":\"0T00:01:28\"}}",
        "payloadType": "json",
        "x": 230,
        "y": 920,
        "wires": [
            [
                "456642fa78bc5939"
            ]
        ]
    },
    {
        "id": "7d9f43e16609d322",
        "type": "inject",
        "z": "9af33632a58e2885",
        "name": "ON",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "{\"Time\":\"2022-05-04T15:58:20\",\"Uptime\":\"7T06:42:17\",\"UptimeSec\":628937,\"Heap\":26,\"SleepMode\":\"Dynamic\",\"Sleep\":50,\"LoadAvg\":19,\"MqttCount\":18,\"POWER\":\"ON\",\"Wifi\":{\"AP\":1,\"SSId\":\"ELVA\",\"BSSId\":\"34:81:C4:B8:D6:8C\",\"Channel\":1,\"Mode\":\"11n\",\"RSSI\":100,\"Signal\":-38,\"LinkCount\":17,\"Downtime\":\"0T00:01:28\"}}",
        "payloadType": "json",
        "x": 230,
        "y": 880,
        "wires": [
            [
                "456642fa78bc5939"
            ]
        ]
    },
    {
        "id": "83ada66a7e43600b",
        "type": "debug",
        "z": "9af33632a58e2885",
        "name": "",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 910,
        "y": 1120,
        "wires": []
    },
    {
        "id": "1e6b0fe9ec3d64aa",
        "type": "mqtt-broker",
        "name": "VALET",
        "broker": "192.168.66.12",
        "port": "1883",
        "clientid": "",
        "autoConnect": true,
        "usetls": false,
        "protocolVersion": "4",
        "keepalive": "60",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "birthMsg": {},
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "closeMsg": {},
        "willTopic": "",
        "willQos": "0",
        "willPayload": "",
        "willMsg": {},
        "sessionExpiry": ""
    },
    {
        "id": "05c27adb2472b756",
        "type": "ui_group",
        "name": "Trockner",
        "tab": "43d098ab158da588",
        "order": 2,
        "disp": true,
        "width": "6",
        "collapse": false,
        "className": ""
    },
    {
        "id": "43d098ab158da588",
        "type": "ui_tab",
        "name": "Waschen",
        "icon": "dashboard",
        "order": 3,
        "disabled": false,
        "hidden": false
    }
]