[ { "id": "1095d804ba7660cf", "type": "tab", "label": "nspanel", "disabled": false, "info": "", "env": [] }, { "id": "ce92ba2dd30d18b5", "type": "mqtt in", "z": "1095d804ba7660cf", "name": "", "topic": "tele/tasmota_NsPanelTerrasse/RESULT", "qos": "2", "datatype": "utf8", "broker": "aeedd16f1f009dd0", "nl": false, "rap": true, "rh": 0, "inputs": 0, "x": 190, "y": 120, "wires": [ [ "e91144d67ea326b2" ] ] }, { "id": "90dd992b9c45dace", "type": "debug", "z": "1095d804ba7660cf", "name": "", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "payload", "targetType": "msg", "statusVal": "", "statusType": "auto", "x": 990, "y": 120, "wires": [] }, { "id": "e91144d67ea326b2", "type": "function", "z": "1095d804ba7660cf", "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": 120, "wires": [ [ "90dd992b9c45dace", "e0a3b3c8887ff55f" ] ] }, { "id": "e0a3b3c8887ff55f", "type": "function", "z": "1095d804ba7660cf", "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)+\",\"+type+\",\"+id+\",\"+iconId+\",\"+name})\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)+\",\"+type+\",\"+id+\",\"+iconId+\",\"+name+\",\"+optVal})\n break\n case \"switch\":\n type = \"switch\"\n iconId = 4\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)+\",\"+type+\",\"+id+\",\"+iconId+\",\"+name+\",\"+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)+\",\"+type+\",\"+id+\",\"+iconId+\",\"+name+\",\"+optVal})\n break\n case \"button\":\n type = \"button\"\n iconId = 3\n var optVal = \"PRESS\"\n out_msgs.push({ payload: \"entityUpd,\"+(i+1)+\",\"+type+\",\"+id+\",\"+iconId+\",\"+name+\",\"+optVal})\n break\n case \"delete\":\n type = \"delete\"\n out_msgs.push({ payload: \"entityUpd,\"+(i+1)+\",\"+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,\"+id+\",\"+heading+\",\"+currentTemp+\",\"+destTemp+\",\"+status+\",\"+minTemp+\",\"+maxTemp+\",\"+stepTemp })\n \n \n return out_msgs\n}\n\n\nfunction handleButtonEvent(words){\n var out_msgs = [ ]\n let id = words[4]\n\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 return out_msgs\n}\n\nfunction scale(number, inMin, inMax, outMin, outMax) {\n return (number - inMin) * (outMax - outMin) / (inMax - inMin) + outMin;\n}\n\nfunction genDetailPage(type, entityId){\n var out_msgs = [ ]\n \n let id = entityId\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 = \"disable\"\n let attr_support_color = attr.supported_color_modes\n if (attr_support_color.includes(\"color_temp\"))\n 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 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 \n if(words[1]=='pageOpen' || words[1]=='startup' ){\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(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": 160, "wires": [ [ "90dd992b9c45dace", "a9571b3ad08027d6" ], [ "d365471c93b90620", "3bc7b6a09e86cf1f" ] ] }, { "id": "cb442d0ff23ccd50", "type": "server-state-changed", "z": "1095d804ba7660cf", "name": "", "server": "7b975ed1.2c58d", "version": 4, "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": 340, "wires": [ [ "a267036facc87a9c" ] ] }, { "id": "d365471c93b90620", "type": "debug", "z": "1095d804ba7660cf", "name": "", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "true", "targetType": "full", "statusVal": "", "statusType": "auto", "x": 990, "y": 240, "wires": [] }, { "id": "76f2b49f12c59fd2", "type": "api-call-service", "z": "1095d804ba7660cf", "name": "", "server": "7b975ed1.2c58d", "version": 4, "debugenabled": false, "domain": "light", "service": "{{action}}", "target": { "entityId": [ "{{payload}}" ], "areaId": [], "deviceId": [] }, "data": "", "dataType": "jsonata", "mergeContext": "", "mustacheAltTags": false, "outputProperties": [], "queue": "none", "x": 1210, "y": 240, "wires": [ [] ] }, { "id": "3bc7b6a09e86cf1f", "type": "switch", "z": "1095d804ba7660cf", "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": 300, "wires": [ [ "76f2b49f12c59fd2" ], [ "439c4edaa91cfd46" ], [ "8b9fd15277f38896" ], [ "d67a45b07be3f0e2" ], [ "948f928f2606a5c7" ] ] }, { "id": "d67a45b07be3f0e2", "type": "api-call-service", "z": "1095d804ba7660cf", "name": "", "server": "7b975ed1.2c58d", "version": 4, "debugenabled": false, "domain": "switch", "service": "{{action}}", "target": { "entityId": [ "{{payload}}" ], "areaId": [], "deviceId": [] }, "data": "", "dataType": "jsonata", "mergeContext": "", "mustacheAltTags": false, "outputProperties": [], "queue": "none", "x": 1220, "y": 400, "wires": [ [] ] }, { "id": "948f928f2606a5c7", "type": "api-call-service", "z": "1095d804ba7660cf", "name": "", "server": "7b975ed1.2c58d", "version": 4, "debugenabled": false, "domain": "cover", "service": "{{action}}", "target": { "entityId": [ "{{payload}}" ], "areaId": [], "deviceId": [] }, "data": "", "dataType": "jsonata", "mergeContext": "", "mustacheAltTags": false, "outputProperties": [], "queue": "none", "x": 1210, "y": 460, "wires": [ [] ] }, { "id": "439c4edaa91cfd46", "type": "api-call-service", "z": "1095d804ba7660cf", "name": "lightBrightness", "server": "7b975ed1.2c58d", "version": 4, "debugenabled": false, "domain": "light", "service": "turn_on", "target": { "entityId": [ "{{payload}}" ], "areaId": [], "deviceId": [] }, "data": "{\"brightness_pct\":{{brightness}}}", "dataType": "json", "mergeContext": "", "mustacheAltTags": false, "outputProperties": [], "queue": "none", "x": 1200, "y": 280, "wires": [ [] ] }, { "id": "8b9fd15277f38896", "type": "function", "z": "1095d804ba7660cf", "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": 340, "wires": [ [ "c45664b5317f7a0f" ] ] }, { "id": "c45664b5317f7a0f", "type": "api-call-service", "z": "1095d804ba7660cf", "name": "lightTemperature", "server": "7b975ed1.2c58d", "version": 4, "debugenabled": false, "domain": "light", "service": "turn_on", "target": { "entityId": [ "{{payload}}" ], "areaId": [], "deviceId": [] }, "data": "{\"color_temp\":{{temperature}}}", "dataType": "json", "mergeContext": "", "mustacheAltTags": false, "outputProperties": [], "queue": "none", "x": 1370, "y": 340, "wires": [ [] ] }, { "id": "275db83c5edd2c9b", "type": "function", "z": "1095d804ba7660cf", "name": "config", "func": "//see start tab", "outputs": 1, "noerr": 0, "initialize": "//if (flow.get(\"ns-config\") === undefined) {\n \nvar pages = \n[\n { \n type: \"cardEntities\",\n heading: \"Rolladen\",\n items: [\"cover.rolladenfenster_cover_1\", \"cover.nspterrasse_cover_1\", \"cover.rolladenterasse_cover_1\", \"sensor.nspterrasse_analog_temperature1\"] \n },\n {\n type: \"cardEntities\",\n heading: \"TestPage\",\n items: [\"button.beamer_key_left\", \"cover.rolladenterasse_cover_1\", \"light.schreibtischlampe\", \"sensor.kleiderschrank1_si7021_temperature\"] \n }\n]\n\n\n flow.set(\"ns-config\", pages)\n//}", "finalize": "", "libs": [], "x": 1390, "y": 100, "wires": [ [] ] }, { "id": "ab0817adc78e3c5b", "type": "inject", "z": "1095d804ba7660cf", "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": 400, "wires": [ [ "e0a3b3c8887ff55f" ] ] }, { "id": "a267036facc87a9c", "type": "function", "z": "1095d804ba7660cf", "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": 340, "wires": [ [] ] }, { "id": "a9571b3ad08027d6", "type": "mqtt out", "z": "1095d804ba7660cf", "name": "", "topic": "cmnd/tasmota_NsPanelTerrasse/CustomSend", "qos": "", "retain": "", "respTopic": "", "contentType": "", "userProps": "", "correl": "", "expiry": "", "broker": "aeedd16f1f009dd0", "x": 1100, "y": 160, "wires": [] }, { "id": "8638719b967711fa", "type": "inject", "z": "1095d804ba7660cf", "name": "", "props": [ { "p": "payload" }, { "p": "topic", "vt": "str" } ], "repeat": "60", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "", "payloadType": "date", "x": 310, "y": 600, "wires": [ [ "d56371833aa274cc" ] ] }, { "id": "7288ca775329100e", "type": "debug", "z": "1095d804ba7660cf", "name": "", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "statusVal": "", "statusType": "auto", "x": 670, "y": 600, "wires": [] }, { "id": "d56371833aa274cc", "type": "function", "z": "1095d804ba7660cf", "name": "time string", "func": "var today = new Date();\n\nlet hours = today.getHours()\nlet mins = today.getMinutes()\n\nif (hours < 10) {\n hours = \"0\" + hours;\n}\nif (mins < 10) {\n mins = \"0\" + mins;\n}\n\n\nvar time = hours + \" : \" + mins;\nmsg.payload = \"time,\"+time;\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 510, "y": 600, "wires": [ [ "7288ca775329100e", "a9571b3ad08027d6" ] ] }, { "id": "bfd12f4e368fe345", "type": "inject", "z": "1095d804ba7660cf", "name": "", "props": [ { "p": "payload" }, { "p": "topic", "vt": "str" } ], "repeat": "", "crontab": "00 23 * * *", "once": false, "onceDelay": 0.1, "topic": "", "payload": "dimmode,0", "payloadType": "str", "x": 750, "y": 540, "wires": [ [ "a9571b3ad08027d6" ] ] }, { "id": "07fd340861321ee3", "type": "inject", "z": "1095d804ba7660cf", "name": "", "props": [ { "p": "payload" }, { "p": "topic", "vt": "str" } ], "repeat": "", "crontab": "00 07 * * *", "once": false, "onceDelay": 0.1, "topic": "", "payload": "dimmode,1", "payloadType": "str", "x": 750, "y": 420, "wires": [ [ "a9571b3ad08027d6" ] ] }, { "id": "9b76fcd1a10e74b1", "type": "inject", "z": "1095d804ba7660cf", "name": "", "props": [ { "p": "payload" }, { "p": "topic", "vt": "str" } ], "repeat": "", "crontab": "00 09 * * *", "once": false, "onceDelay": 0.1, "topic": "", "payload": "dimmode,10", "payloadType": "str", "x": 760, "y": 460, "wires": [ [ "a9571b3ad08027d6" ] ] }, { "id": "4f31d122bf51281e", "type": "inject", "z": "1095d804ba7660cf", "name": "", "props": [ { "p": "payload" }, { "p": "topic", "vt": "str" } ], "repeat": "", "crontab": "00 19 * * *", "once": false, "onceDelay": 0.1, "topic": "", "payload": "dimmode,1", "payloadType": "str", "x": 750, "y": 500, "wires": [ [ "a9571b3ad08027d6" ] ] }, { "id": "243b5fd457f41904", "type": "inject", "z": "1095d804ba7660cf", "name": "", "props": [ { "p": "payload" }, { "p": "topic", "vt": "str" } ], "repeat": "", "crontab": "00 00 * * *", "once": false, "onceDelay": "5", "topic": "", "payload": "", "payloadType": "date", "x": 310, "y": 640, "wires": [ [ "e0eb13c55bb592c9" ] ] }, { "id": "e038718f48e4b5b4", "type": "debug", "z": "1095d804ba7660cf", "name": "", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "statusVal": "", "statusType": "auto", "x": 670, "y": 640, "wires": [] }, { "id": "e0eb13c55bb592c9", "type": "function", "z": "1095d804ba7660cf", "name": "date string", "func": "var today = new Date();\n\nlet day = today.getDay()\nlet month = today.getMonth()\n\nconst options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };\n\nvar date = today.toLocaleDateString('de-DE', options);\n\nmsg.payload = \"date,?\"+date;\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 510, "y": 640, "wires": [ [ "e038718f48e4b5b4", "a9571b3ad08027d6" ] ] }, { "id": "a3a9cf753a414c52", "type": "inject", "z": "1095d804ba7660cf", "name": "", "props": [ { "p": "payload" }, { "p": "topic", "vt": "str" } ], "repeat": "", "crontab": "", "once": true, "onceDelay": "5", "topic": "", "payload": "", "payloadType": "date", "x": 310, "y": 680, "wires": [ [ "e0eb13c55bb592c9" ] ] }, { "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" } ]