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
}
]