I ve a flow with much stuff inside but I think its better to post only parts of it (to much other stuff for switches inside):
[
{
"id": "dad2ad8d29b5f57a",
"type": "ui-led",
"z": "ba1f4b99a9e664d8",
"name": "Verbindung:",
"group": "15ecf48a1d47cdcb",
"order": 4,
"width": "2",
"height": "1",
"label": "Verbindung:",
"labelPlacement": "left",
"labelAlignment": "flex-start",
"states": [
{
"value": "false",
"valueType": "bool",
"color": "#ff0000"
},
{
"value": "true",
"valueType": "bool",
"color": "#00ff00"
}
],
"allowColorForValueInMessage": false,
"shape": "circle",
"showBorder": true,
"showGlow": true,
"x": 1270,
"y": 1380,
"wires": []
},
{
"id": "4921317e571d2772",
"type": "ui_led",
"z": "ba1f4b99a9e664d8",
"order": 9,
"group": "1631802e9c3c9572",
"width": "3",
"height": "1",
"label": "Verbindung:",
"labelPlacement": "left",
"labelAlignment": "left",
"colorForValue": [
{
"color": "#ff0000",
"value": "false",
"valueType": "bool"
},
{
"color": "#008000",
"value": "true",
"valueType": "bool"
}
],
"allowColorForValueInMessage": false,
"shape": "circle",
"showGlow": true,
"name": "isAwake",
"x": 1260,
"y": 1340,
"wires": []
},
{
"id": "81e3a6a72a2001b8",
"type": "debug",
"z": "ba1f4b99a9e664d8",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"x": 1250,
"y": 1300,
"wires": []
},
{
"id": "5b7425c7ea68d8c2",
"type": "function",
"z": "ba1f4b99a9e664d8",
"name": "awaikStatus",
"func": "msg.utsCurrent = parseInt(+new Date())||800;\nmsg.utsLastSensorMessage = flow.get(\"utsLastSensorMessage_t\")||500;\n\nmsg.lastSeenSecodsPassed = msg.utsCurrent - msg.utsLastSensorMessage;\nif (msg.lastSeenSecodsPassed > 60000)\n{\n msg.payload = false;\n return msg;\n}\nelse\n{\n msg.payload = true;\n return msg;\n}\n",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1070,
"y": 1340,
"wires": [
[
"4921317e571d2772",
"81e3a6a72a2001b8",
"dad2ad8d29b5f57a"
]
]
},
{
"id": "085f83cc440f8925",
"type": "inject",
"z": "ba1f4b99a9e664d8",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "30",
"crontab": "",
"once": true,
"onceDelay": "20",
"topic": "",
"payload": "",
"payloadType": "date",
"x": 1070,
"y": 1300,
"wires": [
[
"5b7425c7ea68d8c2"
]
]
},
{
"id": "919c269fc9fb07f7",
"type": "debug",
"z": "ba1f4b99a9e664d8",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"x": 970,
"y": 1260,
"wires": []
},
{
"id": "46b84c72ade60c76",
"type": "function",
"z": "ba1f4b99a9e664d8",
"name": "isSensorId",
"func": "let Id = flow.get('SensorId')||\"empty\";\n//let mqttBlocktime = flow.get(\"MttBlocktime\"); //|| (parseInt(+new Date()) + 2000);\nlet utsNow = parseInt(+new Date());\n\nif(msg.topic.match(Id) && msg.topic.match(\"RESULT\"))\n{\n if(IsJsonString(msg.payload)) \n {\n msg.payload = JSON.parse(msg.payload);\n if(msg.payload.hasOwnProperty(\"Button1\")) \n {\n if(msg.payload.Button1.hasOwnProperty(\"Action\"))\n {\n let RelayState = flow.get(\"relayStatus\");\n //if (mqttBlocktime > utsNow) return null;\n let pl = {};\n //pl.mqttBlocktime = mqttBlocktime;\n pl.utsNow = utsNow;\n pl.topic = msg.topic;\n pl.payload = {};\n pl.payload.Id = Id;\n if (msg.payload.Button1.Action === \"SINGLE\" && RelayState === false ) \n { pl.payload.Relay = \"On\"; }\n else if (msg.payload.Button1.Action === \"SINGLE\" && RelayState === true ) \n { pl.payload.Relay = \"Off\"; } \n else if (msg.payload.Button1.Action !== \"SINGLE\") \n { pl.payload.ButtonPresses = msg.payload.Button1.Action; } \n else\n { return [null, null]; }\n return [pl, null];\n }\n }\n if(msg.payload.hasOwnProperty(\"POWER\"))\n {\n // return null;\n //if (mqttBlocktime > utsNow) return null;\n let pl = {};\n //pl.mqttBlocktime = mqttBlocktime;\n pl.utsNow = utsNow;\n pl.topic = msg.topic;\n pl.payload = {};\n pl.cmdsource = \"SwitchWebInterface\";\n pl.payload.Id = Id;\n if (msg.payload.POWER === \"ON\") \n { pl.payload.Relay = \"On\"; }\n else if (msg.payload.POWER === \"OFF\") \n { pl.payload.Relay = \"Off\"; } \n else\n { return [null, null]; }\n return [pl, null];\n } \n }\n \n\n}\nelse if(msg.topic.match(Id) && msg.topic.match(\"SENSOR\"))\n{\n // Set Time for device online satus:\n flow.set(\"utsLastSensorMessage_t\", utsNow) || 5;\n\n if(IsJsonString(msg.payload)) msg.payload = JSON.parse(msg.payload);\n let power = parseInt(msg.payload.ENERGY.Power);\n if (power > 5000) power = 0;\n return [null, { \"payload\": power }];\n}\nelse\n{\n return [null, null];\n}\n\n\n// \"stat/SwitchTypT/84:F3:EB:31:CB:62/POWER\"\n\n\n\n\n// let Id = flow.get('SensorId')||\"empty\";\n// if (Id == \"empty\") return null;\n// if(IsJsonString(msg.payload)) msg.payload = parseJsonString(msg.payload);\n// if(msg.topic == \"stat/SwitchTypT/\" + Id + \"/STATUS10\")\n// {\n// return [msg, null, null, null];\n// }\n// else if(msg.topic == \"tele/SwitchTypT/\" + Id + \"/SENSOR\")\n// {\n// return [null, msg, null, null];\n// }\n// else if(msg.topic == \"cmnd/SwitchTypT/\" + Id + \"/POWER\")\n// {\n// return [null, null, msg, null];\n// }\n// else\n// {\n// return [null, null, null, msg];\n// }\n\n\n\n\n \n\n\nfunction IsJsonString(str) \n{\n try {\n JSON.parse(str);\n } catch (e) {\n return false;\n }\n return true;\n}\n\nfunction parseJsonString(str) \n{\n let parsedJson = JSON.parse(str);\n return parsedJson; \n}",
"outputs": 2,
"timeout": "",
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 770,
"y": 1260,
"wires": [
[
"feec226e3c412516",
"a7f28cbac63f0146",
"9059d6412b20f34d"
],
[
"0b54fbaac9ee3493",
"919c269fc9fb07f7",
"5b7425c7ea68d8c2"
]
]
},
{
"id": "efe545702374712c",
"type": "mqtt in",
"z": "ba1f4b99a9e664d8",
"d": true,
"name": "",
"topic": "tele/#",
"qos": "0",
"datatype": "auto",
"broker": "f55c6c0d.194bb",
"nl": false,
"rap": false,
"inputs": 0,
"x": 610,
"y": 1200,
"wires": [
[
"46b84c72ade60c76",
"ca9876cd3c7a3d2b"
]
]
},
{
"id": "b98ff48da1322938",
"type": "mqtt in",
"z": "ba1f4b99a9e664d8",
"d": true,
"name": "",
"topic": "stat/#",
"qos": "0",
"datatype": "auto",
"broker": "f55c6c0d.194bb",
"nl": false,
"rap": false,
"inputs": 0,
"x": 610,
"y": 1320,
"wires": [
[
"41aae98349883907",
"46b84c72ade60c76"
]
]
},
{
"id": "a7f28cbac63f0146",
"type": "function",
"z": "ba1f4b99a9e664d8",
"name": "setTriggerPriority",
"func": "let flowX = flow.get('SensorId')||\"empty\";\nif (flowX == \"empty\") return null;\nlet keyX = \"PriorityMqtt\";\nlet conf = global.get('globalConfig');\nlet prio = conf[flowX][keyX];\nmsg.priority = prio;\nif (msg.cmdsource === \"SwitchWebInterface\") msg.priority = flow.get('priorityStatus')||99;\n//msg.cmdsource = \"PriorityMqtt\";\nreturn msg;\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1010,
"y": 1200,
"wires": [
[
"ea8601088eff9004"
]
]
},
{
"id": "feec226e3c412516",
"type": "debug",
"z": "ba1f4b99a9e664d8",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"x": 970,
"y": 1160,
"wires": []
},
{
"id": "ea8601088eff9004",
"type": "function",
"z": "ba1f4b99a9e664d8",
"name": "setLightSwitch",
"func": "let priorityStatus = flow.get('priorityStatus')||99;\nif(msg.priority > priorityStatus) return null;\nif (msg.payload.Relay == \"Off\" || msg.payload === false)\n{\n //let tmp = msg.payload;\n\n let newPayload = {};\n newPayload.Id = flow.get('SensorId')||\"empty\";\n newPayload.Relay = \"Off\";\n msg.payload = newPayload;\n \n let newPayload2 = {};\n let state = false;\n newPayload2.payload = state;\n flow.set(\"relayStatus\", state);\n flow.set(\"priorityStatus\", 99);\n flow.set(\"utsRelayOffWebInterface_t\",0);\n flow.set(\"utsRelayOff_t\", 0); \n\n //if (tmp.sender == \"restore\")\n //{\n // return [msg, newPayload2, null];\n //}\n //else\n //{\n // return [msg, newPayload2, msg];\n //}\n return [msg, newPayload2, msg];\n}\nif (msg.payload.Relay == \"On\" || msg.payload === true)\n{\n //let tmp = msg.payload;\n \n let newPayload = {};\n newPayload.Id = flow.get('SensorId')||\"empty\";\n newPayload.Relay = \"On\";\n msg.payload = newPayload;\n \n let newPayload2 = {};\n let state = true;\n newPayload2.payload = state;\n flow.set(\"relayStatus\", state);\n flow.set(\"priorityStatus\", msg.priority);\n //if (tmp.sender == \"restore\")\n //{\n // return [msg, newPayload2, null];\n //}\n //else\n //{\n // return [msg, newPayload2, msg];\n //}\n return [msg, newPayload2, msg];\n}\nreturn null;",
"outputs": 3,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1320,
"y": 1040,
"wires": [
[
"05410bac050504df",
"eaeb554273b561e7",
"5b09bb12a8c448eb",
"e3dcf3aea11eec8e"
],
[
"dd1ebbdaf9dff194",
"5fae6cd639cbc41f",
"f7cfa8c00adbd4be"
],
[
"6eaf7e2f4b604fe1",
"6f869bcc27dfe84a",
"c30a2b6f87d488d5",
"eba723867387436d",
"5605363013419970"
]
]
},
{
"id": "a44c05b240f1861a",
"type": "function",
"z": "ba1f4b99a9e664d8",
"name": "setTriggerPriority",
"func": "// let flowX = flow.get('SensorId')||\"empty\";\n// if (flowX == \"empty\") return null;\n// let keyX = \"PrioritySwitchWebinterface\";\n// let conf = global.get('globalConfig');\n// let prio = conf[flowX][keyX];\n// msg.priority = prio;\n// flow.set(\"utsRelayOff_t\", 0);\n// return msg;\n\nlet flowX = flow.get('SensorId')||\"empty\";\nif (flowX == \"empty\") return null;\nlet keyX = \"PrioritySwitchWebinterface\";\nlet conf = global.get('globalConfig');\nlet prio = conf[flowX][keyX];\nmsg.priority = prio;\nlet switchOnTimeValue = (flow.get('switchOnTimeValue')|0)*1000;\nmsg.cmdsource = \"webinterface\";\nutsCurrent = parseInt(+new Date());\nflow.set(\"utsRelayOffWebInterface_t\", (utsCurrent + switchOnTimeValue));\nreturn msg;\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1330,
"y": 1120,
"wires": [
[
"ea8601088eff9004",
"0574049117730538"
]
]
},
{
"id": "5fae6cd639cbc41f",
"type": "ui_switch",
"z": "ba1f4b99a9e664d8",
"name": "Schreibtisch",
"label": "",
"tooltip": "",
"group": "1631802e9c3c9572",
"order": 2,
"width": "3",
"height": "1",
"passthru": false,
"decouple": "true",
"topic": "",
"topicType": "str",
"style": "",
"onvalue": "true",
"onvalueType": "bool",
"onicon": "",
"oncolor": "",
"offvalue": "false",
"offvalueType": "bool",
"officon": "",
"offcolor": "",
"animate": true,
"className": "",
"x": 1270,
"y": 1180,
"wires": [
[
"a44c05b240f1861a"
]
]
},
{
"id": "f7cfa8c00adbd4be",
"type": "ui-switch",
"z": "ba1f4b99a9e664d8",
"name": "Schreibtisch",
"label": "Schreibtisch",
"group": "15ecf48a1d47cdcb",
"order": 1,
"width": "2",
"height": "1",
"passthru": false,
"decouple": false,
"topic": "",
"topicType": "str",
"style": "",
"className": "",
"layout": "",
"clickableArea": "switch",
"onvalue": "true",
"onvalueType": "bool",
"onicon": "",
"oncolor": "",
"offvalue": "false",
"offvalueType": "bool",
"officon": "",
"offcolor": "",
"x": 1270,
"y": 1240,
"wires": [
[
"a44c05b240f1861a"
]
]
},
{
"id": "e3dcf3aea11eec8e",
"type": "function",
"z": "ba1f4b99a9e664d8",
"name": "convertToTasmota",
"func": "let Id = flow.get('SensorId')||\"empty\";\nif (Id == \"empty\") return null;\nif (msg.cmdsource == \"SwitchWebInterface\") return null;\nmsg.topic = \"cmnd/SwitchTypT/\" + Id + \"/POWER\";\nmsg.payload = msg.payload.Relay;\n//flow.set(\"MttBlocktime\", ((parseInt(+new Date())) + 200));\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1630,
"y": 940,
"wires": [
[
"e82da21963e2a55c",
"a0253998b386edf5",
"8f9d6a30ac1f994d"
]
]
},
{
"id": "e82da21963e2a55c",
"type": "mqtt out",
"z": "ba1f4b99a9e664d8",
"d": true,
"name": "mqtt",
"topic": "",
"qos": "0",
"retain": "false",
"respTopic": "",
"contentType": "",
"userProps": "",
"correl": "",
"expiry": "",
"broker": "f55c6c0d.194bb",
"x": 1830,
"y": 940,
"wires": []
},
{
"id": "a0253998b386edf5",
"type": "debug",
"z": "ba1f4b99a9e664d8",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"x": 1830,
"y": 900,
"wires": []
},
{
"id": "402fc590e681f98e",
"type": "inject",
"z": "ba1f4b99a9e664d8",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": true,
"onceDelay": "1",
"topic": "ExecuteOnStart",
"payloadType": "str",
"x": 1610,
"y": 220,
"wires": [
[
"e362b529b3647512",
"995279a336276078"
]
]
},
{
"id": "e362b529b3647512",
"type": "function",
"z": "ba1f4b99a9e664d8",
"name": "setSensorId 2C:F4:32:78:26:1C",
"func": "// Edit here:\nflow.set('SensorId',\"2C:F4:32:78:26:1C\");\nflow.set('isDelayLoopRunning', false);\nflow.set('isDelayLoopWebinterfaceRunning', false);\nreturn null;",
"outputs": 1,
"timeout": "",
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1650,
"y": 260,
"wires": [
[]
]
},
{
"id": "995279a336276078",
"type": "debug",
"z": "ba1f4b99a9e664d8",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"x": 1810,
"y": 220,
"wires": []
},
{
"id": "15ecf48a1d47cdcb",
"type": "ui-group",
"name": "Schreibtisch - Steckdose",
"page": "3f733656bce2c526",
"width": "2",
"height": "1",
"order": 2,
"showTitle": true,
"className": "",
"visible": "true",
"disabled": "false",
"groupType": "default"
},
{
"id": "1631802e9c3c9572",
"type": "ui_group",
"name": "Schreibtisch - Steckdose",
"tab": "6106a649e7ac3347",
"order": 12,
"disp": true,
"width": "6",
"collapse": true,
"className": ""
},
{
"id": "f55c6c0d.194bb",
"type": "mqtt-broker",
"name": "",
"broker": "mosquitto",
"port": "1883",
"clientid": "",
"autoConnect": true,
"usetls": false,
"protocolVersion": "3",
"keepalive": "60",
"cleansession": true,
"autoUnsubscribe": true,
"birthTopic": "",
"birthQos": "0",
"birthPayload": "",
"birthMsg": {},
"closeTopic": "",
"closeQos": "0",
"closePayload": "",
"closeMsg": {},
"willTopic": "Abbruch",
"willQos": "0",
"willRetain": "true",
"willPayload": "{\"Abbruch\":\"Abbruch\"}",
"willMsg": {},
"userProps": "",
"sessionExpiry": ""
},
{
"id": "3f733656bce2c526",
"type": "ui-page",
"name": "Schalter - Sonstige",
"ui": "282ba4e5c6170cd2",
"path": "/SchalterSonstige",
"icon": "home",
"layout": "flex",
"theme": "97db8f45911448c5",
"breakpoints": [
{
"name": "Default",
"px": "0",
"cols": "3"
},
{
"name": "Tablet",
"px": "576",
"cols": "6"
},
{
"name": "Small Desktop",
"px": "768",
"cols": "9"
},
{
"name": "Desktop",
"px": "1024",
"cols": "12"
}
],
"order": 20,
"className": "",
"visible": "true",
"disabled": "false"
},
{
"id": "6106a649e7ac3347",
"type": "ui_tab",
"name": "Schalter - Sonstige",
"icon": "wb_incandescent",
"order": 2,
"disabled": false,
"hidden": false
},
{
"id": "282ba4e5c6170cd2",
"type": "ui-base",
"name": "Dashboard 2.0",
"path": "/dashboard",
"includeClientData": true,
"acceptsClientConfig": [
"ui-notification",
"ui-control"
],
"showPathInSidebar": false,
"showPageTitle": true,
"navigationStyle": "default",
"titleBarStyle": "default"
},
{
"id": "97db8f45911448c5",
"type": "ui-theme",
"name": "Default Theme",
"colors": {
"surface": "#ffffff",
"primary": "#0094CE",
"bgPage": "#eeeeee",
"groupBg": "#ffffff",
"groupOutline": "#cccccc"
},
"sizes": {
"pagePadding": "12px",
"groupGap": "12px",
"groupBorderRadius": "4px",
"widgetGap": "12px"
}
}
]
It works fine the code is somehow .... let s say "grown"
you need to enable the mqtt node.
you need to setup tasmota config like this or change mqtt in flow to make it work: