Amerkung: Dieser Post ist geteilt in mehrere Posts, nichtmal ich darf hier so viel auf einmal posten
Hey Leute,
nochmal vielen Dank für die rege Teilnahme an unserem Livestream, hat uns sehr gefreut
Unsere neue App ist wie gesagt online und kann heruntergeladen werden:
Die App ist zweisprachig und richtet sich nach der Systemsprache eures Smartphones. Also entweder euer Handy hat Deutsch als Systemsprache eingestellt, dann ist die App auf deutsch, bei allen anderen Sprachen ist die App auf Englisch.
Dem aufmerksamen iOS-User wird vielleicht auch schon aufgefallen sein, dass die App im (deutschen) App Store nur “Pekaway” und nicht “Pekaway Connect” heißt. Naja, als ich die App zur Überprüfung eingereicht habe, habe ich nur den Titel für den englischssprachigen Store geändert… Klassiker Wird dann mit einem zukünftigen Update umbenannt.
Die App holt sich alle Daten aus der HTTP-Api, für den Zugriff aus der Ferne gibt es eine Erweiterung über MQTT, die dann intern wieder auf die HTTP -Api zugreift.
Aktuell funktioniert das allerdings noch nicht mit der IoT-Bridge! Also nur lokal oder ihr habt schon eine bestehende Internetverbindung.
Also jetzt zu den wichtigen Themen. Wenn ihr die App bereits geladen habt, dann funktioniert so ziemlich alles nicht so richtig mit der aktuell veröffentlichten Software. Es gibt dafür ein paar neue Variablen und HTTP Endpunkte. Konkret müssen die Flows “Heater Controls”, “HTTP Api”, “MQTT Api”, “Init” & “Monit” angepasst werden (und “Connections” für die kommende GPS Antenne). Dazu kommt ein neuer Flow für den Lagesensor, der ist noch nicht finalisiert, funktioniert aber prinzipiell und vielleicht will ja schon jemand darauf aufbauen.
Der Reihe nach:
HTTP-API Flow:
Wie angesprochen gibt es ein bisschen was neues, ein paar Änderungen um die Daten für die App vorzubereiten, etc. etc.
Ganz unten im Flow gibt es die Funktion für den Lagesensor, da haben wir 3 Link Out Nodes, die im Flow für den Lagesensor entsprechend verbunden werden müssen. Dazu später mehr.
Ebenfalls seht ihr eine kleine Beispielfunktion für die GPS Daten, im Großen und Ganzen werden nur die globalen Variablen “latitude”, “longitude” und “gps_updated” geschrieben.
Der (komplette) HTTP-Api Flow:
[{"id":"42fae630.bb5488","type":"comment","z":"e78e73d3.53155","name":"endpoints general ","info":"","x":130,"y":400,"wires":[]},{"id":"d88508e9.959f68","type":"http in","z":"e78e73d3.53155","name":"","url":"batt","method":"get","upload":false,"swaggerDoc":"","x":100,"y":440,"wires":[["bfac6a8c.d2ccf8"]]},{"id":"bfac6a8c.d2ccf8","type":"function","z":"e78e73d3.53155","name":"get battery stats","func":"msg.payload = {\n \"VoltB\":global.get(\"MainBattVolt\"),\n \"Ampere\":global.get(\"MainBattAmps\"),\n \"battsoc\":global.get(\"MainBattSoc\"),\n};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":280,"y":440,"wires":[["b21dc5aa.b70b18"]]},{"id":"b21dc5aa.b70b18","type":"http response","z":"e78e73d3.53155","name":"send answer","statusCode":"200","headers":{},"x":450,"y":440,"wires":[]},{"id":"ff26b15d.781d2","type":"http in","z":"e78e73d3.53155","name":"","url":"level","method":"get","upload":false,"swaggerDoc":"","x":100,"y":480,"wires":[["23326e88.54d5b2"]]},{"id":"23326e88.54d5b2","type":"function","z":"e78e73d3.53155","name":"get level stats","func":"msg.payload = {\n \"level1\": {\n \"state\":global.get(\"Level1\"),\n \"name\":global.get(\"NLevel1\")\n },\n \"level2\": {\n \"state\": global.get(\"Level2\"),\n \"name\":global.get(\"NLevel2\")\n },\n \"level3\": {\n \"state\": global.get(\"Level3\"),\n \"name\":global.get(\"NLevel3\")\n },\n \"level4\": {\n \"state\": global.get(\"Level4\"),\n \"name\":global.get(\"NLevel4\")\n }\n} ; \nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":280,"y":480,"wires":[["37f32fd8.9748e"]]},{"id":"37f32fd8.9748e","type":"http response","z":"e78e73d3.53155","name":"send answer","statusCode":"200","headers":{},"x":450,"y":480,"wires":[]},{"id":"782c51e6.7fe59","type":"http in","z":"e78e73d3.53155","name":"","url":"names","method":"get","upload":false,"swaggerDoc":"","x":110,"y":560,"wires":[["5d23d85a.2ca3b8"]]},{"id":"5d23d85a.2ca3b8","type":"function","z":"e78e73d3.53155","name":"get all names","func":"msg.payload = {\n \"Relay1\": {\n \"name\":global.get(\"None\"),\n \"globalVariable\":\"None\"\n },\n \"Relay2\": {\n \"name\":global.get(\"Ntwo\"),\n \"globalVariable\":\"Ntwo\"\n },\n \"Relay3\": {\n \"name\":global.get(\"Nthree\"),\n \"globalVariable\":\"Nthree\"\n },\n \"Relay4\": {\n \"name\":global.get(\"Nfour\"),\n \"globalVariable\":\"Nfour\"\n },\n \"Relay5\": {\n \"name\":global.get(\"Nfive\"),\n \"globalVariable\":\"Nfive\"\n },\n \"Relay6\": {\n \"name\":global.get(\"Nsix\"),\n \"globalVariable\":\"Nsix\"\n },\n \"Relay7\": {\n \"name\":global.get(\"Nseven\"),\n \"globalVariable\":\"Nseven\"\n },\n \"Relay8\": {\n \"name\":global.get(\"Neight\"),\n \"globalVariable\":\"Neight\"\n },\n \"Relay9\": {\n \"name\":global.get(\"Nnine\"),\n \"globalVariable\":\"Nnine\"\n },\n \"Relay10\": {\n \"name\":global.get(\"Nten\"),\n \"globalVariable\":\"Nten\"\n },\n \"WifiRelay1\": {\n \"name\":global.get(\"NWone\"),\n \"globalVariable\":\"NWone\"\n },\n \"WifiRelay2\": {\n \"name\":global.get(\"NWtwo\"),\n \"globalVariable\":\"NWtwo\"\n },\n \"WifiRelay3\": {\n \"name\":global.get(\"NWthree\"),\n \"globalVariable\":\"NWthree\"\n },\n \"WifiRelay4\": {\n \"name\":global.get(\"NWfour\"),\n \"globalVariable\":\"NWfour\"\n },\n \"WifiRelay5\": {\n \"name\":global.get(\"NWfive\"),\n \"globalVariable\":\"NWfive\"\n },\n \"WifiRelay6\": {\n \"name\":global.get(\"NWsix\"),\n \"globalVariable\":\"NWsix\"\n },\n \"WifiRelay7\": {\n \"name\":global.get(\"NWseven\"),\n \"globalVariable\":\"NWseven\"\n },\n \"WifiRelay8\": {\n \"name\":global.get(\"NWeight\"),\n \"globalVariable\":\"NWeight\"\n },\n \"Temp1\":{\n \"name\":global.get(\"Ntemp1\"),\n \"globalVariable\":\"NTemp1\"\n },\n \"Temp2\":{\n \"name\":global.get(\"Ntemp2\"),\n \"globalVariable\":\"NTemp2\"\n },\n \"Temp3\":{\n \"name\":global.get(\"Ntemp3\"),\n \"globalVariable\":\"NTemp3\"\n },\n \"Temp4\":{\n \"name\":global.get(\"Ntemp4\"),\n \"globalVariable\":\"NTemp4\"\n },\n \"Level1\": {\n \"name\":global.get(\"NLevel1\"),\n \"globalVariable\":\"NLevel1\"\n },\n \"Level2\": {\n \"name\":global.get(\"NLevel2\"),\n \"globalVariable\":\"NLevel2\"\n },\n \"Level3\": {\n \"name\":global.get(\"NLevel3\"),\n \"globalVariable\":\"NLevel3\"\n },\n \"Level4\": {\n \"name\":global.get(\"NLevel4\"),\n \"globalVariable\":\"NLevel4\"\n },\n \"Dimmer1\": {\n \"name\":global.get(\"Ndimmer0\"),\n \"globalVariable\":\"Ndimmer0\"\n },\n \"Dimmer2\": {\n \"name\":global.get(\"Ndimmer1\"),\n \"globalVariable\":\"Ndimmer1\"\n },\n \"Dimmer3\": {\n \"name\":global.get(\"Ndimmer2\"),\n \"globalVariable\":\"Ndimmer2\"\n },\n \"Dimmer4\": {\n \"name\":global.get(\"Ndimmer3\"),\n \"globalVariable\":\"Ndimmer3\"\n },\n \"Dimmer5\": {\n \"name\":global.get(\"Ndimmer4\"),\n \"globalVariable\":\"Ndimmer4\"\n },\n \"Dimmer6\": {\n \"name\":global.get(\"Ndimmer5\"),\n \"globalVariable\":\"Ndimmer5\"\n },\n \"Dimmer7\": {\n \"name\":global.get(\"Ndimmer6\"),\n \"globalVariable\":\"Ndimmer6\"\n },\n \"Dimmer8\": {\n \"name\":global.get(\"Ndimmer7\"),\n \"globalVariable\":\"Ndimmer7\"\n }\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":270,"y":560,"wires":[["359a0021.f59c1"]]},{"id":"359a0021.f59c1","type":"http response","z":"e78e73d3.53155","name":"send answer","statusCode":"200","headers":{},"x":450,"y":560,"wires":[]},{"id":"f43c42b0.3680f","type":"http in","z":"e78e73d3.53155","name":"","url":"heater","method":"get","upload":false,"swaggerDoc":"","x":110,"y":520,"wires":[["ef5df576.d9abc8"]]},{"id":"ef5df576.d9abc8","type":"function","z":"e78e73d3.53155","name":"get heater stats","func":"if (global.get(\"heater_runtime\") == undefined || global.get(\"heater_runtime\") == null || global.get(\"heater_runtime\") == \"cancel\") {global.set(\"heater_runtime\", 0)}\nmsg.payload = {\n \"heatertoggle\":global.get(\"HeaterToggle\"),\n \"heatstatus\":global.get(\"heatstatus\"),\n \"heattemp\":global.get(\"heattemp\"),\n \"heatvolt\":global.get(\"heatvolt\"),\n \"heatfan\":global.get(\"heatfan\"),\n \"heatglow\":global.get(\"heatpump\"),\n \"heatwpump\":global.get(\"heatwpump\"),\n \"heaterror\":global.get(\"heaterror\"),\n \"targettemp_vanpi\":Number(global.get(\"settemp\")),\n \"runtime\":Number(global.get(\"heater_runtime\"))\n};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":280,"y":520,"wires":[["e9020de4.de6d4"]]},{"id":"e9020de4.de6d4","type":"http response","z":"e78e73d3.53155","name":"send answer","statusCode":"200","headers":{},"x":450,"y":520,"wires":[]},{"id":"9ddd5b7.518bea8","type":"http in","z":"e78e73d3.53155","name":"","url":"temp","method":"get","upload":false,"swaggerDoc":"","x":100,"y":600,"wires":[["4cf7aa4a.c5c784"]]},{"id":"4cf7aa4a.c5c784","type":"function","z":"e78e73d3.53155","name":"get temp stats","func":"if (global.get(\"temp1\") == null || global.get(\"temp1\") == \"\") {\n global.set(\"temp1\", \"0\") \n}\nif (global.get(\"temp1\") == \"not connected\" || global.get(\"temp1\") == \"\") {\n global.set(\"temp1\", \"0\") \n}\nif (global.get(\"temp2\") == null || global.get(\"temp2\") == \"\") {\n global.set(\"temp2\", \"0\") \n}\nif (global.get(\"temp3\") == null || global.get(\"temp3\") == \"\") {\n global.set(\"temp3\", \"0\") \n}\nif (global.get(\"temp4\") == null || global.get(\"temp4\") == \"\") {\n global.set(\"temp4\", \"0\") \n}\nif (global.get(\"dimmytemp\") == true) {\n if (global.get(\"dimmytemp1\") == null || global.get(\"dimmytemp1\") == \"\") {\n global.set(\"dimmytemp1\", \"0\")\n }\n if (global.get(\"dimmytemp2\") == null || global.get(\"dimmytemp2\") == \"\") {\n global.set(\"dimmytemp2\", \"0\")\n }\n msg.payload = {\n \"temp1\": {\n \"state\": global.get(\"temp1\").toString(),\n \"name\": global.get(\"Ntemp1\"),\n },\n \"temp2\": {\n \"state\": global.get(\"temp2\").toString(),\n \"name\": global.get(\"Ntemp2\"),\n },\n \"temp3\": {\n \"state\": global.get(\"temp3\").toString(),\n \"name\": global.get(\"Ntemp3\"),\n },\n \"temp4\": {\n \"state\": global.get(\"temp4\").toString(),\n \"name\": global.get(\"Ntemp4\"),\n },\n \"dimmytemp1\": {\n \"state\": global.get(\"dimmytemp1\").toString(),\n \"name\": global.get(\"Ndimmytemp1\"),\n },\n \"dimmytemp2\": {\n \"state\": global.get(\"dimmytemp2\").toString(),\n \"name\": global.get(\"Ndimmytemp2\"),\n }\n } \n}\nelse {\n msg.payload = {\n \"temp1\": {\n \"state\":global.get(\"temp1\").toString(),\n \"name\":global.get(\"Ntemp1\"),\n },\n \"temp2\": {\n \"state\": global.get(\"temp2\").toString(),\n \"name\":global.get(\"Ntemp2\"),\n },\n \"temp3\": {\n \"state\": global.get(\"temp3\").toString(),\n \"name\":global.get(\"Ntemp3\"),\n },\n \"temp4\": {\n \"state\": global.get(\"temp4\").toString(),\n \"name\":global.get(\"Ntemp4\"),\n },\n }\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":280,"y":600,"wires":[["aa3a9dde.7746a"]]},{"id":"aa3a9dde.7746a","type":"http response","z":"e78e73d3.53155","name":"send answer","statusCode":"200","headers":{},"x":450,"y":600,"wires":[]},{"id":"01c1b0774a7ce1c5","type":"http in","z":"e78e73d3.53155","name":"","url":"relay/:input/:value","method":"put","upload":false,"swaggerDoc":"","x":140,"y":1260,"wires":[["d705cc504a44adc6"]]},{"id":"7352a6468ee7758c","type":"http response","z":"e78e73d3.53155","name":"send answer","statusCode":"200","headers":{},"x":550,"y":1300,"wires":[]},{"id":"d705cc504a44adc6","type":"function","z":"e78e73d3.53155","name":"check input and switch state","func":"function number2words(n){\n if (n < 20) return num[n];\n var digit = n%10;\n return number2words(~~(n/1000)) + \" thousand\" + (n%1000 != 0? \" \" + number2words(n%1000): \"\");\n}\n\nif (isNaN(parseInt(msg.req.params.input)) == false){\n var num = \"zero one two three four five six seven eight nine ten\".split(\" \");\n msg.req.params.input = parseInt(msg.req.params.input)\n msg.req.params.input = number2words(msg.req.params.input)\n}\n\nmsg.relay = msg.req.params.input;\n\nif (msg.req.params.value === \"true\") {\n msg.payload = true\n msg.relaystate = msg.payload\n return [msg, msg];\n}\nelse if (msg.req.params.value === \"false\") {\n msg.payload = false\n msg.relaystate = msg.payload\n return [msg, msg];\n}\nelse {\n msg.payload = \"value can only be true or false\"\n return [null, msg];\n}","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":380,"y":1260,"wires":[["1cb3c5e476649f72"],["1682ab47f11056de"]]},{"id":"1cb3c5e476649f72","type":"switch","z":"e78e73d3.53155","name":"","property":"relay","propertyType":"msg","rules":[{"t":"cont","v":"one","vt":"str"},{"t":"cont","v":"two","vt":"str"},{"t":"cont","v":"three","vt":"str"},{"t":"cont","v":"four","vt":"str"},{"t":"cont","v":"five","vt":"str"},{"t":"cont","v":"six","vt":"str"},{"t":"cont","v":"seven","vt":"str"},{"t":"cont","v":"eight","vt":"str"},{"t":"cont","v":"nine","vt":"str"},{"t":"cont","v":"ten","vt":"str"}],"checkall":"false","repair":false,"outputs":10,"x":750,"y":1320,"wires":[["a04b3614573af150"],["11075381c9dd3e27"],["d1c38a7c4b408418"],["bee832ef9e0bbec5"],["27e4acfea3f8598a"],["e0771acc5d3182c3"],["cf7080d88a760efb"],["c51c399bbe263fb6"],[],[]]},{"id":"a04b3614573af150","type":"link out","z":"e78e73d3.53155","name":"switch connect 1","mode":"link","links":["e9ffa3ef.cde5d"],"x":995,"y":1140,"wires":[]},{"id":"bee832ef9e0bbec5","type":"link out","z":"e78e73d3.53155","name":"switch connect 4","links":["f14867fc.930ab8"],"x":995,"y":1260,"wires":[]},{"id":"27e4acfea3f8598a","type":"link out","z":"e78e73d3.53155","name":"switch connect 5","links":["8cde3678.94ac88","1d05179e.1f1a78","1e0f28f7.6b3347","a17061ed.e682d"],"x":995,"y":1300,"wires":[]},{"id":"e0771acc5d3182c3","type":"link out","z":"e78e73d3.53155","name":"switch connect 6","links":["a45ee432.b7ef98","c9adec52.63ae6","f4303c75.d5b1c","31dcf86e.085898"],"x":995,"y":1340,"wires":[]},{"id":"cf7080d88a760efb","type":"link out","z":"e78e73d3.53155","name":"switch connect 7","links":["e97a5ba1.09c7e8","38796905.f4b7f6","de881e69.90777","3f2d3621.ced3da"],"x":995,"y":1380,"wires":[]},{"id":"c51c399bbe263fb6","type":"link out","z":"e78e73d3.53155","name":"switch connect 8","links":["95089e82.5785e","2840c10.f61294","f38ca7b2.7594d8","c946b435.21b198"],"x":995,"y":1420,"wires":[]},{"id":"11075381c9dd3e27","type":"link out","z":"e78e73d3.53155","name":"switch connect 2","links":["7255f9f4.6304d8"],"x":995,"y":1180,"wires":[]},{"id":"d1c38a7c4b408418","type":"link out","z":"e78e73d3.53155","name":"switch connect 3","links":["c698c6e8.416b58"],"x":995,"y":1220,"wires":[]},{"id":"1682ab47f11056de","type":"function","z":"e78e73d3.53155","name":"set answer","func":"if (msg.payload.toString().includes(\"can only be\")){\n return msg\n}\nelse {\n var autooff = global.get(msg.relay+\"offauto\")\n msg.payload = {\n \"relay\": msg.relay,\n \"state\": msg.relaystate,\n \"autooff\": autooff\n }\n return msg\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":370,"y":1300,"wires":[["7352a6468ee7758c"]]},{"id":"857bd591a72db827","type":"http in","z":"e78e73d3.53155","name":"","url":"relay/:input","method":"get","upload":false,"swaggerDoc":"","x":120,"y":1400,"wires":[["3f8e55018a683876"]]},{"id":"24ec5317eca5f0fb","type":"http response","z":"e78e73d3.53155","name":"send answer","statusCode":"200","headers":{},"x":610,"y":1400,"wires":[]},{"id":"3f8e55018a683876","type":"function","z":"e78e73d3.53155","name":"check input and get relay","func":"function number2words(n){\n if (n < 20) return num[n];\n var digit = n%10;\n return number2words(~~(n/1000)) + \" thousand\" + (n%1000 != 0? \" \" + number2words(n%1000): \"\");\n}\n\nvar globalVar = msg.req.params.input\n\nif (isNaN(parseInt(msg.req.params.input)) == false){\n var num = \"zero one two three four five six seven eight nine ten\".split(\" \");\n msg.req.params.input = parseInt(msg.req.params.input)\n msg.req.params.input = number2words(msg.req.params.input)\n globalVar = msg.req.params.input\n}\n\nif (msg.req.params.input==\"all\") {\n msg.payload = {\n \"Relay1\": {\n \"state\":global.get(\"one\"), \n \"name\":global.get(\"None\"),\n //\"autooff\": global.get(\"oneoffauto\")\n },\n \"Relay2\": {\n \"state\":global.get(\"two\"), \n \"name\":global.get(\"Ntwo\"),\n //\"autooff\": global.get(\"twooffauto\")\n },\n \"Relay3\": {\n \"state\":global.get(\"three\"), \n \"name\":global.get(\"Nthree\"),\n //\"autooff\": global.get(\"threeoffauto\")\n },\n \"Relay4\": {\n \"state\":global.get(\"four\"), \n \"name\":global.get(\"Nfour\"),\n //\"autooff\": global.get(\"fouroffauto\")\n },\n \"Relay5\": {\n \"state\":global.get(\"five\"), \n \"name\":global.get(\"Nfive\"),\n //\"autooff\": global.get(\"fiveoffauto\")\n },\n \"Relay6\": {\n \"state\":global.get(\"six\"), \n \"name\":global.get(\"Nsix\"),\n //\"autooff\": global.get(\"sixoffauto\")\n },\n \"Relay7\": {\n \"state\":global.get(\"seven\"), \n \"name\":global.get(\"Nseven\"),\n //\"autooff\": global.get(\"sevenoffauto\")\n },\n \"Relay8\": {\n \"state\":global.get(\"eight\"), \n \"name\":global.get(\"Neight\"),\n //\"autooff\": global.get(\"eightoffauto\")\n }\n\n };\n}\nelse if (global.get(msg.req.params.input)!==undefined) {\n var n = \"N\"+msg.req.params.input\n var autooff = global.get(msg.req.params.input+\"offauto\")\n msg.payload = {\n \"relay\":msg.req.params.input,\n \"state\":global.get(msg.req.params.input),\n \"name\":global.get(n),\n //\"autooff\": autooff\n };\n}\nelse {\n msg.payload = \"relay \" + msg.req.params.input + \" does not exist\"\n}\n \nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":370,"y":1400,"wires":[["24ec5317eca5f0fb"]]},{"id":"86bc478d69c132c1","type":"http in","z":"e78e73d3.53155","name":"","url":"toggle/relay/:input","method":"put","upload":false,"swaggerDoc":"","x":140,"y":1340,"wires":[["57fd6373ec601066"]]},{"id":"57fd6373ec601066","type":"function","z":"e78e73d3.53155","name":"check input and switch state","func":"function number2words(n){\n if (n < 20) return num[n];\n var digit = n%10;\n return number2words(~~(n/1000)) + \" thousand\" + (n%1000 != 0? \" \" + number2words(n%1000): \"\");\n}\n\nif (isNaN(parseInt(msg.req.params.input)) == false){\n var num = \"zero one two three four five six seven eight nine ten\".split(\" \");\n msg.req.params.input = parseInt(msg.req.params.input)\n msg.req.params.input = number2words(msg.req.params.input)\n}\n\nmsg.relay = msg.req.params.input;\n\nif (global.get(msg.relay) == true) {\n msg.payload = false\n msg.relaystate = msg.payload\n}\nelse if (global.get(msg.relay) == false) {\n msg.payload = true\n msg.relaystate = msg.payload\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":380,"y":1340,"wires":[["1cb3c5e476649f72","1682ab47f11056de"]]},{"id":"94700921f269acea","type":"http in","z":"e78e73d3.53155","name":"","url":"relay/","method":"get","upload":false,"swaggerDoc":"","x":110,"y":1440,"wires":[["85a890eb47b407a0"]]},{"id":"85a890eb47b407a0","type":"change","z":"e78e73d3.53155","name":"","rules":[{"t":"set","p":"req.params.input","pt":"msg","to":"all","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":1440,"wires":[["3f8e55018a683876"]]},{"id":"10071c4e6ed27059","type":"http in","z":"e78e73d3.53155","name":"","url":"names/:input","method":"put","upload":false,"swaggerDoc":"","x":130,"y":280,"wires":[["0e42267ed02c70bb"]]},{"id":"0e42267ed02c70bb","type":"function","z":"e78e73d3.53155","name":"check input and set name","func":"if (msg.req.params.input == \"update\") {\n msg.payload = \"names have been updated\"\n return [msg, null]\n}\n\nmsg.globalVar = \"N\"+msg.req.params.input;\n\nif (global.get(msg.globalVar)!==undefined) {\n global.set(msg.globalVar, msg.payload)\n\n msg.payload = {\n \"description\":msg.globalVar,\n \"name\":global.get(msg.globalVar)\n }\n //answer http request\n node.send([msg, null])\n //set payload for textfield in dashboard\n msg.payload = global.get(msg.globalVar)\n return [null, msg]\n}\nelse {\n msg.payload = \"global variable \" + msg.req.params.input + \" is not defined\";\n return [msg, null]\n}","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":450,"y":280,"wires":[["e9be18c319bccfd1","961a8b6d41509271"],["34ed1bb765acddd3"]]},{"id":"e9be18c319bccfd1","type":"http response","z":"e78e73d3.53155","name":"answer","statusCode":"200","headers":{},"x":680,"y":280,"wires":[]},{"id":"34ed1bb765acddd3","type":"switch","z":"e78e73d3.53155","name":"","property":"globalVar","propertyType":"msg","rules":[{"t":"eq","v":"Ntemp1","vt":"str"},{"t":"eq","v":"Ntemp2","vt":"str"},{"t":"eq","v":"Ntemp3","vt":"str"},{"t":"eq","v":"Ntemp4","vt":"str"},{"t":"eq","v":"NLevel1","vt":"str"},{"t":"eq","v":"NLevel2","vt":"str"},{"t":"eq","v":"NLevel3","vt":"str"},{"t":"eq","v":"NLevel4","vt":"str"},{"t":"eq","v":"None","vt":"str"},{"t":"eq","v":"Ntwo","vt":"str"},{"t":"eq","v":"Nthree","vt":"str"},{"t":"eq","v":"Nfour","vt":"str"},{"t":"eq","v":"Nfive","vt":"str"},{"t":"eq","v":"Nsix","vt":"str"},{"t":"eq","v":"Nseven","vt":"str"},{"t":"eq","v":"Neight","vt":"str"},{"t":"eq","v":"Nnine","vt":"str"},{"t":"eq","v":"Nten","vt":"str"},{"t":"eq","v":"NWone","vt":"str"},{"t":"eq","v":"NWtwo","vt":"str"},{"t":"eq","v":"NWthree","vt":"str"},{"t":"eq","v":"NWfour","vt":"str"},{"t":"eq","v":"NWfive","vt":"str"},{"t":"eq","v":"NWsix","vt":"str"},{"t":"eq","v":"NWseven","vt":"str"},{"t":"eq","v":"NWeight","vt":"str"},{"t":"eq","v":"Ndimmer0","vt":"str"},{"t":"eq","v":"Ndimmer1","vt":"str"},{"t":"eq","v":"Ndimmer2","vt":"str"},{"t":"eq","v":"Ndimmer3","vt":"str"},{"t":"eq","v":"Ndimmer4","vt":"str"},{"t":"eq","v":"Ndimmer5","vt":"str"},{"t":"eq","v":"Ndimmer6","vt":"str"},{"t":"eq","v":"Ndimmer7","vt":"str"},{"t":"eq","v":"Ndimmytemp1","vt":"str"},{"t":"eq","v":"Ndimmytemp2","vt":"str"}],"checkall":"false","repair":false,"outputs":36,"x":810,"y":360,"wires":[["8f3c59a42992518b"],["1ca17d1277c17055"],["e2d931c67b5038fe"],["967fa4e3178fb82b"],["4d1b006b57d6ef45"],["45bba022abc3c534"],["dcebcef7012c7f07"],["c693ba0e60a42a37"],["2215762d38495713"],["523289f1d05dad12"],["3a8124b501346d8b"],["fd6bfa7ca31c97fa"],["6f9b853e331a293a"],["004c62c10b636096"],["3a493f6979414933"],["ec202c43ad863b73"],["3818a04b207aea8c"],["3966ddcffc558c87"],["d7a9ec06ef6a2f8f"],["d74657bdf8030b2f"],["da2cf914da6895c2"],["06e51df7bb811802"],["ea39a7c19379ec5a"],["22bb0428f7f4d15b"],["ba8e80a7849282a2"],["d9fdbbd1cd30f63e"],["c26a4b876c4901c9"],["c9ed3e060355439a"],["130f980449b663c9"],["b84b7db4506f8198"],["b84c1e8756a08551"],["058bad9790e5e006"],["cd383f78ea1aa841"],["d9a0767fc8e50b76"],["6f7685fb79ce0438"],["761da5923e187298"]]},{"id":"8f3c59a42992518b","type":"link out","z":"e78e73d3.53155","name":"Ntemp1","links":["1a8794f31a3f9ddb"],"x":1015,"y":20,"wires":[]},{"id":"1ca17d1277c17055","type":"link out","z":"e78e73d3.53155","name":"Ntemp2","links":["dc783718278813d6"],"x":1015,"y":40,"wires":[]},{"id":"e2d931c67b5038fe","type":"link out","z":"e78e73d3.53155","name":"Ntemp3","links":["cfb819effd2aef27"],"x":1015,"y":60,"wires":[]},{"id":"967fa4e3178fb82b","type":"link out","z":"e78e73d3.53155","name":"Ntemp4","links":["d2008d5c540c4214"],"x":1015,"y":80,"wires":[]},{"id":"4d1b006b57d6ef45","type":"link out","z":"e78e73d3.53155","name":"NLevel1","links":["2fd913aba86f7a79"],"x":1015,"y":100,"wires":[]},{"id":"45bba022abc3c534","type":"link out","z":"e78e73d3.53155","name":"NLevel2","links":["3332389371230b20"],"x":1015,"y":120,"wires":[]},{"id":"dcebcef7012c7f07","type":"link out","z":"e78e73d3.53155","name":"NLevel3","links":["4c35af4930ed3a51"],"x":1015,"y":140,"wires":[]},{"id":"c693ba0e60a42a37","type":"link out","z":"e78e73d3.53155","name":"NLevel4","links":["9fa5ed9642841cac"],"x":1015,"y":160,"wires":[]},{"id":"2215762d38495713","type":"link out","z":"e78e73d3.53155","name":"None","links":["7e3adb9d283ce234"],"x":1015,"y":180,"wires":[]},{"id":"523289f1d05dad12","type":"link out","z":"e78e73d3.53155","name":"Ntwo","links":["ca585a03f0fe6085"],"x":1015,"y":200,"wires":[]},{"id":"3a8124b501346d8b","type":"link out","z":"e78e73d3.53155","name":"Nthree","links":["d24286c0f1f05cf1"],"x":1015,"y":220,"wires":[]},{"id":"fd6bfa7ca31c97fa","type":"link out","z":"e78e73d3.53155","name":"Nfour","links":["1bbf9074b56672aa"],"x":1015,"y":240,"wires":[]},{"id":"6f9b853e331a293a","type":"link out","z":"e78e73d3.53155","name":"Nfive","links":["ffdfcbf3d0444b71"],"x":1015,"y":260,"wires":[]},{"id":"004c62c10b636096","type":"link out","z":"e78e73d3.53155","name":"Nsix","links":["f77512a00db0f317"],"x":1015,"y":280,"wires":[]},{"id":"3a493f6979414933","type":"link out","z":"e78e73d3.53155","name":"Nseven","links":["01d48cd43596ed13"],"x":1015,"y":300,"wires":[]},{"id":"ec202c43ad863b73","type":"link out","z":"e78e73d3.53155","name":"Neight","links":["a4c1332f59457b49"],"x":1015,"y":320,"wires":[]},{"id":"3818a04b207aea8c","type":"link out","z":"e78e73d3.53155","name":"Nnine","links":["5d29a3a442f887f7"],"x":1015,"y":340,"wires":[]},{"id":"3966ddcffc558c87","type":"link out","z":"e78e73d3.53155","name":"Nten","links":["82c952ea0eeb0aca"],"x":1015,"y":360,"wires":[]},{"id":"d7a9ec06ef6a2f8f","type":"link out","z":"e78e73d3.53155","name":"NWone","links":["473f2db910e74f46"],"x":1015,"y":380,"wires":[]},{"id":"d74657bdf8030b2f","type":"link out","z":"e78e73d3.53155","name":"NWtwo","links":["dc023f5d7a61c9d9"],"x":1015,"y":400,"wires":[]},{"id":"da2cf914da6895c2","type":"link out","z":"e78e73d3.53155","name":"NWthree","links":["2110d5ae121a4453"],"x":1015,"y":420,"wires":[]},{"id":"06e51df7bb811802","type":"link out","z":"e78e73d3.53155","name":"NWfour","links":["5d624ae1b18443db"],"x":1015,"y":440,"wires":[]},{"id":"ea39a7c19379ec5a","type":"link out","z":"e78e73d3.53155","name":"NWfive","links":["665af31eeae91d53"],"x":1015,"y":460,"wires":[]},{"id":"22bb0428f7f4d15b","type":"link out","z":"e78e73d3.53155","name":"NWsix","links":["5a630b11c01d184b"],"x":1015,"y":480,"wires":[]},{"id":"d9fdbbd1cd30f63e","type":"link out","z":"e78e73d3.53155","name":"NWeight","links":["d3dc38692edfe006"],"x":1015,"y":520,"wires":[]},{"id":"ba8e80a7849282a2","type":"link out","z":"e78e73d3.53155","name":"NWseven","links":["01d48cd43596ed13"],"x":1015,"y":500,"wires":[]},{"id":"c26a4b876c4901c9","type":"link out","z":"e78e73d3.53155","name":"Ndimmer0","links":["c66a52b7774be47b"],"x":1015,"y":540,"wires":[]},{"id":"c9ed3e060355439a","type":"link out","z":"e78e73d3.53155","name":"Ndimmer1","links":["4086c55304ba32ae"],"x":1015,"y":560,"wires":[]},{"id":"130f980449b663c9","type":"link out","z":"e78e73d3.53155","name":"Ndimmer2","links":["d65b3469341a8601"],"x":1015,"y":580,"wires":[]},{"id":"b84b7db4506f8198","type":"link out","z":"e78e73d3.53155","name":"Ndimmer3","links":["38fd2c83faf60559"],"x":1015,"y":600,"wires":[]},{"id":"b84c1e8756a08551","type":"link out","z":"e78e73d3.53155","name":"Ndimmer4","links":["24787a551c032712"],"x":1015,"y":620,"wires":[]},{"id":"058bad9790e5e006","type":"link out","z":"e78e73d3.53155","name":"Ndimmer5","links":["702959d76f03f238"],"x":1015,"y":640,"wires":[]},{"id":"cd383f78ea1aa841","type":"link out","z":"e78e73d3.53155","name":"Ndimmer6","links":["32079052da4028df"],"x":1015,"y":660,"wires":[]},{"id":"d9a0767fc8e50b76","type":"link out","z":"e78e73d3.53155","name":"Ndimmer7","mode":"link","links":["34ce2bd2a0b794e4"],"x":1015,"y":680,"wires":[]},{"id":"f9ca9d33383d5220","type":"http response","z":"e78e73d3.53155","name":"send answer","statusCode":"200","headers":{},"x":590,"y":1620,"wires":[]},{"id":"5d26899bef877b6f","type":"switch","z":"e78e73d3.53155","name":"","property":"relay","propertyType":"msg","rules":[{"t":"cont","v":"one","vt":"str"},{"t":"cont","v":"two","vt":"str"},{"t":"cont","v":"three","vt":"str"},{"t":"cont","v":"four","vt":"str"},{"t":"cont","v":"five","vt":"str"},{"t":"cont","v":"six","vt":"str"},{"t":"cont","v":"seven","vt":"str"},{"t":"cont","v":"eight","vt":"str"}],"checkall":"false","repair":false,"outputs":8,"x":750,"y":1620,"wires":[["937d5e03dd599a61"],["80da336a069ba2df"],["80cd2ca9be046404"],["236f17a63794e768"],["7cb5ca22f1c184e8"],["8c23965172e6d81f"],["c4e1e5d7a9f81b29"],["0bf4c82c6cb860c4"]]},{"id":"236f17a63794e768","type":"link out","z":"e78e73d3.53155","name":"switch connect 4","links":["d2ce5044.ef8af"],"x":995,"y":1580,"wires":[]},{"id":"7cb5ca22f1c184e8","type":"link out","z":"e78e73d3.53155","name":"switch connect 5","links":["9f1c7c65c2da2d42"],"x":995,"y":1620,"wires":[]},{"id":"8c23965172e6d81f","type":"link out","z":"e78e73d3.53155","name":"switch connect 6","links":["d76c3b78c0f14e69"],"x":995,"y":1660,"wires":[]},{"id":"c4e1e5d7a9f81b29","type":"link out","z":"e78e73d3.53155","name":"switch connect 7","links":["34f49f08e1a06032"],"x":995,"y":1700,"wires":[]},{"id":"0bf4c82c6cb860c4","type":"link out","z":"e78e73d3.53155","name":"switch connect 8","links":["1be6547089f6e149"],"x":995,"y":1740,"wires":[]},{"id":"80da336a069ba2df","type":"link out","z":"e78e73d3.53155","name":"switch connect 2","links":["33a5d09e.6cc14"],"x":995,"y":1500,"wires":[]},{"id":"80cd2ca9be046404","type":"link out","z":"e78e73d3.53155","name":"switch connect 3","links":["428f4d48.86eaf4"],"x":995,"y":1540,"wires":[]},{"id":"56e1abb5b2e7247e","type":"function","z":"e78e73d3.53155","name":"set answer","func":"if (msg.payload.toString().includes(\"can only be\")){\n return msg\n}\nelse {\n var autooff = global.get(msg.relay.toLowerCase()+\"offauto\")\n msg.payload = {\n \"relay\": msg.relay,\n \"state\": msg.relaystate,\n \"autooff\": autooff\n }\n return msg\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":410,"y":1620,"wires":[["f9ca9d33383d5220"]]},{"id":"a454928c0a2e740d","type":"http in","z":"e78e73d3.53155","name":"","url":"wrelay/:input","method":"get","upload":false,"swaggerDoc":"","x":130,"y":1720,"wires":[["9c197e66867dcb29"]]},{"id":"a2c7311476d4c970","type":"http response","z":"e78e73d3.53155","name":"send answer","statusCode":"200","headers":{},"x":670,"y":1720,"wires":[]},{"id":"9c197e66867dcb29","type":"function","z":"e78e73d3.53155","name":"check input and get wrelay","func":"function number2words(n){\n if (n < 20) return num[n];\n var digit = n%10;\n return number2words(~~(n/1000)) + \" thousand\" + (n%1000 != 0? \" \" + number2words(n%1000): \"\");\n}\n\nvar globalVar = \"W\"+msg.req.params.input\n\nif (isNaN(parseInt(msg.req.params.input)) == false){\n var num = \"zero one two three four five six seven eight nine ten\".split(\" \");\n msg.req.params.input = parseInt(msg.req.params.input)\n msg.req.params.input = number2words(msg.req.params.input)\n globalVar = \"W\"+msg.req.params.input\n}\n\nif (msg.req.params.input==\"all\") {\n msg.payload = {\n \"WifiRelay1\": {\n \"state\":global.get(\"Wone\"), \n \"name\":global.get(\"NWone\"),\n \"firmware\":global.get(\"wrelay1_firmware\"),\n \"autooff\": global.get(\"woneoffauto\")\n },\n \"WifiRelay2\": {\n \"state\":global.get(\"Wtwo\"), \n \"name\":global.get(\"NWtwo\"),\n \"firmware\":global.get(\"wrelay2_firmware\"),\n \"autooff\": global.get(\"wtwooffauto\")\n },\n \"WifiRelay3\": {\n \"state\":global.get(\"Wthree\"), \n \"name\":global.get(\"NWthree\"),\n \"firmware\":global.get(\"wrelay3_firmware\"),\n \"autooff\": global.get(\"wthreeoffauto\")\n },\n \"WifiRelay4\": {\n \"state\":global.get(\"Wfour\"), \n \"name\":global.get(\"NWfour\"),\n \"firmware\":global.get(\"wrelay4_firmware\"),\n \"autooff\": global.get(\"wfouroffauto\")\n },\n \"WifiRelay5\": {\n \"state\":global.get(\"Wfive\"), \n \"name\":global.get(\"NWfive\"),\n \"firmware\":global.get(\"wrelay5_firmware\"),\n \"autooff\": global.get(\"wfiveoffauto\")\n },\n \"WifiRelay6\": {\n \"state\":global.get(\"Wsix\"), \n \"name\":global.get(\"NWsix\"),\n \"firmware\":global.get(\"wrelay6_firmware\"),\n \"autooff\": global.get(\"wsixoffauto\")\n },\n \"WifiRelay7\": {\n \"state\":global.get(\"Wseven\"), \n \"name\":global.get(\"NWseven\"),\n \"firmware\":global.get(\"wrelay7_firmware\"),\n \"autooff\": global.get(\"wsevenoffauto\")\n },\n \"WifiRelay8\": {\n \"state\":global.get(\"Weight\"), \n \"name\":global.get(\"NWeight\"),\n \"firmware\":global.get(\"wrelay8_firmware\"),\n \"autooff\": global.get(\"weightoffauto\")\n }\n };\n}\n\nelse if (global.get(globalVar)!==undefined) {\n var autooff = global.get(\"w\"+msg.req.params.input+\"offauto\")\n var n = \"NW\"+msg.req.params.input\n msg.payload = {\n \"wifirelay\":globalVar,\n \"state\":global.get(globalVar),\n \"name\":global.get(n),\n \"autooff\": autooff\n };\n}\nelse {\n msg.payload = \"wifirelay \" + msg.req.params.input + \" does not exist\"\n}\n \nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":420,"y":1720,"wires":[["a2c7311476d4c970"]]},{"id":"ac3c4fe5cd58e530","type":"http in","z":"e78e73d3.53155","name":"","url":"/toggle/wrelay/:input","method":"put","upload":false,"swaggerDoc":"","x":150,"y":1660,"wires":[["3afd7417681bcb87"]]},{"id":"3afd7417681bcb87","type":"function","z":"e78e73d3.53155","name":"check input and switch state","func":"function number2words(n){\n if (n < 20) return num[n];\n var digit = n%10;\n return number2words(~~(n/1000)) + \" thousand\" + (n%1000 != 0? \" \" + number2words(n%1000): \"\");\n}\n\nif (isNaN(parseInt(msg.req.params.input)) == false){\n var num = \"zero one two three four five six seven eight nine ten\".split(\" \");\n msg.req.params.input = parseInt(msg.req.params.input)\n msg.req.params.input = number2words(msg.req.params.input)\n}\n\nmsg.relay = \"W\"+msg.req.params.input;\n\nif (global.get(msg.relay) == true) {\n msg.payload = false\n msg.relaystate = msg.payload\n}\nelse if (global.get(msg.relay) == false) {\n msg.payload = true\n msg.relaystate = msg.payload\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":420,"y":1660,"wires":[["5d26899bef877b6f","56e1abb5b2e7247e"]]},{"id":"5aec9fd67fb417a3","type":"http in","z":"e78e73d3.53155","name":"","url":"wrelay/","method":"get","upload":false,"swaggerDoc":"","x":110,"y":1760,"wires":[["8ab619cea79ce0b1"]]},{"id":"8ab619cea79ce0b1","type":"change","z":"e78e73d3.53155","name":"","rules":[{"t":"set","p":"req.params.input","pt":"msg","to":"all","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":1760,"wires":[["9c197e66867dcb29"]]},{"id":"937d5e03dd599a61","type":"link out","z":"e78e73d3.53155","name":"switch connect 1","links":["afbb8dda.ffe6c"],"x":995,"y":1460,"wires":[]},{"id":"1ef68c5891594021","type":"comment","z":"e78e73d3.53155","name":"endpoints relays","info":"","x":120,"y":1220,"wires":[]},{"id":"90aaa84e3c4647b5","type":"comment","z":"e78e73d3.53155","name":"endpoints wifirelays","info":"","x":130,"y":1540,"wires":[]},{"id":"b87b808afe6eb9ed","type":"comment","z":"e78e73d3.53155","name":"endpoints names","info":"","x":120,"y":240,"wires":[]},{"id":"04e90dc1676dd13a","type":"http in","z":"e78e73d3.53155","name":"","url":"dimmer/:input/:value","method":"put","upload":false,"swaggerDoc":"","x":150,"y":1900,"wires":[["4731f46fb5c68aa6"]]},{"id":"b987d9635c725793","type":"http response","z":"e78e73d3.53155","name":"send answer","statusCode":"200","headers":{},"x":570,"y":1940,"wires":[]},{"id":"4731f46fb5c68aa6","type":"function","z":"e78e73d3.53155","name":"check input and set global var","func":"function text2num(s) {\n a = s.toString().split(/[\\s-]+/);\n n = 0;\n g = 0;\n a.forEach(feach);\n return n + g;\n}\n\nfunction feach(w) {\n var x = input[w];\n g = g + x;\n}\n\nfunction number2words(n){\n if (n < 20) return num[n];\n var digit = n%10;\n return number2words(~~(n/1000)) + \" thousand\" + (n%1000 != 0? \" \" + number2words(n%1000): \"\");\n}\n\nvar num = \"zero one two three four five six seven eight nine ten\".split(\" \");\nvar input = { 'one': 0, 'two': 1, 'three': 2, 'four': 3, 'five': 4, 'six': 5, 'seven': 6, 'eight': 7};\nvar a, n, g, dimmerno;\n\n//check if input is a number\nif (isNaN(parseInt(msg.req.params.input)) == false) {\n if (parseInt(msg.req.params.input) < 9 && parseInt(msg.req.params.input) > 0) {\n msg.req.params.input = parseInt(msg.req.params.input)-1\n msg.targetdimmerno = \"Ndimmer\"+msg.req.params.input.toString()\n msg.req.params.input = parseInt(msg.req.params.input)+1\n msg.dimmer = number2words(msg.req.params.input);\n msg.newValue = parseInt(msg.req.params.value);\n }\n else {\n msg.payload = \"dimmer \" + msg.req.params.input + \" does not exist\"\n return [null, msg];\n }\n}\nelse if (isNaN(parseInt(msg.req.params.input)) == true){\n msg.dimmerno = text2num(msg.req.params.input);\n msg.targetdimmerno = \"Ndimmer\"+msg.dimmerno.toString()\n msg.dimmer = msg.req.params.input;\n msg.newValue = parseInt(msg.req.params.value);\n}\n\nif (isNaN(msg.newValue) || msg.newValue < 0 || msg.newValue > 100) {\n msg.payload = \"value type must be numeric and between 0-100\"\n return [null, msg]\n}\nelse if (global.get(msg.targetdimmerno)!==undefined) {\n msg.payload = msg.newValue\n msg.label = global.get(msg.targetdimmerno)\n return [msg, msg]\n}\nelse {\n msg.payload = \"dimmer \" + msg.req.params.input + \" does not exist\"\n return [null, msg];\n \n}","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":430,"y":1900,"wires":[["eaef487a095f1941"],["fc065be1e2a2befc"]]},{"id":"eaef487a095f1941","type":"switch","z":"e78e73d3.53155","name":"","property":"dimmer","propertyType":"msg","rules":[{"t":"cont","v":"one","vt":"str"},{"t":"cont","v":"two","vt":"str"},{"t":"cont","v":"three","vt":"str"},{"t":"cont","v":"four","vt":"str"},{"t":"cont","v":"five","vt":"str"},{"t":"cont","v":"six","vt":"str"},{"t":"cont","v":"seven","vt":"str"},{"t":"cont","v":"eight","vt":"str"}],"checkall":"false","repair":false,"outputs":8,"x":750,"y":1920,"wires":[["5c11b83dee20395c"],["943b6d53caa983d3"],["d237df5591cd888b"],["59f8057dce575916"],["d34f3ab8abe848f6"],["439c5c6219f2ad26"],["7cbbc3bbc7cca512"],["fa5e454b2672161d"]]},{"id":"5c11b83dee20395c","type":"link out","z":"e78e73d3.53155","name":"dimmer0 http","links":["a4c0fd66546e7864"],"x":995,"y":1800,"wires":[]},{"id":"943b6d53caa983d3","type":"link out","z":"e78e73d3.53155","name":"dimmer1 http","links":["1db51e9f7fe5ebea"],"x":995,"y":1840,"wires":[]},{"id":"d237df5591cd888b","type":"link out","z":"e78e73d3.53155","name":"dimmer2 http","links":["09bf8b5862924eed"],"x":995,"y":1880,"wires":[]},{"id":"59f8057dce575916","type":"link out","z":"e78e73d3.53155","name":"dimmer3 http","links":["4896e98db77c2f91"],"x":995,"y":1920,"wires":[]},{"id":"d34f3ab8abe848f6","type":"link out","z":"e78e73d3.53155","name":"dimmer4 http","links":["77683cc8a2a2dd71"],"x":995,"y":1960,"wires":[]},{"id":"439c5c6219f2ad26","type":"link out","z":"e78e73d3.53155","name":"dimmer5 http","links":["2530d817d07d6ef2"],"x":995,"y":2000,"wires":[]},{"id":"7cbbc3bbc7cca512","type":"link out","z":"e78e73d3.53155","name":"dimmer6 http","links":["d4e73c36b453526a"],"x":995,"y":2040,"wires":[]},{"id":"fa5e454b2672161d","type":"link out","z":"e78e73d3.53155","name":"dimmer7 http","links":["bd1237489ec8e5f3"],"x":995,"y":2080,"wires":[]},{"id":"fc065be1e2a2befc","type":"function","z":"e78e73d3.53155","name":"set answer","func":"if (msg.payload.toString().includes(\" must be numeric\") || msg.payload.toString().includes(\" does not exist\")){\n return msg\n}\nelse {\n msg.payload = {\n \"dimmer\": msg.dimmer,\n \"state\": msg.newValue\n }\n return msg\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":390,"y":1940,"wires":[["b987d9635c725793"]]},{"id":"53e6240e6b18b304","type":"http in","z":"e78e73d3.53155","name":"","url":"dimmer/:input","method":"get","upload":false,"swaggerDoc":"","x":130,"y":2000,"wires":[["7fe809b2f568b3ee"]]},{"id":"f684785ea126e942","type":"http response","z":"e78e73d3.53155","name":"send answer","statusCode":"200","headers":{},"x":670,"y":2000,"wires":[]},{"id":"7fe809b2f568b3ee","type":"function","z":"e78e73d3.53155","name":"check input and get dimmer","func":"var a \nvar n \nvar g\n\nfunction text2num(s) {\n a = s.toString().split(/[\\s-]+/);\n n = 0;\n g = 0;\n a.forEach(feach);\n return n + g;\n}\nfunction feach(w) {\n var x = input[w];\n g = g + x;\n}\nvar input = {'one': 0, 'two': 1, 'three': 2, 'four': 3, 'five': 4, 'six': 5, 'seven': 6, 'eight': 7};\nvar targetdimmerno;\nmsg.targetdimmerno = \"\"\n\n//check if input is a number\nif (isNaN(parseInt(msg.req.params.input)) == false) {\n if (parseInt(msg.req.params.input) < 9) {\n msg.req.params.input = parseInt(msg.req.params.input)-1\n targetdimmerno = \"dimmer\"+msg.req.params.input.toString()\n msg.req.params.input = parseInt(msg.req.params.input)+1\n }\n}\nelse if (isNaN(parseInt(msg.req.params.input)) == true){\n msg.dimmerno = text2num(msg.req.params.input);\n targetdimmerno = \"dimmer\"+msg.dimmerno.toString()\n}\n\nif (msg.req.params.input==\"all\") {\n msg.payload = {\n \"dimmer1\": {\n \"state\": parseInt(global.get(\"dimmer0\")),\n \"name\":global.get(\"Ndimmer0\"),\n },\n \"dimmer2\": {\n \"state\": parseInt(global.get(\"dimmer1\")),\n \"name\":global.get(\"Ndimmer1\"),\n },\n \"dimmer3\": {\n \"state\": parseInt(global.get(\"dimmer2\")),\n \"name\":global.get(\"Ndimmer2\"),\n },\n \"dimmer4\": {\n \"state\": parseInt(global.get(\"dimmer3\")),\n \"name\":global.get(\"Ndimmer3\"),\n },\n \"dimmer5\": {\n \"state\": parseInt(global.get(\"dimmer4\")),\n \"name\":global.get(\"Ndimmer4\"),\n },\n \"dimmer6\": {\n \"state\": parseInt(global.get(\"dimmer5\")),\n \"name\":global.get(\"Ndimmer5\"),\n },\n \"dimmer7\": {\n \"state\": parseInt(global.get(\"dimmer6\")),\n \"name\": global.get(\"Ndimmer6\"),\n }\n }\n}\nelse if (global.get(targetdimmerno)!==undefined) {\n msg.payload = {\n \"dimmer\":msg.req.params.input,\n \"state\": parseInt(global.get(targetdimmerno)),\n \"name\":global.get(\"N\"+targetdimmerno)\n };\n}\nelse {\n msg.payload = \"dimmer \" + msg.req.params.input + \" does not exist\"\n}\nmsg.targetdimmerno = targetdimmerno\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":420,"y":2000,"wires":[["f684785ea126e942"]]},{"id":"93928c757eed6cfd","type":"http in","z":"e78e73d3.53155","name":"","url":"dimmer/","method":"get","upload":false,"swaggerDoc":"","x":110,"y":2040,"wires":[["cca88e865aa363ef"]]},{"id":"cca88e865aa363ef","type":"change","z":"e78e73d3.53155","name":"","rules":[{"t":"set","p":"req.params.input","pt":"msg","to":"all","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":2040,"wires":[["7fe809b2f568b3ee"]]},{"id":"d0b5af1299c04c81","type":"comment","z":"e78e73d3.53155","name":"endpoints dimmers","info":"","x":130,"y":1860,"wires":[]},{"id":"2f5ffaba89fd012e","type":"http in","z":"e78e73d3.53155","name":"","url":"wrelay/:input/:value","method":"put","upload":false,"swaggerDoc":"","x":150,"y":1580,"wires":[["766532c5bcc4ca2d"]]},{"id":"766532c5bcc4ca2d","type":"function","z":"e78e73d3.53155","name":"check input and switch state","func":"function number2words(n){\n if (n < 20) return num[n];\n var digit = n%10;\n return number2words(~~(n/1000)) + \" thousand\" + (n%1000 != 0? \" \" + number2words(n%1000): \"\");\n}\n\nif (isNaN(parseInt(msg.req.params.input)) == false){\n var num = \"zero one two three four five six seven eight nine ten\".split(\" \");\n msg.req.params.input = parseInt(msg.req.params.input)\n msg.req.params.input = number2words(msg.req.params.input)\n}\n\nmsg.relay = \"W\"+msg.req.params.input;\n\nif (msg.req.params.value === \"true\") {\n msg.payload = true\n msg.relaystate = msg.payload\n return [msg, msg];\n}\nelse if (msg.req.params.value === \"false\") {\n msg.payload = false\n msg.relaystate = msg.payload\n return [msg, msg];\n}\nelse {\n msg.payload = \"value can only be true or false\"\n return [null, msg];\n}","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":420,"y":1580,"wires":[["5d26899bef877b6f"],["56e1abb5b2e7247e"]]},{"id":"4ce25de51b4fb126","type":"http in","z":"e78e73d3.53155","name":"","url":"names/:input/:value","method":"put","upload":false,"swaggerDoc":"","x":150,"y":320,"wires":[["8baf068e4ca359dc"]]},{"id":"8baf068e4ca359dc","type":"function","z":"e78e73d3.53155","name":"check input and set name","func":"if (msg.req.params.input == \"level\") {\n msg.req.params.input = \"Level\"\n}\n\nmsg.globalVar = \"N\"+msg.req.params.input;\n\nif (global.get(msg.globalVar)!==undefined) {\n global.set(msg.globalVar, msg.req.params.value)\n\n msg.payload = {\n \"description\":msg.globalVar,\n \"name\":global.get(msg.globalVar)\n }\n //answer http request\n node.send([msg, null])\n //set payload for textfield in dashboard\n msg.payload = global.get(msg.globalVar)\n return [null, msg]\n}\nelse {\n msg.payload = \"global variable \" + msg.req.params.input + \" is not defined\";\n return [msg, null]\n}","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":450,"y":320,"wires":[["e9be18c319bccfd1"],["34ed1bb765acddd3"]]},{"id":"961a8b6d41509271","type":"link out","z":"e78e73d3.53155","name":"http update names","links":["32ccfc50.e148f4","3f4ef597.ad8bba","478c01f0.b35c1","7e47707c.5fe7b"],"x":635,"y":240,"wires":[]},{"id":"6a2642e3f0b97b0e","type":"comment","z":"e78e73d3.53155","name":"endpoints heater","info":"","x":120,"y":2140,"wires":[]},{"id":"aadd4382540212d4","type":"http in","z":"e78e73d3.53155","name":"","url":"heater/:truefalse","method":"put","upload":false,"swaggerDoc":"","x":140,"y":2180,"wires":[["f485bcc1320b9dc1"]]},{"id":"29f59ca8fbe82d23","type":"http response","z":"e78e73d3.53155","name":"send answer","statusCode":"200","headers":{},"x":1050,"y":2220,"wires":[]},{"id":"8cc4bb4336555b86","type":"http in","z":"e78e73d3.53155","name":"","url":"heater/:truefalse/:temp","method":"put","upload":false,"swaggerDoc":"","x":160,"y":2300,"wires":[["e5286c54434be8bb"]]},{"id":"ce11f3c7edd3025d","type":"http in","z":"e78e73d3.53155","name":"","url":"heater/:truefalse/:temp/:time","method":"put","upload":false,"swaggerDoc":"","x":170,"y":2460,"wires":[["97686d9a1e813337"]]},{"id":"f97d3e1199c2bd50","type":"http response","z":"e78e73d3.53155","name":"send answer","statusCode":"200","headers":{},"x":1050,"y":2460,"wires":[]},{"id":"9218ac0d4df78330","type":"link out","z":"e78e73d3.53155","name":"http heater on","links":["eb1e92403a6a4490"],"x":995,"y":2140,"wires":[]},{"id":"25bbb2b2adaf0cf8","type":"link out","z":"e78e73d3.53155","name":"http heater off","links":["8114989ad3d836db"],"x":995,"y":2180,"wires":[]},{"id":"f485bcc1320b9dc1","type":"function","z":"e78e73d3.53155","name":"set heater settings","func":"if (msg.req.params.truefalse == \"true\") {\n msg.payload = \"heater \" + msg.req.params.truefalse\n node.send([msg, null, null])\n}\nelse if (msg.req.params.truefalse == \"false\") {\n msg.payload = \"heater \" + msg.req.params.truefalse\n node.send([null, msg, null])\n}\nelse {\n msg.payload = \"heater can only be true or false\"\n}\nreturn [null, null, msg]","outputs":3,"noerr":0,"initialize":"","finalize":"","libs":[],"x":510,"y":2180,"wires":[["9218ac0d4df78330"],["25bbb2b2adaf0cf8","c46d7b1dcb708251"],["29f59ca8fbe82d23","c46d7b1dcb708251"]]},{"id":"e5286c54434be8bb","type":"function","z":"e78e73d3.53155","name":"set heater settings w/ temp","func":"msg.req.params.temp = parseInt(msg.req.params.temp)\n\nif (msg.req.params.truefalse == \"true\") {\n if (isNaN(msg.req.params.temp) == false) {\n if (msg.req.params.temp < 2 || msg.req.params.temp > 35) {\n msg.payload = \"temp value must be within 2 and 35\"\n }\n else {\n msg.payload = parseInt(msg.req.params.temp)\n node.send([msg, null, null])\n msg.payload = \"heater \" + msg.req.params.truefalse + \" with target temperature \" + msg.req.params.temp \n }\n }\n else if (isNaN(msg.req.params.temp) == true) {\n msg.payload = \"temp value must be numeric and between 12 and 35\"\n }\n}\nelse if (msg.req.params.truefalse == \"false\") {\n msg.payload = \"heater \" + msg.req.params.truefalse\n node.send([null, msg, null])\n}\nelse {\n msg.payload = \"heater can only be true or false\"\n}\nreturn [null, null, msg]","outputs":3,"noerr":0,"initialize":"","finalize":"","libs":[],"x":480,"y":2300,"wires":[["026555e3ad71e0cf"],["5776c022733c4136","c46d7b1dcb708251"],["5697815ee2579fe5","c46d7b1dcb708251"]]},{"id":"026555e3ad71e0cf","type":"link out","z":"e78e73d3.53155","name":"http heater on w/ temp","mode":"link","links":["788088e08e7292d0","eb1e92403a6a4490"],"x":995,"y":2260,"wires":[]},{"id":"5697815ee2579fe5","type":"http response","z":"e78e73d3.53155","name":"send answer","statusCode":"200","headers":{},"x":1050,"y":2340,"wires":[]},{"id":"5776c022733c4136","type":"link out","z":"e78e73d3.53155","name":"http heater off","mode":"link","links":["8114989ad3d836db"],"x":995,"y":2300,"wires":[]},{"id":"97686d9a1e813337","type":"function","z":"e78e73d3.53155","name":"set heater settings w/ temp & timer","func":"msg.req.params.temp = parseInt(msg.req.params.temp)\nmsg.req.params.time = parseInt(msg.req.params.time)\n\nif (msg.req.params.truefalse == \"true\") {\n if (isNaN(msg.req.params.temp) == false) {\n if (msg.req.params.temp < 2 || msg.req.params.temp > 35) {\n msg.payload = \"temp value must be within 2 and 35\"\n }\n else {\n if (isNaN(msg.req.params.time) == false) {\n if (msg.req.params.time < 0 || msg.req.params.time > 600) {\n msg.payload = \"time value must be within 0 and 600\"\n }\n else {\n node.send([null, null, null, null, msg, null])\n if (msg.req.params.time == 0 || msg.req.params.time == 0.0) {\n msg.payload = msg.req.params.time\n node.send([null, null, null, null, null, msg])\n msg.payload = parseInt(msg.req.params.temp)\n node.send([msg, null, null, null, null, null])\n msg.payload = \"heater \" + msg.req.params.truefalse + \" with target temperature \" + msg.req.params.temp + \"°C, timer reset\"\n return[null, null, msg, null, null, null]\n }\n msg.timer = msg.req.params.time\n msg.delay = msg.timer*60000\n msg.payload = msg.req.params.time\n node.send([null, null, null, msg, null, msg])\n msg.payload = parseInt(msg.req.params.temp)\n node.send([msg, null, null, null, null, null])\n msg.payload = \"heater \" + msg.req.params.truefalse + \" with target temperature \" + msg.req.params.temp + \"°C and duration \" + msg.req.params.time + \"m\"\n }\n }\n }\n }\n else if (isNaN(msg.req.params.temp) == true) {\n msg.payload = \"temp value must be numeric and between 2 and 35\"\n }\n}\nelse if (msg.req.params.truefalse == \"false\") {\n msg.payload = \"heater \" + msg.req.params.truefalse\n node.send([null, msg, null, null, msg, null])\n}\nelse {\n msg.payload = \"heater can only be true or false\"\n}\nreturn [null, null, msg, null, null, null]","outputs":6,"noerr":0,"initialize":"","finalize":"","libs":[],"x":500,"y":2460,"wires":[["e342e6035235dcf4"],["8d54b616c7e8feb5"],["f97d3e1199c2bd50"],["cf0e7d919697d7f9"],["c46d7b1dcb708251"],["8976e469b15db9cc"]]},{"id":"de9391849ee092b5","type":"delay","z":"e78e73d3.53155","name":"","pauseType":"delayv","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":1040,"y":2500,"wires":[["9fb866bf4390d8d3"]]},{"id":"e342e6035235dcf4","type":"link out","z":"e78e73d3.53155","name":"http heater on w/ temp","mode":"link","links":["788088e08e7292d0","eb1e92403a6a4490"],"x":995,"y":2380,"wires":[]},{"id":"8d54b616c7e8feb5","type":"link out","z":"e78e73d3.53155","name":"http heater off","links":["8114989ad3d836db"],"x":995,"y":2420,"wires":[]},{"id":"c46d7b1dcb708251","type":"change","z":"e78e73d3.53155","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":840,"y":2540,"wires":[["de9391849ee092b5"]]},{"id":"cf0e7d919697d7f9","type":"delay","z":"e78e73d3.53155","name":"","pauseType":"delay","timeout":"200","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":860,"y":2500,"wires":[["de9391849ee092b5"]]},{"id":"9fb866bf4390d8d3","type":"link out","z":"e78e73d3.53155","name":"http heater off","links":["8114989ad3d836db"],"x":1135,"y":2500,"wires":[]},{"id":"13b5cefbcd42f35a","type":"comment","z":"e78e73d3.53155","name":"API timer is not visible in dashboard!","info":"","x":180,"y":2400,"wires":[]},{"id":"4bdada802e6896da","type":"http in","z":"e78e73d3.53155","name":"","url":"names/:device/:input/:value","method":"put","upload":false,"swaggerDoc":"","x":170,"y":360,"wires":[["8527f2998f5d4380"]]},{"id":"8527f2998f5d4380","type":"function","z":"e78e73d3.53155","name":"check input and set name","func":"function text2numD(s) {\n a = s.toString().split(/[\\s-]+/);\n n = 0;\n g = 0;\n a.forEach(feachD);\n return n + g;\n}\nfunction text2numT(s) {\n a = s.toString().split(/[\\s-]+/);\n n = 0;\n g = 0;\n a.forEach(feachT);\n return n + g;\n}\n\nfunction feachD(w) {\n var x = inputDimmer[w];\n g = g + x;\n}\nfunction feachT(w) {\n var x = inputOther[w];\n g = g + x;\n}\n\nfunction number2words(n){\n if (n < 20) return num[n];\n var digit = n%10;\n return number2words(~~(n/1000)) + \" thousand\" + (n%1000 != 0? \" \" + number2words(n%1000): \"\");\n}\n\nvar inputDimmer = {'one': 0, 'two': 1, 'three': 2, 'four': 3, 'five': 4, 'six': 5, 'seven': 6, 'eight': 7};\nvar inputOther = {'one': 1, 'two': 2, 'three': 3, 'four': 4, 'five': 5, 'six': 6, 'seven': 7, 'eight': 8, 'nine': 9, 'ten': 10};\nvar targetdevice;\nvar num;\nmsg.targetdevice = \"\"\nmsg.globalVar = \"\"\n\n//--------------------------------------------------------------\n//only use lower case letters when accessing API!\n\nif (msg.req.params.device == \"level\") {\n msg.req.params.device = \"Level\"\n}\nif (msg.req.params.device == \"Wrelay\") {\n msg.req.params.device = \"wrelay\"\n}\n\nif (msg.req.params.device == \"Level\" || msg.req.params.device == \"temp\" || msg.req.params.device == \"relay\" || msg.req.params.device == \"wrelay\" || msg.req.params.device == \"dimmer\") {\n \n \n //check if device is \"dimmer\"\n if (msg.req.params.device == \"dimmer\") {\n if (isNaN(parseInt(msg.req.params.input)) == false) {\n num = \"one two three four five six seven eight\".split(\" \");\n if (parseInt(msg.req.params.input) < 9 && parseInt(msg.req.params.input) > 0) {\n msg.req.params.input = parseInt(msg.req.params.input)-1\n targetdevice = \"Ndimmer\"+msg.req.params.input.toString()\n msg.req.params.input = parseInt(msg.req.params.input)+1\n msg.dimmer = number2words(parseInt(msg.req.params.input));\n }\n else {\n msg.payload = \"dimmer \" + msg.req.params.input + \" does not exist\"\n return [msg, null];\n }\n }\n else if (isNaN(parseInt(msg.req.params.input)) == true){\n targetdevice = text2numD(msg.req.params.input);\n targetdevice = \"Ndimmer\"+targetdevice.toString()\n msg.dimmer = msg.req.params.input;\n //msg.newValue = parseInt(msg.req.params.value);\n }\n }\n \n //check if device is \"temp\" or \"level\"\n if (msg.req.params.device == \"temp\" || msg.req.params.device == \"Level\") {\n if (isNaN(parseInt(msg.req.params.input)) == false) {\n num = \"one two three four\".split(\" \");\n if (parseInt(msg.req.params.input) < 5 && parseInt(msg.req.params.input) > 0) {\n targetdevice = \"N\"+msg.req.params.device+msg.req.params.input.toString()\n msg.temporlevel = number2words(parseInt(msg.req.params.input));\n }\n else {\n msg.payload = msg.req.params.device+ \" \" + msg.req.params.input + \" does not exist\"\n return [msg, null];\n }\n }\n else if (isNaN(parseInt(msg.req.params.input)) == true){\n targetdevice = text2numT(msg.req.params.input);\n targetdevice = \"N\"+msg.req.params.device+targetdevice.toString()\n msg.temporlevel = msg.req.params.input;\n //msg.newValue = parseInt(msg.req.params.value);\n }\n }\n // else (if device is \"relay\" or \"Wrelay\")\n else {\n if (isNaN(parseInt(msg.req.params.input)) == false){\n num = \"zero one two three four five six seven eight nine ten\".split(\" \");\n msg.req.params.input = parseInt(msg.req.params.input)\n msg.req.params.input = number2words(msg.req.params.input)\n if (msg.req.params.device === \"wrelay\") {\n targetdevice = \"NW\" + msg.req.params.input\n }\n else if (msg.req.params.device === \"relay\") {\n targetdevice = \"N\" + msg.req.params.input\n }\n }\n else if (isNaN(parseInt(msg.req.params.input)) == true){\n if (msg.req.params.device === \"wrelay\") {\n targetdevice = \"NW\" + msg.req.params.input\n }\n else if (msg.req.params.device === \"relay\") {\n targetdevice = \"N\" + msg.req.params.input\n }\n }\n }\n \n//--------------------------------------------------------------\n \n msg.globalVar = targetdevice\n \n if (global.get(msg.globalVar)!= undefined) {\n global.set(msg.globalVar, msg.req.params.value)\n \n msg.payload = {\n \"description\":msg.globalVar,\n \"name\":global.get(msg.globalVar)\n }\n //answer http request\n node.send([msg, null])\n //set payload for textfield in dashboard\n msg.payload = global.get(msg.globalVar)\n return [null, msg]\n }\n else {\n msg.payload = \"global variable \" + msg.req.params.input + \" is not defined for \" + msg.req.params.device;\n return [msg, null]\n }\n}\nelse {\n msg.payload = \"device can only be 'temp', 'level', 'relay', 'wrelay' or 'dimmer'\"\n return [msg, null]\n}","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":450,"y":360,"wires":[["e9be18c319bccfd1"],["34ed1bb765acddd3"]]},{"id":"dfe6ac35b535e163","type":"http in","z":"e78e73d3.53155","name":"","url":"bms","method":"get","upload":false,"swaggerDoc":"","x":100,"y":640,"wires":[["235bf538c950ef47"]]},{"id":"235bf538c950ef47","type":"function","z":"e78e73d3.53155","name":"get battery stats","func":"let bmsjson = {\n \"BMSamps\":global.get(\"BMSamps\"),\n \"BMScap\":global.get(\"BMScap\"),\n \"BMScell1\":(global.get(\"BMScell1\")/1000).toFixed(2),\n \"BMScell2\":(global.get(\"BMScell2\")/1000).toFixed(2),\n \"BMScell3\":(global.get(\"BMScell3\")/1000).toFixed(2),\n \"BMScell4\":(global.get(\"BMScell4\")/1000).toFixed(2),\n \"BMSmaxcap\":global.get(\"BMSmaxcap\"),\n \"BMSmaxvolt\":global.get(\"BMSmaxvolt\"),\n \"BMSminvolt\":global.get(\"BMSminvolt\"),\n \"BMSpower\":global.get(\"BMSpower\"),\n \"BMSsoc\":global.get(\"BMSsoc\"),\n \"BMStemp\":global.get(\"BMStemp\"),\n \"BMSvolt\":global.get(\"BMSvolt\"),\n} ; \n msg.payload = bmsjson;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":280,"y":640,"wires":[["15a044e2c38d465e"]]},{"id":"15a044e2c38d465e","type":"http response","z":"e78e73d3.53155","name":"send answer","statusCode":"200","headers":{},"x":450,"y":640,"wires":[]},{"id":"fd04752f42acafc2","type":"http in","z":"e78e73d3.53155","name":"","url":"conniot","method":"get","upload":false,"swaggerDoc":"","x":110,"y":680,"wires":[["b5fa3f5283a0028c"]]},{"id":"b5fa3f5283a0028c","type":"function","z":"e78e73d3.53155","name":"get connection","func":"let connectionjson = {\n \"connection\": {\n \"state\": true\n }\n\n}; \nmsg.payload = connectionjson;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":280,"y":680,"wires":[["23d691c5507e32d3"]]},{"id":"23d691c5507e32d3","type":"http response","z":"e78e73d3.53155","name":"send answer","statusCode":"200","headers":{},"x":450,"y":680,"wires":[]},{"id":"890d1f2042565f42","type":"http in","z":"e78e73d3.53155","name":"","url":"wrelayiot/","method":"get","upload":false,"swaggerDoc":"","x":120,"y":1800,"wires":[["e81813357c4b008d"]]},{"id":"636d5ddd84294f7f","type":"function","z":"e78e73d3.53155","name":"check input and get wrelay","func":"function number2words(n){\n if (n < 20) return num[n];\n var digit = n%10;\n return number2words(~~(n/1000)) + \" thousand\" + (n%1000 != 0? \" \" + number2words(n%1000): \"\");\n}\n\nvar globalVar = \"W\"+msg.req.params.input\n\nif (isNaN(parseInt(msg.req.params.input)) == false){\n var num = \"zero one two three four five six seven eight nine ten\".split(\" \");\n msg.req.params.input = parseInt(msg.req.params.input)\n msg.req.params.input = number2words(msg.req.params.input)\n globalVar = \"W\"+msg.req.params.input\n}\n\nif (msg.req.params.input==\"all\") {\n msg.payload = {\n \"WifiRelay1\": {\n \"state\":global.get(\"Wone\"), \n \"name\":global.get(\"NWone\"),\n },\n \"WifiRelay2\": {\n \"state\":global.get(\"Wtwo\"), \n \"name\":global.get(\"NWtwo\"),\n },\n \"WifiRelay3\": {\n \"state\":global.get(\"Wthree\"), \n \"name\":global.get(\"NWthree\"),\n },\n \"WifiRelay4\": {\n \"state\":global.get(\"Wfour\"), \n \"name\":global.get(\"NWfour\"),\n },\n \"WifiRelay5\": {\n \"state\":global.get(\"Wfive\"), \n \"name\":global.get(\"NWfive\"),\n },\n \"WifiRelay6\": {\n \"state\":global.get(\"Wsix\"), \n \"name\":global.get(\"NWsix\"),\n },\n \"WifiRelay7\": {\n \"state\":global.get(\"Wseven\"), \n \"name\":global.get(\"NWseven\"),\n },\n \"WifiRelay8\": {\n \"state\":global.get(\"Weight\"), \n \"name\":global.get(\"NWeight\"),\n }\n };\n}\n\nelse if (global.get(globalVar)!==undefined) {\n var n = \"NW\"+msg.req.params.input\n msg.payload = {\n \"wifirelay\":globalVar,\n \"state\":global.get(globalVar),\n \"name\":global.get(n),\n };\n}\nelse {\n msg.payload = \"wifirelay \" + msg.req.params.input + \" does not exist\"\n}\n \nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":620,"y":1800,"wires":[["a2c7311476d4c970"]]},{"id":"e81813357c4b008d","type":"change","z":"e78e73d3.53155","name":"","rules":[{"t":"set","p":"req.params.input","pt":"msg","to":"all","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":1800,"wires":[["636d5ddd84294f7f"]]},{"id":"ab37cf757e8ab171","type":"http in","z":"e78e73d3.53155","name":"","url":"wrelayiot/:input/:value","method":"put","upload":false,"swaggerDoc":"","x":150,"y":1620,"wires":[["766532c5bcc4ca2d"]]},{"id":"5f3b4ca1f4773780","type":"http response","z":"e78e73d3.53155","name":"send answer","statusCode":"200","headers":{},"x":450,"y":760,"wires":[]},{"id":"d02d07dd336ca10f","type":"function","z":"e78e73d3.53155","name":"reboot rpi","func":"let rebootjson = {\n \"reboot_rpi\": {\n \"state\": true\n }\n\n}; \nmsg.payload = rebootjson;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":260,"y":760,"wires":[["5f3b4ca1f4773780","033f10b03f32200b"]]},{"id":"4b522f61da35eaa9","type":"http in","z":"e78e73d3.53155","name":"","url":"reboot","method":"get","upload":false,"swaggerDoc":"","x":110,"y":760,"wires":[["d02d07dd336ca10f"]]},{"id":"0eb0f3ca8bced55d","type":"exec","z":"e78e73d3.53155","command":"sudo reboot","addpay":"","append":"","useSpawn":"false","timer":"","winHide":false,"oldrc":false,"name":"","x":590,"y":800,"wires":[[],[],[]]},{"id":"033f10b03f32200b","type":"delay","z":"e78e73d3.53155","name":"5s","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":430,"y":800,"wires":[["0eb0f3ca8bced55d"]]},{"id":"e0d0fb4aa408cd1e","type":"http in","z":"e78e73d3.53155","name":"","url":"relayiot/","method":"get","upload":false,"swaggerDoc":"","x":110,"y":1480,"wires":[["3cc12295a0acee87"]]},{"id":"3cc12295a0acee87","type":"change","z":"e78e73d3.53155","name":"","rules":[{"t":"set","p":"req.params.input","pt":"msg","to":"all","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":1480,"wires":[["55775742497477e5"]]},{"id":"55775742497477e5","type":"function","z":"e78e73d3.53155","name":"check input and get relay","func":"function number2words(n){\n if (n < 20) return num[n];\n var digit = n%10;\n return number2words(~~(n/1000)) + \" thousand\" + (n%1000 != 0? \" \" + number2words(n%1000): \"\");\n}\n\nvar globalVar = msg.req.params.input\n\nif (isNaN(parseInt(msg.req.params.input)) == false){\n var num = \"zero one two three four five six seven eight nine ten\".split(\" \");\n msg.req.params.input = parseInt(msg.req.params.input)\n msg.req.params.input = number2words(msg.req.params.input)\n globalVar = msg.req.params.input\n}\n\nif (msg.req.params.input==\"all\") {\n msg.payload = {\n \"Relay1\": {\n \"state\":global.get(\"one\"), \n \"name\":global.get(\"None\"),\n //\"autooff\": global.get(\"oneoffauto\")\n },\n \"Relay2\": {\n \"state\":global.get(\"two\"), \n \"name\":global.get(\"Ntwo\"),\n //\"autooff\": global.get(\"twooffauto\")\n },\n \"Relay3\": {\n \"state\":global.get(\"three\"), \n \"name\":global.get(\"Nthree\"),\n //\"autooff\": global.get(\"threeoffauto\")\n },\n \"Relay4\": {\n \"state\":global.get(\"four\"), \n \"name\":global.get(\"Nfour\"),\n //\"autooff\": global.get(\"fouroffauto\")\n },\n \"Relay5\": {\n \"state\":global.get(\"five\"), \n \"name\":global.get(\"Nfive\"),\n //\"autooff\": global.get(\"fiveoffauto\")\n },\n \"Relay6\": {\n \"state\":global.get(\"six\"), \n \"name\":global.get(\"Nsix\"),\n //\"autooff\": global.get(\"sixoffauto\")\n },\n \"Relay7\": {\n \"state\":global.get(\"seven\"), \n \"name\":global.get(\"Nseven\"),\n //\"autooff\": global.get(\"sevenoffauto\")\n },\n \"Relay8\": {\n \"state\":global.get(\"eight\"), \n \"name\":global.get(\"Neight\"),\n //\"autooff\": global.get(\"eightoffauto\")\n },\n \"Relay9\": {\n \"state\":global.get(\"nine\"), \n \"name\":global.get(\"Nnine\"),\n //\"autooff\": global.get(\"oneoffauto\")\n },\n \"Relay10\": {\n \"state\":global.get(\"ten\"), \n \"name\":global.get(\"Nten\"),\n //\"autooff\": global.get(\"oneoffauto\")\n }\n };\n}\nelse if (global.get(msg.req.params.input)!==undefined) {\n var n = \"N\"+msg.req.params.input\n var autooff = global.get(msg.req.params.input+\"offauto\")\n msg.payload = {\n \"relay\":msg.req.params.input,\n \"state\":global.get(msg.req.params.input),\n \"name\":global.get(n),\n //\"autooff\": autooff\n };\n}\nelse {\n msg.payload = \"relay \" + msg.req.params.input + \" does not exist\"\n}\n \nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":630,"y":1480,"wires":[["24ec5317eca5f0fb"]]},{"id":"a2480738462df03d","type":"http in","z":"e78e73d3.53155","name":"","url":"debug","method":"get","upload":false,"swaggerDoc":"","x":110,"y":720,"wires":[["a19d1bc659618942"]]},{"id":"a19d1bc659618942","type":"function","z":"e78e73d3.53155","name":"debug info","func":"msg.payload = {\n \"version\":global.get(\"currentVersion\"),\n \"wifiIP\":global.get(\"wifiIP\"),\n \"eth0IP\":global.get(\"eth0IP\"),\n \"BatteryDataDelivery\":global.get(\"BatteryDataDelivery\"),\n \"accesspoint\":global.get(\"accesspoint\"),\n \"pkwshuntactive\":global.get(\"pkwshuntactive\"),\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":270,"y":720,"wires":[["6f4b1984b6b545ed"]]},{"id":"6f4b1984b6b545ed","type":"http response","z":"e78e73d3.53155","name":"send answer","statusCode":"200","headers":{},"x":450,"y":720,"wires":[]},{"id":"d6896f1d6e9fe09d","type":"http in","z":"e78e73d3.53155","name":"","url":"/attime","method":"put","upload":false,"swaggerDoc":"","x":110,"y":3100,"wires":[["e60a32d21c8c4492"]]},{"id":"01a934bba9cede4c","type":"http response","z":"e78e73d3.53155","name":"http (200)","statusCode":"200","headers":{},"x":460,"y":3140,"wires":[]},{"id":"73015f47095b7f66","type":"split","z":"e78e73d3.53155","name":"","splt":"=","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":450,"y":3100,"wires":[["f3881285a5493a26"]]},{"id":"f3881285a5493a26","type":"split","z":"e78e73d3.53155","name":"","splt":"&","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":570,"y":3100,"wires":[["026b2fbf4f2571af"]]},{"id":"026b2fbf4f2571af","type":"change","z":"e78e73d3.53155","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"date","fromt":"str","to":"","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"time","fromt":"str","to":"","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"gmt","fromt":"str","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":730,"y":3100,"wires":[["a2d9b11cf030ea23"]]},{"id":"a2d9b11cf030ea23","type":"function","z":"e78e73d3.53155","name":"reformat","func":"if (msg.payload == \"\") {\n return null\n}\nif (msg.payload.includes(\"/\")) {\n msg.topic = \"date\"\n var year = msg.payload.substring(0,2)\n var month = msg.payload.substring(3,5)\n var day = msg.payload.substring(6,8)\n msg.payload = day + \".\" + month + \".\" + year\n}\nif (msg.payload.includes(\":\")) {\n msg.topic = \"time\"\n}\nif (msg.payload.includes(\"+\") || msg.payload.includes(\"-\")) {\n msg.topic = \"gmt\"\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":900,"y":3100,"wires":[["efcc9f88eab5bc52"]]},{"id":"efcc9f88eab5bc52","type":"join","z":"e78e73d3.53155","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"3","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"num","reduceFixup":"","x":1030,"y":3100,"wires":[["818b23cfc9267063"]]},{"id":"818b23cfc9267063","type":"function","z":"e78e73d3.53155","name":"set exec payload","func":"var year = \"20\"+msg.payload.date.substring(msg.payload.date.length-2)\nvar month = msg.payload.date.substring(3,5)\nvar day = msg.payload.date.substring(0,2)\n\nmsg.payload = \"sudo date -s '\" +year + \"-\" + month + \"-\" + day + \" \" + msg.payload.time +\"'\"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1190,"y":3100,"wires":[["60fdd0513d372a74"]]},{"id":"60fdd0513d372a74","type":"exec","z":"e78e73d3.53155","command":"","addpay":"payload","append":"","useSpawn":"false","timer":"","winHide":false,"oldrc":false,"name":"set date/time","x":1370,"y":3100,"wires":[[],[],[]]},{"id":"77d6cd751c9186e1","type":"comment","z":"e78e73d3.53155","name":"(click for instructions) Set system time (Turn off network time sync in frontend!)","info":"Format needs to be\n\nIP:PORT/attime?date=YY/MM/DD&time=hh:mm:ss&gmt=+04\n\nwith gmt being 15min steps, so range is -48 to +48\n\nHeaders are \"Content-Type: text/html; charset=utf-8\"","x":310,"y":3060,"wires":[]},{"id":"e60a32d21c8c4492","type":"function","z":"e78e73d3.53155","name":"check payload","func":"if (global.get(\"timesyncd\") == \"inactive\") {\n msg.payload = (msg.payload == \"\" ? msg.req.url : msg.payload)\n return [msg, null]\n}\nelse if (global.get(\"timesyncd\") == \"active\") {\n msg.payload = \"network timesync is active\"\n return [null, msg]\n}","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":280,"y":3100,"wires":[["73015f47095b7f66","01a934bba9cede4c"],["01a934bba9cede4c"]]},{"id":"542a2c9f0ca623ea","type":"http in","z":"e78e73d3.53155","name":"","url":"switchall/:truefalse","method":"put","upload":false,"swaggerDoc":"","x":140,"y":2840,"wires":[["616ae227b7d1006f","fcbb89cd0e972cfa"]]},{"id":"f50fd70f9c6826f3","type":"comment","z":"e78e73d3.53155","name":"endpoint toggle all on/off (relays, w-relays, dimmers)","info":"","x":230,"y":2800,"wires":[]},{"id":"a87e79fb235e68f4","type":"http response","z":"e78e73d3.53155","name":"send answer","statusCode":"200","headers":{},"x":550,"y":2900,"wires":[]},{"id":"616ae227b7d1006f","type":"function","z":"e78e73d3.53155","name":"check true or false","func":"if (msg.req.params.truefalse == \"false\") {\n return [msg, null]\n}\nelse if (msg.req.params.truefalse == \"true\") {\n return [null, msg]\n}\n","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":410,"y":2840,"wires":[["de95656a18aa0369"],["3ae13fe66c9c4fd2"]]},{"id":"fcbb89cd0e972cfa","type":"function","z":"e78e73d3.53155","name":"set answer","func":"if (msg.req.params.truefalse == \"false\") {\n msg.payload = {\n \"switchall\":\"false\"\n }\n}\nelse if (msg.req.params.truefalse == \"true\") {\n msg.payload = \"turning everything back on from memory is yet not implemented!\" \n}\n\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":390,"y":2900,"wires":[["a87e79fb235e68f4"]]},{"id":"3fe38c2d6edc0c84","type":"link out","z":"e78e73d3.53155","name":"http switchall relays/wrelays off","mode":"link","links":["1be6547089f6e149","1d05179e.1f1a78","2840c10.f61294","33a5d09e.6cc14","34f49f08e1a06032","38796905.f4b7f6","428f4d48.86eaf4","7255f9f4.6304d8","9f1c7c65c2da2d42","afbb8dda.ffe6c","c698c6e8.416b58","c9adec52.63ae6","d2ce5044.ef8af","d76c3b78c0f14e69","e9ffa3ef.cde5d","f14867fc.930ab8"],"x":1115,"y":2800,"wires":[]},{"id":"de95656a18aa0369","type":"function","z":"e78e73d3.53155","name":"set globals","func":"//save current global states\nmsg.payload = {\n \"one\": global.get(\"one\"),\n \"two\": global.get(\"two\"),\n \"three\": global.get(\"three\"),\n \"four\": global.get(\"four\"),\n \"five\": global.get(\"five\"),\n \"six\": global.get(\"six\"),\n \"seven\": global.get(\"seven\"),\n \"eight\": global.get(\"eight\"),\n \"Wone\": global.get(\"Wone\"),\n \"Wtwo\": global.get(\"Wtwo\"),\n \"Wthree\": global.get(\"Wthree\"),\n \"Wfour\": global.get(\"Wfour\"),\n \"Wfive\": global.get(\"Wfive\"),\n \"Wsix\": global.get(\"Wsix\"),\n \"Wseven\": global.get(\"Wseven\"),\n \"Weight\": global.get(\"Weight\"),\n \"dimmer0\": global.get(\"dimmer0\"),\n \"dimmer1\": global.get(\"dimmer1\"),\n \"dimmer2\": global.get(\"dimmer2\"),\n \"dimmer3\": global.get(\"dimmer3\"),\n \"dimmer4\": global.get(\"dimmer4\"),\n \"dimmer5\": global.get(\"dimmer5\"),\n \"dimmer6\": global.get(\"dimmer6\"),\n \"dimmer7\": global.get(\"dimmer7\")\n}\n\n//turn all globals off\nglobal.set(\"one\", false)\nglobal.set(\"two\", false)\nglobal.set(\"three\", false)\nglobal.set(\"four\", false)\nglobal.set(\"five\", false)\nglobal.set(\"six\", false)\nglobal.set(\"seven\", false)\nglobal.set(\"eight\", false)\nglobal.set(\"Wone\", false)\nglobal.set(\"Wtwo\", false)\nglobal.set(\"Wthree\", false)\nglobal.set(\"Wfour\", false)\nglobal.set(\"Wfive\", false)\nglobal.set(\"Wsix\", false)\nglobal.set(\"Wseven\", false)\nglobal.set(\"Weight\", false)\nglobal.set(\"dimmer0\", 0)\nglobal.set(\"dimmer1\", 0)\nglobal.set(\"dimmer2\", 0)\nglobal.set(\"dimmer3\", 0)\nglobal.set(\"dimmer4\", 0)\nglobal.set(\"dimmer5\", 0)\nglobal.set(\"dimmer6\", 0)\nglobal.set(\"dimmer7\", 0)\n \nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":630,"y":2820,"wires":[["8c191f1ddb4a9e61"]]},{"id":"8c191f1ddb4a9e61","type":"file","z":"e78e73d3.53155","name":"","filename":"pekaway/switchall","appendNewline":false,"createDir":true,"overwriteFile":"true","encoding":"none","x":830,"y":2820,"wires":[["d3f7d57b888ae358"]]},{"id":"3ae13fe66c9c4fd2","type":"file in","z":"e78e73d3.53155","name":"","filename":"pekaway/switchall","format":"utf8","chunk":false,"sendError":false,"encoding":"none","allProps":false,"x":650,"y":2860,"wires":[["fbb0856682157ebe"]]},{"id":"fbb0856682157ebe","type":"json","z":"e78e73d3.53155","name":"","property":"payload","action":"","pretty":false,"x":830,"y":2860,"wires":[["b29bf552eb93a13b"]]},{"id":"d3f7d57b888ae358","type":"function","z":"e78e73d3.53155","name":"turn off","func":"//turn off relays & w-relays\nmsg.payload = false\nnode.send([msg, null])\n//turn off dimmers\nvar dimmervalue = 0\nvar i = 1\nwhile (i < 9) {\n msg.url = \"http://127.0.0.1:1880/dimmer/\" + i +\"/\" + dimmervalue\n msg.payload = \"\"\n node.send([null, msg])\n i = i + 1\n}","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":990,"y":2820,"wires":[["3fe38c2d6edc0c84"],["d6c0637581ab0b06"]]},{"id":"d6c0637581ab0b06","type":"http request","z":"e78e73d3.53155","name":"dimmers off","method":"PUT","ret":"txt","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"x":1170,"y":2840,"wires":[[]]},{"id":"af04e125a02e7e81","type":"http in","z":"e78e73d3.53155","name":"","url":"info/","method":"get","upload":false,"swaggerDoc":"","x":100,"y":3000,"wires":[["3610a0e28dfa7021"]]},{"id":"3610a0e28dfa7021","type":"function","z":"e78e73d3.53155","name":"get variables","func":"msg.payload = {\n \"VanPi_Ctrl\": global.get(\"currentVersion\"),\n \"install_date\": global.get(\"installdate\"),\n \"current_date\": new Date().toLocaleString(),\n \"uptime\": global.get(\"uptime\").trim(),\n \"van_name\": global.get(\"van_name\"),\n \"cpu_temp\": global.get(\"rpi_cpu_temp\"),\n \"cpu_usage\": global.get(\"rpi_cpu_usage\"),\n \"ttgo\": global.get(\"ttgo\"),\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":290,"y":3000,"wires":[["c1249b3174e91f47"]]},{"id":"fd8dd0dde3d5c912","type":"comment","z":"e78e73d3.53155","name":"endpoint get some general information about the system","info":"","x":240,"y":2960,"wires":[]},{"id":"c1249b3174e91f47","type":"http response","z":"e78e73d3.53155","name":"send answer","statusCode":"200","headers":{},"x":470,"y":3000,"wires":[]},{"id":"6f7685fb79ce0438","type":"link out","z":"e78e73d3.53155","name":"Ndimmytemp1","mode":"link","links":["e5ec8a87df41929d"],"x":1015,"y":700,"wires":[]},{"id":"761da5923e187298","type":"link out","z":"e78e73d3.53155","name":"Ndimmytemp2","mode":"link","links":["e834be69d9ff260b"],"x":1015,"y":720,"wires":[]},{"id":"42e02e39624a5cb2","type":"http in","z":"e78e73d3.53155","name":"","url":"reset_wifi_ap/:input","method":"put","upload":false,"swaggerDoc":"","x":150,"y":900,"wires":[["6a5a6cd3aad7c7e9","328d22e9e47a30a2"]]},{"id":"328d22e9e47a30a2","type":"function","z":"e78e73d3.53155","name":"check input","func":"if (msg.req.params.input == \"true\") {\n let resetjson = {\n \"reset_wifiAP\": {\n \"state\": true\n }\n }; \n msg.payload = resetjson;\n return msg;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":350,"y":940,"wires":[["b110837e6b592954"]]},{"id":"d955441457ae8497","type":"http response","z":"e78e73d3.53155","name":"send answer","statusCode":"200","headers":{},"x":650,"y":900,"wires":[]},{"id":"8a6bd10dd566d096","type":"link out","z":"e78e73d3.53155","name":"reset wifiAP","mode":"link","links":["53610bbf2e35371a"],"x":745,"y":940,"wires":[]},{"id":"b110837e6b592954","type":"function","z":"e78e73d3.53155","name":"set payload OK","func":"msg.payload = \"OK\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":520,"y":940,"wires":[["8a6bd10dd566d096"]]},{"id":"6a5a6cd3aad7c7e9","type":"delay","z":"e78e73d3.53155","name":"3s","pauseType":"delay","timeout":"3","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":330,"y":900,"wires":[["cf9884f4e4493203"]]},{"id":"cf9884f4e4493203","type":"function","z":"e78e73d3.53155","name":"check input","func":"if (msg.req.params.input == \"true\") {\n let resetjson = {\n \"reset_wifiAP\": {\n \"state\": true,\n \"ssid\": global.get(\"ssid\").substring(5),\n \"wpa\": global.get(\"wpa\")\n }\n };\n msg.payload = resetjson;\n return msg;\n}\nelse {\n let resetjson = {\n \"reset_wifiAP\": {\n \"state\": false,\n \"error\": \"endpoint to hit needs parameter true ('<ip>:1880/reset_wifiAP/true')\"\n }\n };\n msg.payload = resetjson;\n return msg;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":470,"y":900,"wires":[["d955441457ae8497"]]},{"id":"c3e884d6b59ebf48","type":"http in","z":"e78e73d3.53155","name":"","url":"network","method":"get","upload":false,"swaggerDoc":"","x":110,"y":860,"wires":[["252b57b56a81916a"]]},{"id":"252b57b56a81916a","type":"exec","z":"e78e73d3.53155","command":"sudo ifconfig wlan0 | sed -En -e 's/.*inet ([0-9.]+).*/\\1/p'","addpay":false,"append":"","useSpawn":"false","timer":"","winHide":false,"oldrc":false,"name":"check ip wlan0","x":280,"y":860,"wires":[["68b73acc3c84685f"],[],[]]},{"id":"68b73acc3c84685f","type":"function","z":"e78e73d3.53155","name":"set payload","func":"msg.wlan0 = msg.payload\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":450,"y":860,"wires":[["138895d07b51385c"]]},{"id":"2d5f44fe81f2fc48","type":"exec","z":"e78e73d3.53155","command":"sudo ifconfig eth0 | sed -En -e 's/.*inet ([0-9.]+).*/\\1/p'","addpay":false,"append":"","useSpawn":"false","timer":"","winHide":false,"oldrc":false,"name":"check ip eth0","x":910,"y":860,"wires":[["ddd02c9281315ad3"],[],[]]},{"id":"ddd02c9281315ad3","type":"function","z":"e78e73d3.53155","name":"set payload","func":"msg.eth0 = msg.payload\n\nlet networkjson = {\n \"network\": {\n \"ap_state\": global.get(\"accesspoint\"),\n \"ap_ssid\": global.get(\"ssid\"),\n \"ap_wpa\": global.get(\"wpa\"),\n \"wlan0_ip\": msg.wlan0.trim(),\n \"connected to\": msg.ssid,\n \"eth0_ip\": msg.eth0.trim()\n }\n};\nmsg.payload = networkjson;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1070,"y":860,"wires":[["5adccb99ea240bab"]]},{"id":"138895d07b51385c","type":"exec","z":"e78e73d3.53155","command":"iwgetid | cut -d \":\" -f2-","addpay":"","append":"","useSpawn":"false","timer":"","winHide":false,"oldrc":false,"name":"get SSID","x":600,"y":860,"wires":[["007593b8fcfe63cb"],[],[]]},{"id":"007593b8fcfe63cb","type":"function","z":"e78e73d3.53155","name":"set payload","func":"if (msg.payload != \"\") {\n msg.ssid = msg.payload.trim()\n}\nelse {\n msg.ssid = \"\"\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":750,"y":860,"wires":[["2d5f44fe81f2fc48"]]},{"id":"5adccb99ea240bab","type":"http response","z":"e78e73d3.53155","name":"send answer","statusCode":"200","headers":{},"x":1230,"y":860,"wires":[]},{"id":"3c9c6cc3bf6fee8e","type":"comment","z":"e78e73d3.53155","name":"endpoints network","info":"","x":130,"y":820,"wires":[]},{"id":"049e2d2e9ab3c402","type":"http in","z":"e78e73d3.53155","name":"","url":"update_wifi_ap/:ssid/:wpa","method":"put","upload":false,"swaggerDoc":"","x":170,"y":980,"wires":[["c30a5229b4c47747"]]},{"id":"c30a5229b4c47747","type":"function","z":"e78e73d3.53155","name":"check input","func":"let ssid = msg.req.params.ssid + \"_pekaway.com\"\nlet wpa = msg.req.params.wpa\nlet wifiAPjson = {}\n \nif (wpa.length < 8 || wpa.length > 63) {\n wifiAPjson = {\n \"wifiAP\": {\n \"updated\": false,\n \"ssid\": ssid,\n \"wpa\": wpa,\n \"error\":\"Passphrase needs to be between 8 and 63 characters long!\"\n }\n }\n msg.payload = wifiAPjson\n return [msg, null]\n}\n\nelse {\n wifiAPjson = {\n \"wifiAP\": {\n \"updated\": true,\n \"ssid\": ssid,\n \"wpa\": wpa,\n \"reboot\": true\n }\n }\n global.set(\"wpa\", wpa)\n global.set(\"ssid\", ssid)\n msg.payload = wifiAPjson\n\n return [null, msg]\n}","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":410,"y":980,"wires":[["b1ee1c2b5aabc9dd"],["b1ee1c2b5aabc9dd","349299c7e8f20aec"]]},{"id":"b1ee1c2b5aabc9dd","type":"http response","z":"e78e73d3.53155","name":"send answer","statusCode":"200","headers":{},"x":610,"y":980,"wires":[]},{"id":"3568302164bf5c67","type":"link out","z":"e78e73d3.53155","name":"update wifiAP","mode":"link","links":["4db059e1118648d3"],"x":745,"y":1020,"wires":[]},{"id":"349299c7e8f20aec","type":"function","z":"e78e73d3.53155","name":"set payload OK","func":"msg = {\n \"payload\": \"OK\",\n \"ssid\": global.get(\"ssid\"),\n \"wpa\": global.get(\"wpa\")\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":620,"y":1020,"wires":[["3568302164bf5c67"]]},{"id":"badd957725934738","type":"http in","z":"e78e73d3.53155","name":"","url":"activate_wifi_ap/:input","method":"put","upload":false,"swaggerDoc":"","x":160,"y":1080,"wires":[["127692c2434841af"]]},{"id":"127692c2434841af","type":"function","z":"e78e73d3.53155","name":"check input","func":"let input = msg.req.params.input\nmsg.input = input,\nmsg.ap_state_old = global.get(\"accesspoint\")\nnode.send([msg, null, null])\n\nif (input == \"true\") {\n msg.payload = \"Ok!\"\n return [null, msg, null]\n}\nelse if (input == \"false\") {\n msg.payload = \"Ok!\"\n return [null, null, msg]\n}","outputs":3,"noerr":0,"initialize":"","finalize":"","libs":[],"x":410,"y":1080,"wires":[["a45f20d3a8342422"],["284f7d986075218f"],["4251953a5d2e02b9"]]},{"id":"284f7d986075218f","type":"link out","z":"e78e73d3.53155","name":"switch to access point","mode":"link","links":["f466a3bb3fc1964f"],"x":635,"y":1100,"wires":[]},{"id":"4251953a5d2e02b9","type":"link out","z":"e78e73d3.53155","name":"turn off access point","mode":"link","links":["ac75384ae361d2e5"],"x":635,"y":1140,"wires":[]},{"id":"18e6f26f455ccfec","type":"http response","z":"e78e73d3.53155","name":"send answer","statusCode":"200","headers":{},"x":890,"y":1060,"wires":[]},{"id":"ffe2c321ba6998f1","type":"function","z":"e78e73d3.53155","name":"set answer","func":"msg.payload.ap_state_new = global.get(\"accesspoint\")\nlet ap_state_old = msg.ap_state_old\nlet input = msg.input;\nlet reboot\n\nif (input == \"false\" ||input == false) {\n reboot = \"false\"\n msg.payload = {\n \"input\": input,\n \"ap_state_old\": ap_state_old,\n \"ap_state_new\": global.get(\"accesspoint\"),\n \"reboot\": reboot\n }\n}\nelse if (input == \"true\" || input == true) {\n reboot = true\n msg.payload = {\n \"input\": input,\n \"ap_state_old\": ap_state_old,\n \"ap_state_new\": global.get(\"accesspoint\"),\n \"reboot\": reboot\n }\n}\n\nelse {\n msg.payload = {\n \"input\": input,\n \"error\": \"input can only be 'true' or 'false'\"\n }\n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":690,"y":1060,"wires":[["18e6f26f455ccfec"]]},{"id":"a45f20d3a8342422","type":"delay","z":"e78e73d3.53155","name":"0.5s","pauseType":"delay","timeout":"0.5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":550,"y":1060,"wires":[["ffe2c321ba6998f1"]]},{"id":"18248bd261f66d64","type":"http in","z":"e78e73d3.53155","name":"","url":"autoterm/:ventilation_heatingpower/:value","method":"put","upload":false,"swaggerDoc":"","x":220,"y":2620,"wires":[["2848c586d7fef769"]]},{"id":"f9d7671cd7a7eb65","type":"comment","z":"e78e73d3.53155","name":"endpoint autoterm specific (ventilation, heatingpower) (EXPERIMENTAL)","info":"","x":300,"y":2580,"wires":[]},{"id":"2848c586d7fef769","type":"function","z":"e78e73d3.53155","name":"set heater settings w/ temp","func":"msg.req.params.value = parseInt(msg.req.params.value)\n\nif (msg.req.params.ventilation_heatingpower == \"ventilation\") {\n if (isNaN(msg.req.params.value) == false) {\n if (msg.req.params.temp < 11 || msg.req.params.temp >= 0) {\n msg.payload = \"ventilation value must be within 0 and 10\"\n }\n else {\n msg.payload = parseInt(msg.req.params.value)\n node.send([msg, null, null])\n msg.payload = \"autoterm \" + msg.req.params.ventilation_heatingpower + \" with target value \" + msg.req.params.value \n }\n }\n else if (isNaN(msg.req.params.temp) == true) {\n msg.payload = \"ventilation value must be numeric and between 0 and 10\"\n }\n}\nelse if (msg.req.params.ventilation_heatingpower == \"heatingpower\") {\n if (isNaN(msg.req.params.value) == false) {\n if (msg.req.params.temp < 11 || msg.req.params.temp >= 0) {\n msg.payload = \"heatingpower value must be within 0 and 10\"\n }\n else {\n msg.payload = parseInt(msg.req.params.value)\n node.send([msg, null, null])\n msg.payload = \"autoterm \" + msg.req.params.ventilation_heatingpower + \" with target value \" + msg.req.params.value\n }\n }\n else if (isNaN(msg.req.params.temp) == true) {\n msg.payload = \"heatingpower value must be numeric and between 0 and 10\"\n }\n}\n\nelse {\n msg.payload = \"autoterm specific commands can only be 'ventilation' or 'heatingpower'\"\n}\nreturn [null, null, msg]","outputs":3,"noerr":0,"initialize":"","finalize":"","libs":[],"x":680,"y":2620,"wires":[["5be81bd5b43f94d0"],["572f63b680e321fc"],["9b9f0894ba084cdf"]]},{"id":"9b9f0894ba084cdf","type":"http response","z":"e78e73d3.53155","name":"send answer","statusCode":"200","headers":{},"x":1039,"y":2658,"wires":[]},{"id":"5be81bd5b43f94d0","type":"link out","z":"e78e73d3.53155","name":"http autoterm ventilation","mode":"link","links":["f9d784ab7f323cf6"],"x":985,"y":2580,"wires":[]},{"id":"572f63b680e321fc","type":"link out","z":"e78e73d3.53155","name":"http autoterm heatingpower","mode":"link","links":["e6f5d17b430ade7b"],"x":985,"y":2620,"wires":[]},{"id":"8976e469b15db9cc","type":"link out","z":"e78e73d3.53155","name":"http heater on w/ temp for runtime","mode":"link","links":["093319b1a513fb43"],"x":775,"y":2580,"wires":[]},{"id":"be4eb9d57f984b56","type":"http in","z":"e78e73d3.53155","name":"","url":"gps","method":"get","upload":false,"swaggerDoc":"","x":100,"y":3240,"wires":[["d7ba0acc80ad79e7"]]},{"id":"d7ba0acc80ad79e7","type":"function","z":"e78e73d3.53155","name":"get variables","func":"msg.payload = {\n \"lat\": parseFloat(global.get(\"latitude\")),\n \"lon\": parseFloat(global.get(\"longitude\")),\n \"date\": global.get(\"gps_updated\") || \"\",\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":290,"y":3240,"wires":[["0c08bcc5d5494f65"]]},{"id":"07ea2b2a8b03c5ac","type":"comment","z":"e78e73d3.53155","name":"endpoint gps position","info":"","x":140,"y":3200,"wires":[]},{"id":"0c08bcc5d5494f65","type":"http response","z":"e78e73d3.53155","name":"send answer","statusCode":"200","headers":{},"x":470,"y":3240,"wires":[]},{"id":"866cbbd5709bd9dc","type":"inject","z":"e78e73d3.53155","name":"Halle","props":[{"p":"lat","v":"51.483334","vt":"num"},{"p":"topic","vt":"str"},{"p":"lon","v":"11.966667","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":990,"y":3520,"wires":[["23e278c7fc4c6dfe"]]},{"id":"23e278c7fc4c6dfe","type":"function","z":"e78e73d3.53155","name":"gps pos test","func":"let date = new Date()\nglobal.set(\"gps_updated\", date)\nglobal.set(\"latitude\", msg.lat)\nglobal.set(\"longitude\", msg.lon)\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1310,"y":3520,"wires":[["9ba48d39cbfd747d"]]},{"id":"47fd747da834db6b","type":"inject","z":"e78e73d3.53155","name":"Rostock","props":[{"p":"lat","v":"54.146520","vt":"num"},{"p":"topic","vt":"str"},{"p":"lon","v":"12.134871","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":"60","topic":"","x":1000,"y":3560,"wires":[["23e278c7fc4c6dfe"]]},{"id":"3063741daa56f462","type":"inject","z":"e78e73d3.53155","name":"Malaga","props":[{"p":"lat","v":"36.703500","vt":"num"},{"p":"topic","vt":"str"},{"p":"lon","v":"-4.439922","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":"120","topic":"","x":990,"y":3600,"wires":[["23e278c7fc4c6dfe"]]},{"id":"9ba48d39cbfd747d","type":"debug","z":"e78e73d3.53155","name":"debug 73","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1520,"y":3520,"wires":[]},{"id":"fea43e57ef1419d6","type":"inject","z":"e78e73d3.53155","name":"Griechenland","props":[{"p":"lat","v":"37.489407","vt":"num"},{"p":"topic","vt":"str"},{"p":"lon","v":"22.380565","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":"180","topic":"","x":1010,"y":3640,"wires":[["23e278c7fc4c6dfe"]]},{"id":"d885ec0c2280eac3","type":"inject","z":"e78e73d3.53155","name":"Kuala Lumpur","props":[{"p":"lat","v":"3.145933","vt":"num"},{"p":"topic","vt":"str"},{"p":"lon","v":"101.700522","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":"240","topic":"","x":1010,"y":3680,"wires":[["23e278c7fc4c6dfe"]]},{"id":"349412d68089639d","type":"inject","z":"e78e73d3.53155","d":true,"name":"random lat/lon","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"60","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":1020,"y":3480,"wires":[["8a02b8332fd301f4"]]},{"id":"8a02b8332fd301f4","type":"function","z":"e78e73d3.53155","name":"function 4","func":"let date = new Date()\nglobal.set(\"gps_updated\", date) // needed for smartphone app!\n\nlet lat = Math.round((Math.random() * 10+ 44) * 1000000) / 1000000\nlet lon = Math.round((Math.random() * 15 + 1) * 1000000) / 1000000\n\n//set lat&lon to the global variables to make them accessable through the HTTP API\nglobal.set(\"latitude\", lat)\nglobal.set(\"longitude\", lon)\n\nmsg.lat = lat,\nmsg.lon = lon\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1300,"y":3480,"wires":[["9ba48d39cbfd747d"]]},{"id":"85b194725e15adc0","type":"http in","z":"e78e73d3.53155","name":"","url":"app_home/","method":"get","upload":false,"swaggerDoc":"","x":120,"y":3340,"wires":[["9ed748e450026407"]]},{"id":"e5df736feee72178","type":"http response","z":"e78e73d3.53155","name":"send answer","statusCode":"200","headers":{},"x":990,"y":3340,"wires":[]},{"id":"9ed748e450026407","type":"function","z":"e78e73d3.53155","name":"reformat payload","func":"var num = \"zero one two three four five six seven eight nine ten\".split(\" \");\nfunction number2words(n) {\n if (n < 20) return num[n];\n var digit = n % 10;\n return number2words(~~(n / 1000)) + \" thousand\" + (n % 1000 != 0 ? \" \" + number2words(n % 1000) : \"\");\n}\n\n// let relays = msg.req.query.r ?? 0\n// let wrelays = msg.req.query.w ?? 0\n// let dimmer = msg.req.query.d ?? 0\nlet temp = msg.req.query.t ?? 0\nlet batt = msg.req.query.b ?? 0\nlet level = msg.req.query.l ?? 0\n\n//check for string \"undefined\"\ntemp = (temp == \"undefined\") ? 0 : temp\nbatt = (batt == \"undefined\") ? 0 : batt\nlevel = (level == \"undefined\") ? 0 : level\n\n// if (relays != null && relays != undefined && relays != \"0\") {\n// relays = relays.split(\",\")\n// let i = 0\n// while (i< relays.length) {\n// relays[i] = parseInt(relays[i])\n// relays[i] = number2words(relays[i])\n// i++\n// }\n// }\n// if (wrelays != null && wrelays != undefined && wrelays != \"0\") {\n// wrelays = wrelays.split(\",\")\n// let i = 0\n// while (i < wrelays.length) {\n// wrelays[i] = parseInt(wrelays[i])\n// wrelays[i] = \"W\"+number2words(wrelays[i])\n// i++\n// }\n// }\n// if (dimmer != null && dimmer != undefined && dimmer != \"0\") {\n// dimmer = dimmer.split(\",\")\n// let i = 0\n// while (i < dimmer.length) {\n// dimmer[i] = parseInt(dimmer[i]) - 1 // dimmer index starts at 0 internally!\n// dimmer[i] = \"dimmer\"+dimmer[i]\n// i++\n// }\n// }\nif (temp != null && temp != undefined && temp != \"0\") {\n temp = temp.split(\",\")\n let i = 0\n while (i < temp.length) {\n temp[i] = \"temp\" + temp[i]\n i++\n }\n}\nif (level != null && level != undefined && level != \"0\") {\n level = level.split(\",\")\n let i = 0\n while (i < level.length) {\n level[i] = \"level\" + level[i]\n i++\n }\n}\nif (batt != null && batt != undefined) {\n batt = batt == \"1\" ? 1:0;\n}\n\nmsg.payload = {\n // \"relays\": relays,\n // \"wrelays\": wrelays,\n // \"dimmer\": dimmer,\n \"temp\": temp,\n \"batt\": batt,\n \"level\": level\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":330,"y":3340,"wires":[["266381b96a593915"]]},{"id":"266381b96a593915","type":"function","z":"e78e73d3.53155","name":"generate objects","func":"let relays = msg.payload.relays ?? 0;\nlet wrelays = msg.payload.wrelays ?? 0;\nlet dimmer = msg.payload.dimmer ?? 0;\nlet temp = msg.payload.temp ?? 0;\nlet batt = msg.payload.batt ?? 0;\nlet level = msg.payload.level ?? 0;\n\n\nfunction wordToNumber(word) {\n const numberWords = {\n zero: 0,\n one: 1,\n two: 2,\n three: 3,\n four: 4,\n five: 5,\n six: 6,\n seven: 7,\n eight: 8,\n nine: 9,\n ten: 10, // Add more as needed\n };\n\n const lowerCaseWord = word.toLowerCase();\n return numberWords[lowerCaseWord] || NaN;\n}\n\n// if (relays != null && relays != undefined && relays != \"0\") {\n// let i = 0;\n// msg.payload.relays = [];\n\n// while (i < relays.length) {\n// msg.payload.relays[i] = {};\n// msg.payload.relays[i].id = \"Relay\"+wordToNumber(relays[i])\n// msg.payload.relays[i].state = global.get(relays[i]);\n// msg.payload.relays[i].name = global.get(\"N\" + relays[i]);\n// //msg.payload.relays[i].autooff = global.get(relays[i] + \"offauto\") ?? 0;\n// i++;\n// }\n// }\n\n// if (wrelays != null && wrelays != undefined && wrelays != \"0\") {\n// let i = 0;\n// msg.payload.wrelays = [];\n\n// while (i < wrelays.length) {\n// msg.payload.wrelays[i] = {};\n// msg.payload.wrelays[i].id = \"WifiRelay\"+wordToNumber(wrelays[i].substring(1))\n// msg.payload.wrelays[i].state = global.get(wrelays[i]);\n// msg.payload.wrelays[i].name = global.get(\"N\" + wrelays[i]);\n// msg.payload.wrelays[i].firmware = global.get(\"wrelay\" + wordToNumber(wrelays[i].substring(1))+\"_firmware\");\n// //msg.payload.wrelays[i].autooff = global.get(wrelays[i] + \"offauto\") ?? 0;\n// i++;\n// }\n// }\n\n// if (dimmer != null && dimmer != undefined && dimmer != \"0\") {\n// let i = 0;\n// msg.payload.dimmer = [];\n\n// while (i < dimmer.length) {\n// msg.payload.dimmer[i] = {};\n// msg.payload.dimmer[i].id = \"dimmer\"+(parseInt(dimmer[i].substring(6))+1)\n// msg.payload.dimmer[i].state = global.get(dimmer[i]);\n// msg.payload.dimmer[i].name = global.get(\"N\" + dimmer[i]);\n// //msg.payload.dimmer[i].autooff = global.get(dimmer[i] + \"offauto\") ?? 0;\n// i++;\n// }\n// }\n\nif (temp != null && temp != undefined && temp != \"0\") {\n let i = 0;\n msg.payload.temp = [];\n\n while (i < temp.length) {\n msg.payload.temp[i] = {};\n msg.payload.temp[i].id = \"temp\"+parseInt(temp[i].substring(4))\n msg.payload.temp[i].state = global.get(temp[i]);\n msg.payload.temp[i].name = global.get(\"N\" + temp[i]);\n i++;\n }\n}\nif (level != null && level != undefined && level != \"0\") {\n let i = 0;\n msg.payload.level = [];\n\n while (i < level.length) {\n msg.payload.level[i] = {};\n msg.payload.level[i].id = \"level\"+parseInt(level[i].substring(5))\n msg.payload.level[i].state = global.get(\"Level\"+level[i].substring(level[i].length-1));\n msg.payload.level[i].name = global.get(\"NLevel\" + level[i].substring(level[i].length - 1));\n i++;\n }\n}\nif (batt != null && batt != undefined && batt != \"0\" || batt != 0 && batt == 1) {\n msg.payload.batt = {\n \"VoltB\": global.get(\"MainBattVolt\"),\n \"Ampere\": global.get(\"MainBattAmps\"),\n \"battsoc\": global.get(\"MainBattSoc\")\n }\n}\n\n\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":530,"y":3340,"wires":[["081e13488093c513"]]},{"id":"081e13488093c513","type":"function","z":"e78e73d3.53155","name":"create response object","func":"//Create new object and respond\n\nmsg.newObject = {\n // \"relays\": {},\n // \"wrelays\": {},\n // \"dimmer\": {},\n \"temp\": {},\n \"batt\": {},\n \"level\": {},\n}\n\n// for (var i = 0; i < msg.payload.relays.length; i++) {\n// msg.newObject.relays[msg.payload.relays[i].id] = msg.payload.relays[i]\n// }\n// for (var i = 0; i < msg.payload.wrelays.length; i++) {\n// msg.newObject.wrelays[msg.payload.wrelays[i].id] = msg.payload.wrelays[i]\n// }\n// for (var i = 0; i < msg.payload.dimmer.length; i++) {\n// msg.newObject.dimmer[msg.payload.dimmer[i].id] = msg.payload.dimmer[i]\n// }\nfor (var i = 0; i < msg.payload.temp.length; i++) {\n msg.newObject.temp[msg.payload.temp[i].id] = msg.payload.temp[i]\n}\nfor (var i = 0; i < msg.payload.level.length; i++) {\n msg.newObject.level[msg.payload.level[i].id] = msg.payload.level[i]\n}\nmsg.newObject.batt = msg.payload.batt\n\nmsg.payload = msg.newObject\n\nif (msg.payload.batt == 0) {\n delete msg.payload.batt\n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":760,"y":3340,"wires":[["e5df736feee72178"]]},{"id":"65e561c5aa1b380a","type":"http in","z":"e78e73d3.53155","name":"","url":"position_sensor/","method":"get","upload":false,"swaggerDoc":"","x":140,"y":3500,"wires":[["fb780f6a94877b94"]]},{"id":"fb780f6a94877b94","type":"function","z":"e78e73d3.53155","name":"get variables","func":"if (msg.payload.request == \"true\" && (flow.get(\"mpuRequestStarted\") == false || flow.get(\"mpuRequestStarted\") == undefined)) {\n flow.set(\"mpuRequestStarted\", true)\n node.send([null, msg, null, null])\n}\nif (msg.payload.request == \"calibrate\") {\n msg.payload = {\n \"calibration\": true\n }\n return [ msg, null, msg, null]\n}\nif (msg.payload.request == \"true\" && flow.get(\"mpuRequestStarted\") == true){ \n msg.payload = {\n \"x_angle\": global.get(\"x_angle\"),\n \"y_angle\": global.get(\"y_angle\"),\n }\n return [null, null, msg, null];\n}\nelse if (msg.payload.request == \"false\") {\n flow.set(\"mpuRequestStarted\", false)\n msg.payload = { \"request\": false}\n return[null, null, msg, msg]\n}","outputs":4,"noerr":0,"initialize":"","finalize":"","libs":[],"x":350,"y":3500,"wires":[["46505864c3d9e739"],["44b78f2a6ec1dafb"],["be6a1f7f781fb604"],["ebdf10e1d4ee8666"]]},{"id":"be6a1f7f781fb604","type":"http response","z":"e78e73d3.53155","name":"send answer","statusCode":"200","headers":{},"x":635,"y":3507,"wires":[]},{"id":"8ddf79b96a97f756","type":"comment","z":"e78e73d3.53155","name":"endpoint for widgets on the app homescreen","info":"","x":210,"y":3300,"wires":[]},{"id":"e1c574b320512f5b","type":"comment","z":"e78e73d3.53155","name":"endpoint position sensor mpu6050","info":"","x":180,"y":3460,"wires":[]},{"id":"44b78f2a6ec1dafb","type":"link out","z":"e78e73d3.53155","name":"positionSensor start","mode":"link","links":["6619f21f66ccc3a3"],"x":535,"y":3480,"wires":[]},{"id":"ebdf10e1d4ee8666","type":"link out","z":"e78e73d3.53155","name":"positionSensor stop","mode":"link","links":["be30fa7396b2172a"],"x":535,"y":3540,"wires":[]},{"id":"46505864c3d9e739","type":"link out","z":"e78e73d3.53155","name":"positionSensor calibrate","mode":"link","links":["a32a3d5947c57eb9"],"x":535,"y":3440,"wires":[]},{"id":"b29bf552eb93a13b","type":"debug","z":"e78e73d3.53155","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":990,"y":2860,"wires":[]}]