Dashboard toggle button without switch

Hello together,

I am trying to build in a button into my dashboard, which should:
... show a status (1 of 3 different possibles) with the according icon.
... provide the possibility to toggle the status and provide a dynamic output (e.g. based on the currently showed icon).

I would use the switch button, but this does not work, because I want to influence the icon with the input as I have to differentiate three different types of it (weekend, home, public).

So the output (button pressed) should contain the current status, which does not work as I can only specify a static topic and a static value.

I think I will be able to handle this with a context variable to save the current status/icon, but does anyone has a clue how to build the toggle w/o context variable? If not, I will do it of course with the context variable, but just want to ask, if anyone had the same issue in the past.

I attached the beginning of my ideas with the button and the different input:

[
    {
        "id": "2f8a5b8b.3b3d84",
        "type": "ui_button",
        "z": "4e44f1f8.f25318",
        "name": "Ranki",
        "group": "966d0c6c.5b7048",
        "order": 8,
        "width": "1",
        "height": "1",
        "passthru": false,
        "label": "",
        "tooltip": "{{tooltip}}",
        "color": " #0079F2",
        "bgcolor": "#FFFFFF",
        "icon": "{{myicon}}",
        "payload": "true",
        "payloadType": "bool",
        "topic": "Button pressed",
        "x": 2430,
        "y": 640,
        "wires": [
            [
                "7e916ace.8d13a4"
            ]
        ]
    },
    {
        "id": "3cc7c581.af95da",
        "type": "inject",
        "z": "4e44f1f8.f25318",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 2080,
        "y": 600,
        "wires": [
            [
                "544dcc8e.4abdb4"
            ]
        ]
    },
    {
        "id": "544dcc8e.4abdb4",
        "type": "change",
        "z": "4e44f1f8.f25318",
        "name": "Ranki Home",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "true",
                "tot": "bool"
            },
            {
                "t": "set",
                "p": "myicon",
                "pt": "msg",
                "to": "home",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "tooltip",
                "pt": "msg",
                "to": "Ranki@Home",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 2250,
        "y": 600,
        "wires": [
            [
                "2f8a5b8b.3b3d84"
            ]
        ]
    },
    {
        "id": "f8e9468d.7d8b88",
        "type": "change",
        "z": "4e44f1f8.f25318",
        "name": "Ranki Base",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "true",
                "tot": "bool"
            },
            {
                "t": "set",
                "p": "myicon",
                "pt": "msg",
                "to": "weekend",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "tooltip",
                "pt": "msg",
                "to": "Ranki@Base",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 2250,
        "y": 640,
        "wires": [
            [
                "2f8a5b8b.3b3d84"
            ]
        ]
    },
    {
        "id": "d91ccfae.ecd93",
        "type": "inject",
        "z": "4e44f1f8.f25318",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 2080,
        "y": 640,
        "wires": [
            [
                "f8e9468d.7d8b88"
            ]
        ]
    },
    {
        "id": "7d223aba.322464",
        "type": "change",
        "z": "4e44f1f8.f25318",
        "name": "Ranki away",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "true",
                "tot": "bool"
            },
            {
                "t": "set",
                "p": "myicon",
                "pt": "msg",
                "to": "public",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "tooltip",
                "pt": "msg",
                "to": "Ranki away",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 2250,
        "y": 680,
        "wires": [
            [
                "2f8a5b8b.3b3d84"
            ]
        ]
    },
    {
        "id": "43957dd0.142034",
        "type": "inject",
        "z": "4e44f1f8.f25318",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 2080,
        "y": 680,
        "wires": [
            [
                "7d223aba.322464"
            ]
        ]
    },
    {
        "id": "7e916ace.8d13a4",
        "type": "debug",
        "z": "4e44f1f8.f25318",
        "name": "",
        "active": true,
        "console": "false",
        "complete": "true",
        "x": 2570,
        "y": 640,
        "wires": []
    },
    {
        "id": "966d0c6c.5b7048",
        "type": "ui_group",
        "name": "Uhrzeit",
        "tab": "14d26b61.40ec4d",
        "order": 1,
        "disp": false,
        "width": "6",
        "collapse": false
    },
    {
        "id": "14d26b61.40ec4d",
        "type": "ui_tab",
        "name": "Smart Boot",
        "icon": "fa-anchor",
        "order": 1,
        "disabled": false,
        "hidden": false
    }
]

Cheers
Ranki

Hi.

You might be better doing this in a template node rather than maintain state in context at server side.

This rather larger demo I did for another user might provide some cues. In particular the mute button that toggles icon. You could use the same design patter to create a 3 state button.

See this thread.

Hi @Steve-Mcl,

I am currently using a template node, but I wanted to make it "smaller" with just one element :upside_down_face:; I'll check your solution out and see, what I will implement. Thank you!

Cheers
Ranki

Hello together,

I did it now with a context variable (flow), which is quite easy (see attached flow), but it would be great, if the dashboard-button could save any kind of information (maybe defined with {{status}}, which will be handed over to it's outgoing payload, if the button is pressed.

My way now:
I save the icon sent in the context «flow.icon». The change after the button gets the flow.icon and adds it to the msg.

Afterwards I differentiate the output of the button with a switch to set another button stage. :slight_smile:

Cheers
Ranki

[
    {
        "id": "2f8a5b8b.3b3d84",
        "type": "ui_button",
        "z": "4e44f1f8.f25318",
        "name": "toggle button",
        "group": "966d0c6c.5b7048",
        "order": 8,
        "width": "1",
        "height": "1",
        "passthru": false,
        "label": "",
        "tooltip": "{{tooltip}}",
        "color": " #0079F2",
        "bgcolor": "#FFFFFF",
        "icon": "{{myicon}}",
        "payload": "true",
        "payloadType": "bool",
        "topic": "toggle_button",
        "x": 2470,
        "y": 660,
        "wires": [
            [
                "7247a753.fc5448"
            ]
        ]
    },
    {
        "id": "3cc7c581.af95da",
        "type": "inject",
        "z": "4e44f1f8.f25318",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 2080,
        "y": 600,
        "wires": [
            [
                "544dcc8e.4abdb4"
            ]
        ]
    },
    {
        "id": "544dcc8e.4abdb4",
        "type": "change",
        "z": "4e44f1f8.f25318",
        "name": "myicon: home",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "true",
                "tot": "bool"
            },
            {
                "t": "set",
                "p": "myicon",
                "pt": "msg",
                "to": "home",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "tooltip",
                "pt": "msg",
                "to": "Ranki@Home",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 2260,
        "y": 600,
        "wires": [
            [
                "2f8a5b8b.3b3d84",
                "659d26a2.07bf08"
            ]
        ]
    },
    {
        "id": "f8e9468d.7d8b88",
        "type": "change",
        "z": "4e44f1f8.f25318",
        "name": "myicon: weekend",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "true",
                "tot": "bool"
            },
            {
                "t": "set",
                "p": "myicon",
                "pt": "msg",
                "to": "weekend",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "tooltip",
                "pt": "msg",
                "to": "Ranki@Base",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 2270,
        "y": 640,
        "wires": [
            [
                "2f8a5b8b.3b3d84",
                "659d26a2.07bf08"
            ]
        ]
    },
    {
        "id": "d91ccfae.ecd93",
        "type": "inject",
        "z": "4e44f1f8.f25318",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 2080,
        "y": 640,
        "wires": [
            [
                "f8e9468d.7d8b88"
            ]
        ]
    },
    {
        "id": "7d223aba.322464",
        "type": "change",
        "z": "4e44f1f8.f25318",
        "name": "myicon: public",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "true",
                "tot": "bool"
            },
            {
                "t": "set",
                "p": "myicon",
                "pt": "msg",
                "to": "public",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "tooltip",
                "pt": "msg",
                "to": "Ranki away",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 2260,
        "y": 680,
        "wires": [
            [
                "2f8a5b8b.3b3d84",
                "659d26a2.07bf08"
            ]
        ]
    },
    {
        "id": "43957dd0.142034",
        "type": "inject",
        "z": "4e44f1f8.f25318",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": true,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 2070,
        "y": 680,
        "wires": [
            [
                "7d223aba.322464"
            ]
        ]
    },
    {
        "id": "7e916ace.8d13a4",
        "type": "debug",
        "z": "4e44f1f8.f25318",
        "name": "home => weekend",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 3130,
        "y": 620,
        "wires": []
    },
    {
        "id": "659d26a2.07bf08",
        "type": "change",
        "z": "4e44f1f8.f25318",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "icon",
                "pt": "flow",
                "to": "myicon",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 2480,
        "y": 600,
        "wires": [
            []
        ]
    },
    {
        "id": "18f024a5.805b3b",
        "type": "switch",
        "z": "4e44f1f8.f25318",
        "name": "switch(myicon)",
        "property": "myicon",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "home",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "weekend",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "public",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 3,
        "x": 2900,
        "y": 660,
        "wires": [
            [
                "7e916ace.8d13a4",
                "f8e9468d.7d8b88"
            ],
            [
                "6dd47d3c.52b6c4",
                "7d223aba.322464"
            ],
            [
                "fcbe0b43.74aa08",
                "544dcc8e.4abdb4"
            ]
        ]
    },
    {
        "id": "6dd47d3c.52b6c4",
        "type": "debug",
        "z": "4e44f1f8.f25318",
        "name": "weekend => public",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 3130,
        "y": 660,
        "wires": []
    },
    {
        "id": "fcbe0b43.74aa08",
        "type": "debug",
        "z": "4e44f1f8.f25318",
        "name": "public => home",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 3120,
        "y": 700,
        "wires": []
    },
    {
        "id": "7247a753.fc5448",
        "type": "change",
        "z": "4e44f1f8.f25318",
        "name": "clean & update msg",
        "rules": [
            {
                "t": "delete",
                "p": "event",
                "pt": "msg"
            },
            {
                "t": "set",
                "p": "myicon",
                "pt": "msg",
                "to": "icon",
                "tot": "flow"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 2660,
        "y": 660,
        "wires": [
            [
                "18f024a5.805b3b",
                "b6d0eda9.5efea"
            ]
        ]
    },
    {
        "id": "b6d0eda9.5efea",
        "type": "debug",
        "z": "4e44f1f8.f25318",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 2830,
        "y": 700,
        "wires": []
    },
    {
        "id": "966d0c6c.5b7048",
        "type": "ui_group",
        "name": "Uhrzeit",
        "tab": "14d26b61.40ec4d",
        "order": 1,
        "disp": false,
        "width": "6",
        "collapse": false
    },
    {
        "id": "14d26b61.40ec4d",
        "type": "ui_tab",
        "name": "Smart Boot",
        "icon": "fa-anchor",
        "order": 1,
        "disabled": false,
        "hidden": false
    }
]

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