Using dashboard switch to trigger data logging in the underlying flow?

Thank's to help from the forum users, I manage to get data from sensors, combined and formatted/sorted them and finnaly store them to a folder for later analysis.
In parallel I use dashboard to visualize the data. A simple monitoring dash with graph and labels.
Now that this is working the last thing I would like to achieve is to control wether or not I start recording the data and I want to do this using a button or switch on te dashboard.

I don't understand how to implement the switch. I though it would be simple! Here is a simple dashboard/flow to attemp at triggering something:

[
    {
        "id": "f60891e11f2ae0bd",
        "type": "tab",
        "label": "Flow 3",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "81a66d48b039abd2",
        "type": "inject",
        "z": "f60891e11f2ae0bd",
        "name": "Data in",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "1",
        "crontab": "",
        "once": false,
        "onceDelay": "0",
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 180,
        "y": 160,
        "wires": [
            [
                "cc92ac8ad9607b7b",
                "9abfb14f90aa98e3"
            ]
        ]
    },
    {
        "id": "cc92ac8ad9607b7b",
        "type": "switch",
        "z": "f60891e11f2ae0bd",
        "name": "True/false",
        "property": "topic",
        "propertyType": "msg",
        "rules": [
            {
                "t": "true"
            },
            {
                "t": "false"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 380,
        "y": 160,
        "wires": [
            [
                "834069390ae63af1"
            ],
            []
        ]
    },
    {
        "id": "235648a4c17ae6c7",
        "type": "ui_switch",
        "z": "f60891e11f2ae0bd",
        "name": "",
        "label": "switch",
        "tooltip": "",
        "group": "16f8a9442c6a9a31",
        "order": 1,
        "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": 270,
        "y": 60,
        "wires": [
            [
                "cc92ac8ad9607b7b"
            ]
        ]
    },
    {
        "id": "834069390ae63af1",
        "type": "debug",
        "z": "f60891e11f2ae0bd",
        "name": "debug 2490",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": true,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 570,
        "y": 120,
        "wires": []
    },
    {
        "id": "9abfb14f90aa98e3",
        "type": "debug",
        "z": "f60891e11f2ae0bd",
        "name": "debug 2491",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": true,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 260,
        "y": 280,
        "wires": []
    },
    {
        "id": "16f8a9442c6a9a31",
        "type": "ui_group",
        "name": "Text_data",
        "tab": "6a0aa1baf854d833",
        "order": 4,
        "disp": true,
        "width": 7,
        "collapse": false,
        "className": ""
    },
    {
        "id": "6a0aa1baf854d833",
        "type": "ui_tab",
        "name": "Tab 1",
        "icon": "dashboard",
        "order": 1
    }
]

I search the forum for things like trigger flow and dashboard triggers / switch but found nothing. Maybe I am not using the good keywords. There must be something simliar available?

Use the switch to set a context variable, then use that context var in the switch node.
e.g

[{"id":"235648a4c17ae6c7","type":"ui_switch","z":"f60891e11f2ae0bd","name":"","label":"switch","tooltip":"","group":"16f8a9442c6a9a31","order":1,"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":210,"y":60,"wires":[["8df051a49f72e170"]]},{"id":"81a66d48b039abd2","type":"inject","z":"f60891e11f2ae0bd","name":"Data in","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"1","crontab":"","once":false,"onceDelay":"0","topic":"","payload":"","payloadType":"date","x":180,"y":160,"wires":[["cc92ac8ad9607b7b","9abfb14f90aa98e3"]]},{"id":"cc92ac8ad9607b7b","type":"switch","z":"f60891e11f2ae0bd","name":"True/false","property":"record","propertyType":"flow","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":380,"y":160,"wires":[["834069390ae63af1"],[]]},{"id":"9abfb14f90aa98e3","type":"debug","z":"f60891e11f2ae0bd","name":"debug 2491","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":260,"y":280,"wires":[]},{"id":"834069390ae63af1","type":"debug","z":"f60891e11f2ae0bd","name":"debug 2490","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":570,"y":120,"wires":[]},{"id":"8df051a49f72e170","type":"change","z":"f60891e11f2ae0bd","name":"","rules":[{"t":"set","p":"record","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":380,"y":60,"wires":[[]]},{"id":"16f8a9442c6a9a31","type":"ui_group","name":"Text_data","tab":"6a0aa1baf854d833","order":4,"disp":true,"width":7,"collapse":false,"className":""},{"id":"6a0aa1baf854d833","type":"ui_tab","name":"Tab 1","icon":"dashboard","order":1}]

Or use node-red-contrib-simple-gate

Thank you! exactly what I am looking for.

I think I understand your solution but I am unsure about the difference between flow and msg? and there is also global?

in any case thanks for your help.

This is all mentioned in the docs Working with context : Node-RED

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