[ { "id": "1b16bf0e99b71548", "type": "tab", "label": "nspdebug", "disabled": false, "info": "", "env": [] }, { "id": "fc261f2d1db2acab", "type": "mqtt out", "z": "1b16bf0e99b71548", "name": "", "topic": "cmnd/tasmota_nspdebugtest/Screen", "qos": "", "retain": "", "respTopic": "", "contentType": "", "userProps": "", "correl": "", "expiry": "", "broker": "aeedd16f1f009dd0", "x": 1190, "y": 140, "wires": [] }, { "id": "3adbb7a87040adcb", "type": "debug", "z": "1b16bf0e99b71548", "name": "", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "payload", "targetType": "msg", "statusVal": "", "statusType": "auto", "x": 1070, "y": 80, "wires": [] }, { "id": "3f8b47affabd553d", "type": "mqtt in", "z": "1b16bf0e99b71548", "name": "", "topic": "tele/tasmota_nspdebugtest/RESULT", "qos": "2", "datatype": "auto", "broker": "aeedd16f1f009dd0", "nl": false, "rap": true, "rh": 0, "inputs": 0, "x": 260, "y": 80, "wires": [ [ "799924b71e358164" ] ] }, { "id": "799924b71e358164", "type": "function", "z": "1b16bf0e99b71548", "name": "check for '\"{\"csv\":'", "func": "if(msg.payload.startsWith('\\{\"csv\":')){\n obj = JSON.parse(msg.payload)\n msg.payload = obj.csv\n return msg;\n}", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 530, "y": 80, "wires": [ [ "3adbb7a87040adcb", "85003e2af29ab409" ] ] }, { "id": "85003e2af29ab409", "type": "function", "z": "1b16bf0e99b71548", "name": "pages", "func": "var pages = \n[\n {\n heading: \"Rolladen\",\n items: [\"cover.rolladenfenster_cover_1\", \"cover.nspterrasse_cover_1\", \"cover.rolladenterasse_cover_1\", \"delete\"] \n },\n {\n heading: \"TestPage\",\n items: [\"button.beamer_key_left\", \"cover.rolladenterasse_cover_1\", \"light.schreibtischlampe\", \"sensor.kleiderschrank1_si7021_temperature\"] \n }\n]\n\nfunction genPage(pageNum){\n var out_msgs = [ { 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 if(id.startsWith(\"cover\")){\n type = \"shutter\"\n iconId = 0\n out_msgs.push({ payload: \"entityUpd,\"+(i+1)+\",\"+iconId+\",\"+name+\",\"+type})\n }\n if(id.startsWith(\"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 }\n if(id.startsWith(\"sensor\")){\n type = \"text\"\n \n if(global.get(\"homeassistant.homeAssistant.states['\"+id+\"'].attributes.device_class\") == \"temperature\"){\n iconId = 2\n }\n \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 }\n if(id.startsWith(\"button\")){\n type = \"button\"\n iconId = 3\n var optVal = \"PRESS\"\n out_msgs.push({ payload: \"entityUpd,\"+(i+1)+\",\"+iconId+\",\"+name+\",\"+type+\",\"+optVal})\n }\n if(id == \"delete\"){\n type = \"delete\"\n out_msgs.push({ payload: \"entityUpd,\"+(i+1)+\",0,dc,\"+type})\n }\n \n \n }\n )\n\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\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 context.set(\"currentPage\", pageNum)\n \n if(words[1]=='pageOpen'){\n return [genPage(pageNum), null]\n }\n if(words[1]=='buttonPress'){\n return [null, handleButtonEvent(pageNum, words)]\n }\n \n}\nif(words[0]=='extUpd'){\n if (context.get(\"currentPage\") === undefined) {\n context.set(\"currentPage\", 0)\n }\n \n return [genPage(context.get(\"currentPage\")), 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", "outputs": 2, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 850, "y": 120, "wires": [ [ "fc261f2d1db2acab", "3adbb7a87040adcb" ], [ "9e65c8b0a6164b41", "c2ce60ae97237e54" ] ] }, { "id": "ad12712f4d203754", "type": "server-state-changed", "z": "1b16bf0e99b71548", "name": "", "server": "7b975ed1.2c58d", "version": 3, "exposeToHomeAssistant": false, "haConfig": [ { "property": "name", "value": "" }, { "property": "icon", "value": "" } ], "entityidfilter": "light.schreibtischlampe", "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": 330, "y": 300, "wires": [ [ "cd7f5a96eb38397f" ] ] }, { "id": "9e65c8b0a6164b41", "type": "debug", "z": "1b16bf0e99b71548", "name": "", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "true", "targetType": "full", "statusVal": "", "statusType": "auto", "x": 1070, "y": 200, "wires": [] }, { "id": "05197826ebe7c1af", "type": "api-call-service", "z": "1b16bf0e99b71548", "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": 1290, "y": 200, "wires": [ [] ] }, { "id": "c2ce60ae97237e54", "type": "switch", "z": "1b16bf0e99b71548", "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": 1070, "y": 260, "wires": [ [ "05197826ebe7c1af" ], [ "20f5ee9a5622c10c" ], [ "967e2ba5ebf31f47" ], [ "e51c68a584fd494f" ], [ "b64afa1882d55eaf" ] ] }, { "id": "e51c68a584fd494f", "type": "api-call-service", "z": "1b16bf0e99b71548", "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": 1300, "y": 360, "wires": [ [] ] }, { "id": "cd7f5a96eb38397f", "type": "function", "z": "1b16bf0e99b71548", "name": "extUpd", "func": "msg.payload = \"extUpd\"\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 660, "y": 180, "wires": [ [ "85003e2af29ab409" ] ] }, { "id": "06ee793a02d15ff6", "type": "inject", "z": "1b16bf0e99b71548", "name": "", "props": [ { "p": "payload" }, { "p": "topic", "vt": "str" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "", "payloadType": "date", "x": 420, "y": 340, "wires": [ [ "cd7f5a96eb38397f" ] ] }, { "id": "b64afa1882d55eaf", "type": "api-call-service", "z": "1b16bf0e99b71548", "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": 1290, "y": 420, "wires": [ [] ] }, { "id": "20f5ee9a5622c10c", "type": "api-call-service", "z": "1b16bf0e99b71548", "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": 1280, "y": 240, "wires": [ [] ] }, { "id": "967e2ba5ebf31f47", "type": "function", "z": "1b16bf0e99b71548", "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": 1270, "y": 300, "wires": [ [ "41eac1fcf4784c53" ] ] }, { "id": "41eac1fcf4784c53", "type": "api-call-service", "z": "1b16bf0e99b71548", "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": 1450, "y": 300, "wires": [ [] ] }, { "id": "b4ee2c699f24babb", "type": "function", "z": "1b16bf0e99b71548", "name": "pages", "func": "msg.payload = global.get(\"homeassistant.homeAssistant.states['sensor.kleiderschrank1_si7021_temperature']\")\nreturn msg", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 870, "y": 580, "wires": [ [ "1f8f8e6dda770b85" ] ] }, { "id": "48655032e4a2ded6", "type": "inject", "z": "1b16bf0e99b71548", "name": "", "props": [ { "p": "payload" }, { "p": "topic", "vt": "str" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "", "payloadType": "date", "x": 680, "y": 600, "wires": [ [ "b4ee2c699f24babb" ] ] }, { "id": "1f8f8e6dda770b85", "type": "debug", "z": "1b16bf0e99b71548", "name": "", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "true", "targetType": "full", "statusVal": "", "statusType": "auto", "x": 990, "y": 600, "wires": [] }, { "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" } ]