Files
nspanel-lovelace-ui/node-red-example-flow.json
2022-02-08 23:54:44 +01:00

661 lines
24 KiB
JSON

[
{
"id": "ba6c8bb20b9aa4cc",
"type": "tab",
"label": "NSP_Kueche",
"disabled": false,
"info": "",
"env": []
},
{
"id": "df42e19d07582858",
"type": "mqtt in",
"z": "ba6c8bb20b9aa4cc",
"name": "",
"topic": "tele/tasmota_nspkueche/RESULT",
"qos": "2",
"datatype": "auto",
"broker": "aeedd16f1f009dd0",
"nl": false,
"rap": true,
"rh": 0,
"inputs": 0,
"x": 190,
"y": 80,
"wires": [
[
"a44b586b7fd6c26d"
]
]
},
{
"id": "f1c977fd5eacc769",
"type": "debug",
"z": "ba6c8bb20b9aa4cc",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 990,
"y": 80,
"wires": []
},
{
"id": "a44b586b7fd6c26d",
"type": "function",
"z": "ba6c8bb20b9aa4cc",
"name": "check for CustomRecv",
"func": "if(msg.payload.startsWith('\\{\"CustomRecv\":')){\n obj = JSON.parse(msg.payload)\n msg.payload = obj.CustomRecv\n return msg;\n}",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 460,
"y": 80,
"wires": [
[
"f1c977fd5eacc769",
"86dcef64cf01cad1"
]
]
},
{
"id": "86dcef64cf01cad1",
"type": "function",
"z": "ba6c8bb20b9aa4cc",
"name": "pages",
"func": "var pages = flow.get(\"ns-config\")\n\nfunction genEntitiesPage(pageNum){\n var out_msgs = [ {payload:\"pageType,cardEntities\"}, { payload: \"entityUpdHeading,\"+pages[pageNum].heading } ]\n\n pages[pageNum].items.forEach(function (id, i) {\n \n var type = \"delete\"\n var iconId = 0\n var name = global.get(\"homeassistant.homeAssistant.states['\"+id+\"'].attributes.friendly_name\")\n \n switch (id.substring(0,id.indexOf('.'))) {\n case \"cover\":\n type = \"shutter\"\n iconId = 0\n out_msgs.push({ payload: \"entityUpd,\"+(i+1)+\",\"+iconId+\",\"+name+\",\"+type})\n break\n case \"light\":\n type = \"light\"\n iconId = 1\n var optVal = \"0\"\n if(global.get(\"homeassistant.homeAssistant.states['\"+id+\"'].state\") == \"on\")\n optVal = \"1\"\n out_msgs.push({ payload: \"entityUpd,\"+(i+1)+\",\"+iconId+\",\"+name+\",\"+type+\",\"+optVal})\n break\n case \"sensor\":\n type = \"text\"\n if(global.get(\"homeassistant.homeAssistant.states['\"+id+\"'].attributes.device_class\") == \"temperature\"){\n iconId = 2\n }\n var optVal = global.get(\"homeassistant.homeAssistant.states['\"+id+\"'].state\") + \" \" + global.get(\"homeassistant.homeAssistant.states['\"+id+\"'].attributes.unit_of_measurement\")\n out_msgs.push({ payload: \"entityUpd,\"+(i+1)+\",\"+iconId+\",\"+name+\",\"+type+\",\"+optVal})\n break\n case \"button\":\n type = \"button\"\n iconId = 3\n var optVal = \"PRESS\"\n out_msgs.push({ payload: \"entityUpd,\"+(i+1)+\",\"+iconId+\",\"+name+\",\"+type+\",\"+optVal})\n break\n case \"delete\":\n type = \"delete\"\n out_msgs.push({ payload: \"entityUpd,\"+(i+1)+\",0,dc,\"+type})\n break\n default:\n break\n }\n\n })\n\n\n \n return out_msgs\n \n}\n\nfunction genThermoPage(pageNum){\n id = pages[pageNum].item\n var out_msgs = [ {payload:\"pageType,cardThermo\"} ]\n \n let heading = global.get(\"homeassistant.homeAssistant.states['\"+id+\"'].attributes.friendly_name\")\n let currentTemp = global.get(\"homeassistant.homeAssistant.states['\"+id+\"'].attributes.current_temperature\")*10\n let destTemp = global.get(\"homeassistant.homeAssistant.states['\"+id+\"'].attributes.temperature\")*10\n let status = global.get(\"homeassistant.homeAssistant.states['\"+id+\"'].attributes.hvac_action\")\n let minTemp = global.get(\"homeassistant.homeAssistant.states['\"+id+\"'].attributes.min_temp\")*10\n let maxTemp = global.get(\"homeassistant.homeAssistant.states['\"+id+\"'].attributes.max_temp\")*10\n //let stepTemp = global.get(\"homeassistant.homeAssistant.states['\"+id+\"'].attributes.target_temp_step\")*10\n let stepTemp = 0.5*10\n \n out_msgs.push({ payload: \"entityUpd,\"+heading+\",\"+currentTemp+\",\"+destTemp+\",\"+status+\",\"+minTemp+\",\"+maxTemp+\",\"+stepTemp })\n \n \n return out_msgs\n}\n\n\nfunction handleButtonEvent(pageNum, words){\n var out_msgs = [ ]\n pages[pageNum].items.forEach(function (id, i) {\n var name = global.get(\"homeassistant.homeAssistant.states['\"+id+\"'].attributes.friendly_name\")\n if(words[4]==name){\n if(words[6]==\"OnOff\"){\n var domain = \"switch\"\n if(id.startsWith(\"light\"))\n domain = \"light\"\n var action = \"turn_off\"\n if(words[7]==\"1\")\n action = \"turn_on\"\n out_msgs.push( {payload: id, action: action, domain: domain})\n }\n \n if(words[6]==\"up\")\n out_msgs.push( {payload: id, action: \"open_cover\", domain: \"cover\"})\n if(words[6]==\"stop\")\n out_msgs.push( {payload: id, action: \"stop_cover\", domain: \"cover\"})\n if(words[6]==\"down\")\n out_msgs.push( {payload: id, action: \"close_cover\", domain: \"cover\"})\n \n if(words[6]==\"brightnessSlider\")\n out_msgs.push( {payload: id, action: \"turn_on\", domain: \"lightBrightness\", brightness: parseInt(words[7])})\n if(words[6]==\"colorTempSlider\")\n out_msgs.push( {payload: id, action: \"turn_on\", domain: \"lightTemperature\", temperature: parseInt(words[7])})\n \n }\n }\n \n )\n return out_msgs\n}\n\nfunction searchIdInPages(friendlyName){\n let id_ret = \"\"\n // search entity in pages\n pages.forEach(page => {\n if(\"items\" in page){\n page.items.forEach(function (id, i) {\n var name = global.get(\"homeassistant.homeAssistant.states['\"+id+\"'].attributes.friendly_name\")\n if(name == friendlyName){\n id_ret = id\n }\n })\n }\n })\n return id_ret\n}\n\nfunction scale(number, inMin, inMax, outMin, outMax) {\n return (number - inMin) * (outMax - outMin) / (inMax - inMin) + outMin;\n}\n\nfunction genDetailPage(type, friendlyName){\n var out_msgs = [ ]\n \n let id = searchIdInPages(friendlyName)\n if(type == \"popupLight\"){\n let switchVal = \"0\"\n if(global.get(\"homeassistant.homeAssistant.states['\"+id+\"'].state\") == \"on\")\n switchVal = \"1\"\n \n let attr = global.get(\"homeassistant.homeAssistant.states['\"+id+\"'].attributes\")\n \n let brightness = Math.trunc(scale(attr.brightness, 0, 255, 0, 100))\n \n let colortemp = Math.trunc(scale(attr.color_temp, attr.min_mireds, attr.max_mireds, 0, 100))\n \n out_msgs.push({ payload: \"entityUpdateDetail,\"+switchVal+\",\"+brightness+\",\"+colortemp})\n }\n\n\n \n return out_msgs\n \n}\n\n\nwords = msg.payload.split(',')\nif(words[0]=='event'){\n var pageNum = parseInt(words[2])\n pageNum = (pageNum % pages.length)\n pageNum = Math.abs(pageNum)\n flow.set(\"ns-currentPage\", pageNum)\n \n if(words[1]=='pageOpen'){\n var retMsgs = []\n \n if(pages[pageNum].type == \"cardEntities\"){\n retMsgs = genEntitiesPage(pageNum)\n }else if(pages[pageNum].type == \"cardThermo\")\n {\n retMsgs = genThermoPage(pageNum)\n }\n \n return [retMsgs, null]\n }\n if(words[1]=='buttonPress'){\n return [null, handleButtonEvent(pageNum, words)]\n }\n if(words[1]=='pageOpenDetail'){\n return [genDetailPage(words[2], words[3]), null]\n }\n \n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n",
"outputs": 2,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 770,
"y": 120,
"wires": [
[
"f1c977fd5eacc769",
"1c40e3fbed77566a"
],
[
"bea462f25c2d6594",
"bb5a45a85294d141"
]
]
},
{
"id": "23673f9ed21f9314",
"type": "server-state-changed",
"z": "ba6c8bb20b9aa4cc",
"name": "",
"server": "7b975ed1.2c58d",
"version": 3,
"exposeToHomeAssistant": false,
"haConfig": [
{
"property": "name",
"value": ""
},
{
"property": "icon",
"value": ""
}
],
"entityidfilter": "light.kueche_lights",
"entityidfiltertype": "exact",
"outputinitially": false,
"state_type": "str",
"haltifstate": "",
"halt_if_type": "str",
"halt_if_compare": "is",
"outputs": 1,
"output_only_on_state_change": true,
"for": 0,
"forType": "num",
"forUnits": "minutes",
"ignorePrevStateNull": false,
"ignorePrevStateUnknown": false,
"ignorePrevStateUnavailable": false,
"ignoreCurrentStateUnknown": false,
"ignoreCurrentStateUnavailable": false,
"outputProperties": [
{
"property": "payload",
"propertyType": "msg",
"value": "",
"valueType": "entityState"
},
{
"property": "data",
"propertyType": "msg",
"value": "",
"valueType": "eventData"
},
{
"property": "topic",
"propertyType": "msg",
"value": "",
"valueType": "triggerId"
}
],
"x": 200,
"y": 300,
"wires": [
[
"056cb9e82f6134a5"
]
]
},
{
"id": "bea462f25c2d6594",
"type": "debug",
"z": "ba6c8bb20b9aa4cc",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 990,
"y": 200,
"wires": []
},
{
"id": "d89d65da2c861934",
"type": "api-call-service",
"z": "ba6c8bb20b9aa4cc",
"name": "",
"server": "7b975ed1.2c58d",
"version": 3,
"debugenabled": false,
"service_domain": "light",
"service": "{{action}}",
"entityId": "{{payload}}",
"data": "",
"dataType": "jsonata",
"mergecontext": "",
"mustacheAltTags": false,
"outputProperties": [],
"queue": "none",
"x": 1210,
"y": 200,
"wires": [
[]
]
},
{
"id": "bb5a45a85294d141",
"type": "switch",
"z": "ba6c8bb20b9aa4cc",
"name": "",
"property": "domain",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "light",
"vt": "str"
},
{
"t": "eq",
"v": "lightBrightness",
"vt": "str"
},
{
"t": "eq",
"v": "lightTemperature",
"vt": "str"
},
{
"t": "eq",
"v": "switch",
"vt": "str"
},
{
"t": "eq",
"v": "cover",
"vt": "str"
}
],
"checkall": "true",
"repair": false,
"outputs": 5,
"x": 990,
"y": 260,
"wires": [
[
"d89d65da2c861934"
],
[
"1ddde5e25ac783b8"
],
[
"1207b113e1e44be4"
],
[
"f494954196883dd7"
],
[
"0cea8c43c493c215"
]
]
},
{
"id": "f494954196883dd7",
"type": "api-call-service",
"z": "ba6c8bb20b9aa4cc",
"name": "",
"server": "7b975ed1.2c58d",
"version": 3,
"debugenabled": false,
"service_domain": "switch",
"service": "{{action}}",
"entityId": "{{payload}}",
"data": "",
"dataType": "jsonata",
"mergecontext": "",
"mustacheAltTags": false,
"outputProperties": [],
"queue": "none",
"x": 1220,
"y": 360,
"wires": [
[]
]
},
{
"id": "0cea8c43c493c215",
"type": "api-call-service",
"z": "ba6c8bb20b9aa4cc",
"name": "",
"server": "7b975ed1.2c58d",
"version": 3,
"debugenabled": false,
"service_domain": "cover",
"service": "{{action}}",
"entityId": "{{payload}}",
"data": "",
"dataType": "jsonata",
"mergecontext": "",
"mustacheAltTags": false,
"outputProperties": [],
"queue": "none",
"x": 1210,
"y": 420,
"wires": [
[]
]
},
{
"id": "1ddde5e25ac783b8",
"type": "api-call-service",
"z": "ba6c8bb20b9aa4cc",
"name": "lightBrightness",
"server": "7b975ed1.2c58d",
"version": 3,
"debugenabled": false,
"service_domain": "light",
"service": "turn_on",
"entityId": "{{payload}}",
"data": "{\"brightness_pct\":{{brightness}}}",
"dataType": "json",
"mergecontext": "",
"mustacheAltTags": false,
"outputProperties": [],
"queue": "none",
"x": 1200,
"y": 240,
"wires": [
[]
]
},
{
"id": "1207b113e1e44be4",
"type": "function",
"z": "ba6c8bb20b9aa4cc",
"name": "calcMireds",
"func": "function scale(number, inMin, inMax, outMin, outMax) {\n return (number - inMin) * (outMax - outMin) / (inMax - inMin) + outMin;\n}\n\nvar id = msg.payload\nvar attr = global.get(\"homeassistant.homeAssistant.states['\"+id+\"'].attributes\")\n\nvar mireds = scale(msg.temperature, 0, 100, attr.min_mireds, attr.max_mireds)\n\nmsg.temperature = mireds\nreturn msg\n\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1190,
"y": 300,
"wires": [
[
"8f0f6a771251ef17"
]
]
},
{
"id": "8f0f6a771251ef17",
"type": "api-call-service",
"z": "ba6c8bb20b9aa4cc",
"name": "lightTemperature",
"server": "7b975ed1.2c58d",
"version": 3,
"debugenabled": false,
"service_domain": "light",
"service": "turn_on",
"entityId": "{{payload}}",
"data": "{\"color_temp\":{{temperature}}}",
"dataType": "json",
"mergecontext": "",
"mustacheAltTags": false,
"outputProperties": [],
"queue": "none",
"x": 1370,
"y": 300,
"wires": [
[]
]
},
{
"id": "b968e02c88f3500d",
"type": "function",
"z": "ba6c8bb20b9aa4cc",
"name": "pages",
"func": "msg.payload = global.get(\"homeassistant.homeAssistant.states['sensor.kleiderschrank1_si7021_temperature']\")\nreturn msg",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 790,
"y": 580,
"wires": [
[
"b51a0f5849d2a1a0"
]
]
},
{
"id": "1f1d39ecab559597",
"type": "inject",
"z": "ba6c8bb20b9aa4cc",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 640,
"y": 580,
"wires": [
[
"b968e02c88f3500d"
]
]
},
{
"id": "b51a0f5849d2a1a0",
"type": "debug",
"z": "ba6c8bb20b9aa4cc",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 950,
"y": 580,
"wires": []
},
{
"id": "1c40e3fbed77566a",
"type": "mqtt out",
"z": "ba6c8bb20b9aa4cc",
"name": "",
"topic": "cmnd/tasmota_nspkueche/CustomSend",
"qos": "",
"retain": "",
"respTopic": "",
"contentType": "",
"userProps": "",
"correl": "",
"expiry": "",
"broker": "aeedd16f1f009dd0",
"x": 1080,
"y": 120,
"wires": []
},
{
"id": "06345c11ce5d62fe",
"type": "function",
"z": "ba6c8bb20b9aa4cc",
"name": "config",
"func": "//see start tab",
"outputs": 1,
"noerr": 0,
"initialize": "if (flow.get(\"ns-config\") === undefined) {\n \n var pages = \n [\n {\n type: \"cardEntities\",\n heading: \"TestPage\",\n items: [\"light.kueche_lights\", \"sensor.nsp_kueche_analog_temperature1\", \"delete\", \"delete\"] \n },\n {\n type: \"cardThermo\",\n item: \"climate.kuche_boden\"\n }\n ]\n\n\n flow.set(\"ns-config\", pages)\n}",
"finalize": "",
"libs": [],
"x": 1390,
"y": 60,
"wires": [
[]
]
},
{
"id": "cac2f4129b2e5a4f",
"type": "inject",
"z": "ba6c8bb20b9aa4cc",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "event,pageOpen,0",
"payloadType": "str",
"x": 430,
"y": 360,
"wires": [
[
"86dcef64cf01cad1"
]
]
},
{
"id": "056cb9e82f6134a5",
"type": "function",
"z": "ba6c8bb20b9aa4cc",
"name": "externalUpdates",
"func": "let currentPageNr = flow.get(\"ns-currentPage\")\n\nlet currentPageConfig = flow.get(\"ns-config\")[currentPageNr]\n\nif(\"items\" in currentPageConfig){\n if(msg.topic in currentPageConfig.items){\n \n }\n}\n\n",
"outputs": 1,
"noerr": 0,
"initialize": "if (flow.get(\"ns-currentPage\") === undefined) {\n flow.set(\"ns-currentPage\", 0)\n}",
"finalize": "",
"libs": [],
"x": 460,
"y": 300,
"wires": [
[]
]
},
{
"id": "946aaade2d1f150a",
"type": "server-state-changed",
"z": "ba6c8bb20b9aa4cc",
"name": "",
"server": "7b975ed1.2c58d",
"version": 3,
"exposeToHomeAssistant": false,
"haConfig": [
{
"property": "name",
"value": ""
},
{
"property": "icon",
"value": ""
}
],
"entityidfilter": "light.kueche_lights",
"entityidfiltertype": "exact",
"outputinitially": false,
"state_type": "str",
"haltifstate": "on",
"halt_if_type": "str",
"halt_if_compare": "is",
"outputs": 2,
"output_only_on_state_change": true,
"for": 0,
"forType": "num",
"forUnits": "minutes",
"ignorePrevStateNull": false,
"ignorePrevStateUnknown": false,
"ignorePrevStateUnavailable": false,
"ignoreCurrentStateUnknown": false,
"ignoreCurrentStateUnavailable": false,
"outputProperties": [
{
"property": "payload",
"propertyType": "msg",
"value": "",
"valueType": "entityState"
},
{
"property": "data",
"propertyType": "msg",
"value": "",
"valueType": "eventData"
},
{
"property": "topic",
"propertyType": "msg",
"value": "",
"valueType": "triggerId"
}
],
"x": 760,
"y": 440,
"wires": [
[
"962b6a55abf0113e"
],
[]
]
},
{
"id": "962b6a55abf0113e",
"type": "function",
"z": "ba6c8bb20b9aa4cc",
"name": "wake&display",
"func": "var out_msgs = \n[ {payload:\"wake\"}, \n {payload: \"pageType,popupLight,Kueche\"} \n]\n\n\n\nreturn [out_msgs]",
"outputs": 1,
"noerr": 0,
"initialize": "if (flow.get(\"ns-currentPage\") === undefined) {\n flow.set(\"ns-currentPage\", 0)\n}",
"finalize": "",
"libs": [],
"x": 800,
"y": 380,
"wires": [
[
"1c40e3fbed77566a",
"f1c977fd5eacc769"
]
]
},
{
"id": "f3a47d87b237c392",
"type": "inject",
"z": "ba6c8bb20b9aa4cc",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "pageType,popupLight,Kueche",
"payloadType": "str",
"x": 730,
"y": 340,
"wires": [
[
"1c40e3fbed77566a"
]
]
},
{
"id": "aeedd16f1f009dd0",
"type": "mqtt-broker",
"name": "",
"broker": "192.168.75.30",
"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": "7b975ed1.2c58d",
"type": "server",
"name": "HomeAssistant",
"version": 2,
"addon": true,
"rejectUnauthorizedCerts": true,
"ha_boolean": "y|yes|true|on|home|open",
"connectionDelay": true,
"cacheJson": true,
"heartbeat": false,
"heartbeatInterval": "30"
}
]