Skip to content

Instantly share code, notes, and snippets.

@CyberAndi
Last active Nov 21, 2019
Embed
What would you like to do?
Mediola (a.i.o.) Gateway read Properties
[{"id":"51466e46.72aaf8","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"d3afe9b.b32c098","type":"http request","z":"51466e46.72aaf8","name":"Mediola Gateway","method":"GET","ret":"txt","paytoqs":false,"url":"http://192.168.1.1/command?XC_USER=USERNAME&XC_PASS=PASSWORD&XC_FNC=GetStates","tls":"","persist":false,"proxy":"","authType":"","x":470,"y":240,"wires":[["f6683031.e9215","d793052c.44407"]]},{"id":"961a60b8.6f9bf8","type":"inject","z":"51466e46.72aaf8","name":"Mediola abfrufen","topic":"Mediola","payload":"","payloadType":"date","repeat":"60","crontab":"","once":true,"onceDelay":0.1,"x":230,"y":240,"wires":[["d3afe9b.b32c098"]]},{"id":"f6683031.e9215","type":"function","z":"51466e46.72aaf8","name":"Mediola Status ok","func":"var ergebnis = msg.payload.substring(msg.payload.indexOf('[{')+1);\n ergebnis = ergebnis.substring(2, ergebnis.indexOf('}]') -1); \nvar wert = ergebnis.split('},{');\nvar count = 0;\nvar mediola = wert;\nvar splitmsg = mediola;\nvar statemsg = \"\";\nvar daten = \"\";\nvar subdaten = \"\";\nvar decimaldaten = \"\";\nvar decdaten = [];\nvar adressen = \"\";\nvar decimal = 0;\nvar temp = \"\";\nvar temp2 = \"\";\nvar tempzahl = 0;\nvar laenge = 0;\nvar erg = \"\";\nvar globalMediola = [];\nvar msg_out=[]; //array for message objects\nvar j = 0\nvar i = 0;\nvar k = 0;\n msg.payload = null;\n msg.ergebnis = ergebnis;\n for (i = 0; i < mediola.length -1; i++) {\n daten = mediola[i].substring(mediola[i].indexOf(\"state\")+ 8);\n daten = daten.substring(0,daten.indexOf('\"'));\n adressen = mediola[i].substring(mediola[i].indexOf(\"adr\")+ 6);\n adressen = adressen.substring(0,adressen.indexOf(\",\")-1);\n if (daten != \"off\" && daten != \"on\") {\n decimaldaten = daten.split(\":\");\n decimal = 0;\n subdaten = \"\";\n for (j=0; j < decimaldaten.length; j++){ //pro decimaldatenObjekt in Dezimal umrechnen\n temp = \"\"; \n temp2 = \"\";\n decdaten[j] = \"\";\n decimal = 0;\n temp = String(decimaldaten[j].toLowerCase());\n \n for (k = 0; k < temp.length ; k = k + 1) { //pro Zeichen in Dezimal umrechnen\n \n temp2 = temp.substring(temp.length - k -1, temp.length - k );\n if (temp2 == \"a\") {\n temp2 = \"10\";\n } else if (temp2 == \"b\") {\n temp2 = \"11\";\n } else if (temp2 == \"c\") {\n temp2 = \"12\";\n } else if (temp2 == \"d\") {\n temp2 = \"13\";\n } else if (temp2 == \"e\") {\n temp2 = \"14\";\n } else if (temp2 == \"f\") {\n temp2 = \"15\";\n }\n \n decimal = ((16 ** k ) * Number(temp2))+ decimal;\n \n }\n decdaten[j] = String(decimal);\n if (j > 0) {\n subdaten = subdaten + \":\" + decdaten[j];\n } else {\n subdaten = decdaten[j];\n }\n }\n \n } \n if (subdaten == \"255:255\" || subdaten == \"0:0:255\") {\n subdaten = \"unknown\"\n }\n if (mediola[i].indexOf(\"type\") != -1 && mediola[i].indexOf(\"WS300\") != -1){\n var KlimaMsg = {payload:subdaten,name:\"Klima_\"+i + \":\"+adressen,sensor:\"Klima\",adresse:adressen,temperatur:decdaten[0],luftfeuchtigkeit:decdaten[1],on_off:\"\",daten:decimaldaten[0] + \":\"+ decimaldaten[1]+\":\"+decimaldaten[2],stream:wert[i]};\n globalMediola[i] = KlimaMsg;\n msg_out.push(KlimaMsg);\n } else if (mediola[i].indexOf(\"type\") != -1 && mediola[i].indexOf(\"IT\") != -1){\n var ITMsg = {payload:subdaten,name:\"Intertechno_\"+i + \":\"+adressen,sensor:\"Intertechno\",adresse:adressen,temperatur:\"\",luftfeuchtigkeit:\"\",on_off:\"\",daten:decimaldaten[0]+\":\"+decimaldaten[1],stream:wert[i]};\n globalMediola[i] = ITMsg;\n msg_out.push(ITMsg);\n } else if (mediola[i].indexOf(\"type\") != -1 && mediola[i].indexOf(\"FS20\") != -1){\n var FS20Msg = {payload:subdaten,name:\"FS20_\"+i + \":\"+adressen,sensor:\"FS20\",adresse:adressen,temperatur:\"\",luftfeuchtigkeit:\"\",on_off:\"\",daten:daten,stream:wert[i]};\n globalMediola[i] = FS20Msg;\n msg_out.push(FS20Msg);\n } else if (mediola[i].indexOf(\"type\") != -1 && mediola[i].indexOf(\"FHT\") != -1){\n var FHTMsg = {payload:subdaten,name:\"FunkThermostat_\"+i + \":\"+adressen,sensor:\"FunkThermostat\",adresse:adressen,temperatur:\"\",luftfeuchtigkeit:\"\",on_off:\"\",daten:daten,stream:wert[i]};\n globalMediola[i] = FHTMsg;\n msg_out.push(FHTMsg);\n } else if (mediola[i].indexOf(\"type\") != -1 && mediola[i].indexOf(\"IR\") != -1){\n var IRMsg = {payload:subdaten,name:\"Infrarot_\"+i + \":\"+adressen,sensor:\"Infrarot\",adresse:adressen,temperatur:\"\",luftfeuchtigkeit:\"\",on_off:\"\",daten:daten,stream:wert[i]};\n globalMediola[i] = IRMsg;\n msg_out.push(IRMsg);\n } else if (mediola[i].indexOf(\"type\") != -1 && mediola[i].indexOf(\"EM\") != -1){\n var StromMsg = {payload:subdaten,name:\"Stromsensor_\"+i + \":\"+adressen,sensor:\"Stromsensor\",adresse:adressen,temperatur:\"\",luftfeuchtigkeit:\"\",on_off:\"\",daten:daten,stream:wert[i]};\n globalMediola[i] = StromMsg;\n msg_out.push(StromMsg);\n } else if (mediola[i].indexOf(\"type\") != -1 && mediola[i].indexOf(\"RF\") != -1){\n var RFMsg = {payload:subdaten,name:\"Funksignal_\"+i + \":\"+adressen,sensor:\"Funksignal\",adresse:adressen,temperatur:\"\",luftfeuchtigkeit:\"\",on_off:\"\",daten:daten,stream:wert[i]};\n globalMediola[i] = RFMsg;\n msg_out.push(RFMsg);\n } else if (mediola[i].indexOf(\"type\") != -1 && mediola[i].indexOf(\"HM\") != -1){\n var HMMsg = {payload:subdaten,name:\"HomeMatic_\"+i + \":\"+adressen,sensor:\"HomeMatic\",adresse:adressen,temperatur:\"\",luftfeuchtigkeit:\"\",on_off:\"\",daten:daten,stream:wert[i]};\n globalMediola[i] = HMMsg;\n msg_out.push(HMMsg);\n } else if (mediola[i].indexOf(\"type\") != -1 && mediola[i].indexOf(\"HmIP\") != -1){\n var HMIPMsg = {payload:subdaten,name:\"HomeMaricIP_\"+i + \":\"+adressen,sensor:\"HomeMatic IP\",adresse:adressen,temperatur:\"\",luftfeuchtigkeit:\"\",on_off:\"\",daten:daten,stream:wert[i]};\n globalMediola[i] = HMIPMsg;\n msg_out.push(HMIPMsg);\n } else {\n var sonstigeMsg = {payload:subdaten,name:\"Sensor_\"+i + \":\"+adressen,sensor:\"unknown\",adresse:adressen,temperatur:\"\",luftfeuchtigkeit:\"\",on_off:\"\",daten:daten,stream:wert[i]};\n globalMediola[i] = sonstigeMsg;\n msg_out.push(sonstigeMsg);\n }\n }\n\nglobal.set('Mediola_GW1_Read',globalMediola);\nreturn [msg_out] \n\n\nergebnis = null;\nwert = null;\ncount = null;\nmediola = null;\nsplitmsg = null;\nstatemsg =null;\ndaten = null;\nsubdaten = null;\ndecimaldaten = null;\ndecdaten = null;\nadressen = null;\ndecimal = null;\ntemp = null;\ntemp2 = null;\ntempzahl = null;\nlaenge = null;\nerg = null;\nglobalMediola = null;\nmsg_out=null;\nj = null;\ni = null;\nk = null;\n\n","outputs":1,"noerr":0,"x":700,"y":240,"wires":[["328c0d9.4da1272","d793052c.44407","f7e9b5d9.47c588"]]},{"id":"328c0d9.4da1272","type":"switch","z":"51466e46.72aaf8","name":"Mediola_Sensor","property":"adresse","propertyType":"msg","rules":[{"t":"eq","v":"11","vt":"str"},{"t":"eq","v":"13","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":930,"y":240,"wires":[["f6648a81.ab8ae"],["8ce4da89.bfbed"]]},{"id":"f6648a81.ab8ae","type":"function","z":"51466e46.72aaf8","name":"Mediola_Klima","func":"var Nachricht = msg.payload;\nvar Wert = [];\nvar Luftfeuchtigkeit = 0;\nvar Temperatur = 0;\nvar msg_out=[];\nWert = Nachricht.split(\":\")\nif (Nachricht.adresse !== \"\") {\n Temperatur = Number(Wert[0])/10;\n Luftfeuchtigkeit = Number(Wert[1])/10;\n var newMsg = {payload:String(Temperatur),topic:msg.topic+\"Temp\"};\n var newMsg2 = {payload:String(Luftfeuchtigkeit),topic:msg.topic+\"LFeucht\"};\n\n}\nreturn [newMsg, newMsg2]\nNachricht = null;\nWert[0]= null;\nwert[1]= null;\nWert = null;\nLuftfeuchtigkeit = null;\nTemperatur = null;\n","outputs":2,"noerr":0,"x":1170,"y":140,"wires":[[],[]]},{"id":"8ce4da89.bfbed","type":"function","z":"51466e46.72aaf8","name":"Mediola_Klima","func":"var Nachricht = msg.payload;\nvar Wert = [];\nvar Luftfeuchtigkeit = 0;\nvar Temperatur = 0;\nvar msg_out=[];\nvar Aussen=global.get('Temperatur_Aussen');\nWert = Nachricht.split(\":\")\nif (Nachricht.adresse !== \"\") {\n Temperatur = Number(Wert[0])/10;\n Luftfeuchtigkeit = Number(Wert[1])/10;\n global.set('Temperatur_Aussen', Number(String(Temperatur).substring(0,String(Temperatur).indexOf(\".\")) ) );\n var newMsg = {payload:String(Temperatur),topic:msg.topic+\"Temp\"};\n var newMsg2 = {payload:String(Luftfeuchtigkeit),topic:msg.topic+\"LFeucht\"};\n}\nreturn [newMsg, newMsg2]\nNachricht = null;\nWert[0]= null;\nwert[1]= null;\nWert = null;\nLuftfeuchtigkeit = null;\naussen = null;\nTemperatur = null;\n","outputs":2,"noerr":0,"x":1170,"y":300,"wires":[[],[]]},{"id":"d793052c.44407","type":"debug","z":"51466e46.72aaf8","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":920,"y":180,"wires":[]},{"id":"f7e9b5d9.47c588","type":"debug","z":"51466e46.72aaf8","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":900,"y":140,"wires":[]}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment