var IP = "192.168.5.184"; var PORT = 51443; var updateintervall = 10; // Update Intervall in Sekunden var api_version = "1.0"; var device_id = "iobroker-device-1234567890" var operator_id = "iobroker-1111-2222-3333-444455556666"; var Pfad = "Mitsubishi_WF-RAC"; var instanz = "0"; var airconId = ""; var basicdata = []; var ac_device = []; var debug = 1; var preset_new = ""; var running_new = ""; var auto3d_new = ""; var CoolHotJudge_new = ""; var Fan_new = ""; var Modus_new = ""; var vacant_new = ""; var WindLR_new = ""; var WindUD_new = ""; var link_preset = 'javascript.0.Mitsubishi_WF-RAC.xxxxxxxxxxxx.Livedaten.PresetTemp' var link_running = 'javascript.0.Mitsubishi_WF-RAC.xxxxxxxxxxxx.Livedaten.running' var link_3dauto = 'javascript.0.Mitsubishi_WF-RAC.xxxxxxxxxxxx.Livedaten.3DAuto' var link_CoolHotJudge = 'javascript.0.Mitsubishi_WF-RAC.xxxxxxxxxxxx.Livedaten.CoolHotJudge' var link_Fan = 'javascript.0.Mitsubishi_WF-RAC.xxxxxxxxxxxx.Livedaten.Fan' var link_Modus = 'javascript.0.Mitsubishi_WF-RAC.xxxxxxxxxxxx.Livedaten.Modus' var link_vacant = 'javascript.0.Mitsubishi_WF-RAC.xxxxxxxxxxxx.Livedaten.Vacant' var link_WindLR = 'javascript.0.Mitsubishi_WF-RAC.xxxxxxxxxxxx.Livedaten.WindLR' var link_WindUD = 'javascript.0.Mitsubishi_WF-RAC.xxxxxxxxxxxx.Livedaten.WindUD' var indoorTempList=[-30.0,-30.0,-30.0,-30.0,-30.0,-30.0,-30.0,-30.0,-30.0,-30.0,-30.0,-30.0,-30.0,-30.0,-30.0,-30.0,-29.0,-28.0,-27.0,-26.0,-25.0,-24.0,-23.0,-22.5,-22.0,-21.0,-20.0,-19.5,-19.0,-18.0,-17.5,-17.0,-16.5,-16.0,-15.0,-14.5,-14.0,-13.5,-13.0,-12.5,-12.0,-11.5,-11.0,-10.5,-10.0,-9.5,-9.0,-8.6,-8.3,-8.0,-7.5,-7.0,-6.5,-6.0,-5.6,-5.3,-5.0,-4.5,-4.0,-3.6,-3.3,-3.0,-2.6,-2.3,-2.0,-1.6,-1.3,-1.0,-0.5,0.0,0.3,0.6,1.0,1.3,1.6,2.0,2.3,2.6,3.0,3.2,3.5,3.7,4.0,4.3,4.6,5.0,5.3,5.6,6.0,6.3,6.6,7.0,7.2,7.5,7.7,8.0,8.3,8.6,9.0,9.2,9.5,9.7,10.0,10.3,10.6,11.0,11.2,11.5,11.7,12.0,12.3,12.6,13.0,13.2,13.5,13.7,14.0,14.2,14.5,14.7,15.0,15.3,15.6,16.0,16.2,16.5,16.7,17.0,17.2,17.5,17.7,18.0,18.2,18.5,18.7,19.0,19.2,19.5,19.7,20.0,20.2,20.5,20.7,21.0,21.2,21.5,21.7,22.0,22.2,22.5,22.7,23.0,23.2,23.5,23.7,24.0,24.2,24.5,24.7,25.0,25.2,25.5,25.7,26.0,26.2,26.5,26.7,27.0,27.2,27.5,27.7,28.0,28.2,28.5,28.7,29.0,29.2,29.5,29.7,30.0,30.2,30.5,30.7,31.0,31.3,31.6,32.0,32.2,32.5,32.7,33.0,33.2,33.5,33.7,34.0,34.2,34.5,34.7,35.0,35.3,35.6,36.0,36.2,36.5,36.7,37.0,37.2,37.5,37.7,38.0,38.3,38.6,39.0,39.2,39.5,39.7,40.0,40.3,40.6,41.0,41.2,41.5,41.7,42.0,42.3,42.6,43.0,43.2,43.5,43.7,44.0,44.3,44.6,45.0,45.3,45.6,46.0,46.2,46.5,46.7,47.0,47.3,47.6,48.0,48.3,48.6,49.0,49.3,49.6,50.0,50.3,50.6,51.0,51.3,51.6,52.0] var outdoorTempList=[-50.0,-50.0,-50.0,-50.0,-50.0,-48.9,-46.0,-44.0,-42.0,-41.0,-39.0,-38.0,-37.0,-36.0,-35.0,-34.0,-33.0,-32.0,-31.0,-30.0,-29.0,-28.5,-28.0,-27.0,-26.0,-25.5,-25.0,-24.0,-23.5,-23.0,-22.5,-22.0,-21.5,-21.0,-20.5,-20.0,-19.5,-19.0,-18.5,-18.0,-17.5,-17.0,-16.5,-16.0,-15.5,-15.0,-14.6,-14.3,-14.0,-13.5,-13.0,-12.6,-12.3,-12.0,-11.5,-11.0,-10.6,-10.3,-10.0,-9.6,-9.3,-9.0,-8.6,-8.3,-8.0,-7.6,-7.3,-7.0,-6.6,-6.3,-6.0,-5.6,-5.3,-5.0,-4.6,-4.3,-4.0,-3.7,-3.5,-3.2,-3.0,-2.6,-2.3,-2.0,-1.7,-1.5,-1.2,-1.0,-0.6,-0.3,0.0,0.2,0.5,0.7,1.0,1.3,1.6,2.0,2.2,2.5,2.7,3.0,3.2,3.5,3.7,4.0,4.2,4.5,4.7,5.0,5.2,5.5,5.7,6.0,6.2,6.5,6.7,7.0,7.2,7.5,7.7,8.0,8.2,8.5,8.7,9.0,9.2,9.5,9.7,10.0,10.2,10.5,10.7,11.0,11.2,11.5,11.7,12.0,12.2,12.5,12.7,13.0,13.2,13.5,13.7,14.0,14.2,14.4,14.6,14.8,15.0,15.2,15.5,15.7,16.0,16.2,16.5,16.7,17.0,17.2,17.5,17.7,18.0,18.2,18.5,18.7,19.0,19.2,19.4,19.6,19.8,20.0,20.2,20.5,20.7,21.0,21.2,21.5,21.7,22.0,22.2,22.5,22.7,23.0,23.2,23.5,23.7,24.0,24.2,24.5,24.7,25.0,25.2,25.5,25.7,26.0,26.2,26.5,26.7,27.0,27.2,27.5,27.7,28.0,28.2,28.5,28.7,29.0,29.2,29.5,29.7,30.0,30.2,30.5,30.7,31.0,31.3,31.6,32.0,32.2,32.5,32.7,33.0,33.2,33.5,33.7,34.0,34.3,34.6,35.0,35.2,35.5,35.7,36.0,36.3,36.6,37.0,37.2,37.5,37.7,38.0,38.3,38.6,39.0,39.3,39.6,40.0,40.3,40.6,41.0,41.3,41.6,42.0,42.3,42.6,43.0] log ("Systemstart...."); updatedaten(); await wait(2000); log ("Klimaanlage : '" + airconId + "' gefunden."); delete_account() await wait(2000); update_account(); await wait(2000); Intervall = setInterval(async function () { updatedaten(); }, updateintervall * 1000); on({id: link_preset, change: "ne"}, async function (obj) { var value = obj.state.val; var oldValue = obj.oldState.val; if (ac_device[1] != value) { log ("Preset manual geändert auf : " + value + " °C") preset_new = '' + value; senddata() } }); on({id: link_running, change: "ne"}, async function (obj) { var value = obj.state.val; var oldValue = obj.oldState.val; if (ac_device[0] != value) { log ("Running manual geändert auf : " + value + " ") running_new = '' + value; senddata() } }); on({id: link_3dauto, change: "ne"}, async function (obj) { var value = obj.state.val; var oldValue = obj.oldState.val; if (ac_device[6] != value) { log ("3D Auto manual geändert auf : " + value + " ") auto3d_new = '' + value; senddata() } }); on({id: link_CoolHotJudge, change: "ne"}, async function (obj) { var value = obj.state.val; var oldValue = obj.oldState.val; if (ac_device[7] != value) { log ("CoolHotJudge manual geändert auf : " + value + " ") CoolHotJudge_new = '' + value; senddata() } }); on({id: link_Fan, change: "ne"}, async function (obj) { var value = obj.state.val; var oldValue = obj.oldState.val; if (ac_device[3] != value) { log ("Fan manual geändert auf : " + value + " ") Fan_new = '' + value; senddata() } }); on({id: link_Modus, change: "ne"}, async function (obj) { var value = obj.state.val; var oldValue = obj.oldState.val; if (ac_device[2] != value) { log ("Modus manual geändert auf : " + value + " ") Modus_new = '' + value; senddata() } }); on({id: link_vacant, change: "ne"}, async function (obj) { var value = obj.state.val; var oldValue = obj.oldState.val; if (ac_device[9] != value) { log ("Vacant manual geändert auf : " + value + " ") vacant_new = '' + value; senddata() } }); on({id: link_WindLR, change: "ne"}, async function (obj) { var value = obj.state.val; var oldValue = obj.oldState.val; if (ac_device[5] != value) { log ("Wind LR manual geändert auf : " + value + " ") WindLR_new = '' + value; senddata() } }); on({id: link_WindUD, change: "ne"}, async function (obj) { var value = obj.state.val; var oldValue = obj.oldState.val; if (ac_device[4] != value) { log ("Wind UD manual geändert auf : " + value + " ") WindUD_new = '' + value; senddata() } }); function senddata() { if (preset_new != "") { var preset = preset_new} else { var preset = ac_device[1] } if (running_new != "") { var running = running_new} else { var running = ac_device[0] } if (auto3d_new != "") { var auto3d = auto3d_new} else { var auto3d = ac_device[6] } if (CoolHotJudge_new != "") { var CoolHotJudge = CoolHotJudge_new} else { var CoolHotJudge = ac_device[7] } if (Fan_new != "") { var fan = Fan_new} else { var fan = ac_device[3] } if (Modus_new != "") { var Modus = Modus_new} else { var Modus = ac_device[2] } if (vacant_new != "") { var vacant = vacant_new} else { var vacant = ac_device[9] } if (WindLR_new != "") { var WindLR = WindLR_new} else { var WindLR = ac_device[5] } if (WindUD_new != "") { var WindUD = WindUD_new} else { var WindUD = ac_device[4] } log ("Setzte auf : 'preset:"+preset+"', 'running:"+running+"', 'auto3d:"+auto3d+"', 'HotJudge:"+CoolHotJudge + "', 'Fan:" + fan + "', 'Modus:" + Modus + "', 'Vacant:" + vacant + "', 'WindLR:"+WindLR + "', 'WindUD:"+WindUD + "'") var stat_byte = [0, 0, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; log (stat_byte); // COMMAND TO BYTES if (running) { stat_byte[2] |= 3; } else { stat_byte[2] |= 2; } // Operating Mode if (Modus == 0) { stat_byte[2] |= 32; log ("Modus0");} if (Modus == 1) { stat_byte[2] |= 40; log ("Modus1");} if (Modus == 2) { stat_byte[2] |= 48; log ("Modus2");} if (Modus == 3) { stat_byte[2] |= 44; log ("Modus3");} if (Modus == 4) { stat_byte[2] |= 36; log ("Modus4");} if (fan == 0) { stat_byte[3] |= 15; log ("fan0");} if (fan == 1) { stat_byte[3] |= 8; log ("fan1");} if (fan == 2) { stat_byte[3] |= 9; log ("fan2");} if (fan == 3) { stat_byte[3] |= 10; log ("fan3");} if (fan == 4) { stat_byte[3] |= 14; log ("fan4"); } if (WindUD == 0) { stat_byte[2] |= 192; stat_byte[3] |= 128; log ("WindUD0");} if (WindUD == 1) { stat_byte[2] |= 128; stat_byte[3] |= 128; log ("WindUD1");} if (WindUD == 2) { stat_byte[2] |= 128; stat_byte[3] |= 144; log ("WindUD2");} if (WindUD == 3) { stat_byte[2] |= 128; stat_byte[3] |= 160; log ("WindUD3");} if (WindUD == 4) { stat_byte[2] |= 128; stat_byte[3] |= 176; log ("WindUD4");} if (WindLR == 0) { stat_byte[12] |= 3; stat_byte[11] |= 16; log ("WindLR0");} if (WindLR == 1) { stat_byte[12] |= 2; stat_byte[11] |= 16; log ("WindLR1");} if (WindLR == 2) { stat_byte[12] |= 2; stat_byte[11] |= 17; log ("WindLR2");} if (WindLR == 3) { stat_byte[12] |= 2; stat_byte[11] |= 18; log ("WindLR3");} if (WindLR == 4) { stat_byte[12] |= 2; stat_byte[11] |= 19; log ("WindLR4");} if (WindLR == 5) { stat_byte[12] |= 2; stat_byte[11] |= 20; log ("WindLR5");} if (WindLR == 6) { stat_byte[12] |= 2; stat_byte[11] |= 21; log ("WindLR6");} if (WindLR == 7) { stat_byte[12] |= 2; stat_byte[11] |= 22; log ("WindLR7");} if (Modus == 3) {preset = "25.0"; log ("Preset 25°C");} stat_byte[4] |= parseFloat(preset / 0.5) + 128; if (auto3d) { stat_byte[12] |= 12; log ("3D Auto an"); } else { stat_byte[12] |= 8; log ("3D Auto aus"); } if (!CoolHotJudge) { stat_byte[8] |= 8; log ("CoolHot aus");} if (ac_device[8] == 1) { stat_byte[10] |= 0; if (vacant == 1) { stat_byte[10] |= 1 } else { stat_byte[10] |= 0 } } if (ac_device[8] == 1 || ac_device[8] == 2) { } else { stat_byte[10] |= 0; stat_byte[10] |= 128; } log (stat_byte); // RECEIVE TO BYTES var stat_byteb = [0, 0, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; if (running) { stat_byteb[2] |= 1; } // Operating Mode if (Modus == 1) { stat_byteb[2] |= 8; log ("Modus1");} if (Modus == 2) { stat_byteb[2] |= 16; log ("Modus2");} if (Modus == 3) { stat_byteb[2] |= 12; log ("Modus3");} if (Modus == 4) { stat_byteb[2] |= 4; log ("Modus4");} if (fan == 0) { stat_byteb[3] |= 7; log ("fan0");} if (fan == 2) { stat_byteb[3] |= 1; log ("fan2");} if (fan == 3) { stat_byteb[3] |= 2; log ("fan3");} if (fan == 4) { stat_byteb[3] |= 6; log ("fan4"); } if (WindUD == 0) { stat_byteb[2] |= 64; log ("WindUD0");} if (WindUD == 2) { stat_byteb[3] |= 16; log ("WindUD2");} if (WindUD == 3) { stat_byteb[3] |= 32; log ("WindUD3");} if (WindUD == 4) { stat_byteb[3] |= 48; log ("WindUD4");} if (WindLR == 0) { stat_byteb[12] |= 1; log ("WindLR0");} if (WindLR == 1) { stat_byteb[11] |= 0; log ("WindLR1");} if (WindLR == 2) { stat_byteb[11] |= 1; log ("WindLR2");} if (WindLR == 3) { stat_byteb[11] |= 2; log ("WindLR3");} if (WindLR == 4) { stat_byteb[11] |= 3; log ("WindLR4");} if (WindLR == 5) { stat_byteb[11] |= 4; log ("WindLR5");} if (WindLR == 6) { stat_byteb[11] |= 5; log ("WindLR6");} if (WindLR == 7) { stat_byteb[11] |= 6; log ("WindLR7");} if (Modus == 3) {preset = "25.0"; log ("Preset 25°C");} stat_byteb[4] |= parseFloat(preset / 0.5); if (auto3d) { stat_byteb[12] |= 4; log ("3D Auto an"); } if (!CoolHotJudge) { stat_byteb[8] |= 8; log ("CoolHot aus");} if (ac_device[8] == 1) { stat_byteb[0] |= 1; if (vacant == 1) { stat_byteb[10] |= 1 } else { stat_byteb[10] |= 0 } } if (ac_device[8] == 1 || ac_device[8] == 2) { } else { stat_byteb[15] |= 0; } log (stat_byteb.toString()); stat_byte.push('1', '255', '255', '255', '255'); stat_byteb.push('1', '255', '255', '255', '255'); log ("Command:'" + stat_byte.toString() + "'"); log ("Receive:'" + stat_byteb.toString() + "'"); var command = add_crc16(this, stat_byte); var receive = add_crc16(this, stat_byteb); log ("Command add CRC:'" + command.toString() + "'"); log ("Receive add CRC:'" + receive.toString() + "'"); var content_new = (command + " " + receive).slice(2, -1); //log ("CRC:" + crc16(stat_byte)); log ("Content New : '" + content_new + "'"); console.log("FERTIG??:" + Buffer.from(content_new, "base64").toString("base64")); } function updatedaten() { var url = "curl -X POST http://" + IP + ":" + PORT + "/beaver/command/getDeviceInfo -H \'Content-Type: application/json\' -d \'{" var urlb = '"apiVer":"'+api_version + '","command":"getAirconStat","deviceId":"' + device_id + '","operatorId":"' + operator_id + '","timestamp":'+ Math.round(new Date().getTime() / 1000) + '}' url = url + urlb + "'" exec(url, async function (error, result, stderr) { var ac_device = []; if (result) { if (debug) { log ("Update empfangen..."); } const obj = JSON.parse(result); const contents = obj.contents; var airconStat = contents.airconStat; const wireless = contents.wireless; const mcu = contents.mcu; ac_device = translate_bytes(airconStat); airconId = contents.airconId; basicdata[0] = contents.airconId; basicdata[1] = contents.airconStat; basicdata[2] = contents.logStat; basicdata[3] = contents.updatedBy; basicdata[4] = contents.expires; basicdata[5] = contents.ledStat; basicdata[6] = contents.autoHeating; basicdata[7] = contents.highTemp; basicdata[8] = contents.lowTemp; basicdata[9] = contents.firmType; basicdata[10] = wireless.firmVer; basicdata[11] = mcu.firmVer; basicdata[12] = contents.timezone; basicdata[13] = contents.remoteList; basicdata[14] = contents.numOfAccount; if (debug) { debuglogbasic(basicdata) } if (debug) { log (" ") } if (debug) { debuglogdata(ac_device) } createObjects() } else { if (debug) { log ("Keine Werte erhalten....") } } }); } function debuglogbasic(basicdata) { log ("********* BASIC-DATEN *********") log ("AirconID : " + basicdata[0]) log ("LogStat : " + basicdata[2]) log ("updatedBy : " + basicdata[3]) log ("expires : " + basicdata[4]) log ("ledStatus : " + basicdata[5]) log ("autoHeating : " + basicdata[6]) log ("highTemp : " + basicdata[7]) log ("lowTemp : " + basicdata[8]) log ("firmType : " + basicdata[9]) log ("wirelessfirmVer : " + basicdata[10]) log ("mcufirmVer : " + basicdata[11]) log ("timezone : " + basicdata[12]) log ("remoteList : " + basicdata[13]) log ("numOfAccount : " + basicdata[14]) log ("*******************************") } function debuglogdata(ac_device) { log ("********* LIVE-DATEN *********") log ("Klima läuft : " + Boolean(ac_device[0])) //Status log ("Preset Temp : " + ac_device[1] + " °C") //PRESET TEMP log ("Modus : " + ac_device[2]) log ("Lüfter : " + ac_device[3]) log ("Wind UD : " + ac_device[4]) log ("Wind LR : " + ac_device[5]) log ("3D Auto : " + Boolean(ac_device[6])) log ("CoolHotJudge : " + Boolean(ac_device[7])) log ("ModelNr : " + ac_device[8]) log ("Vacant : " + Boolean(ac_device[9])) log ("Error : " + ac_device[10]) log ("Indoor Temp. : " + ac_device[11] + " °C") log ("Outdoor Temp. : " + ac_device[12] + " °C") log ("Elektrik : " + ac_device[13] + "") log ("*******************************") } function translate_bytes(inputString) { var afterstr2utf = Buffer.from(inputString, "base64"); var content_byte_array = []; var content = []; var value_segment = []; for (var i = 0; i < afterstr2utf.length; i ++) { content_byte_array.push(hexToInt(decimalToHexString(afterstr2utf[i]))) } start_length = content_byte_array[18] * 4 + 21 for (var i = start_length; i < start_length + 18 ; i ++) { content.push(content_byte_array[i]) } for (var i = start_length + 19; i < content_byte_array.length - 2; i ++) { value_segment.push(content_byte_array[i]) } ac_device[0] = 3 & content[2] // LÄUFT KLIMA ? ac_device[1] = content[4] / 2 // PRESET TEMP // MODUS var xxxx = 60 & content[2] if (xxxx == 0 ) { ac_device[2] = 0; } // AUTOMATIK if (xxxx == 8 ) { ac_device[2] = 1; } // KÜHLEN if (xxxx == 16) { ac_device[2] = 2; } // HEIZEN if (xxxx == 12) { ac_device[2] = 3; } // LÜFTEN if (xxxx == 4) { ac_device[2] = 4; } // ENTFEUCHTEN // LÜFTER var xxxx = 15 & content[3] if (xxxx == 7) { ac_device[3] = 0; } // AUTOMATIK if (xxxx == 0) { ac_device[3] = 1; } // KLEIN if (xxxx == 1) { ac_device[3] = 2; } // MITTEL if (xxxx == 2) { ac_device[3] = 3; } // HOCH if (xxxx == 6) { ac_device[3] = 4; } // SEHR HOCH // WINDDIR UD var xxxx = content[2] & 192; var xxxy = 240 & content[3]; if (xxxx == 64) { ac_device[4] = 0; } // AUTO else { if (xxxy == 0) { ac_device[4] = 1; } // Hoch if (xxxy == 16) { ac_device[4] = 2; } // Mittel if (xxxy == 32) { ac_device[4] = 3; } // Tief if (xxxy == 48) { ac_device[4] = 4; } // sehr Tief } // WINDDIR LR var xxxx = content[12] & 3; var xxxy = 31 & content[11]; if (xxxx == 1) { ac_device[5] = 0; } // AUTO else { ac_device[5] = xxxy + 1 /* if (xxxy == 0) { ac_device[5] = 1; } // Links / Links if (xxxy == 1) { ac_device[5] = 2; } // Links / Mitte if (xxxy == 2) { ac_device[5] = 3; } // Mitte / Mitte if (xxxy == 3) { ac_device[5] = 4; } // Mitte / Rechts if (xxxy == 4) { ac_device[5] = 5; } // Rechts / Rechts if (xxxy == 5) { ac_device[5] = 6; } // Links / Rechts if (xxxy == 6) { ac_device[5] = 7; } // Rechts / Links */ } var xxxx = 12 & content[12]; if (xxxx == 0) { ac_device[6] = 0; } // 3DAuto Aus if (xxxx == 4) { ac_device[6] = 1; } // 3DAuto An var xxxx = content[8] & 8; if (xxxx >= 0) { ac_device[7] = 0; } // CoolHotJudge Aus if (xxxx < 0) { ac_device[7] = 1; } // CoolHotJudge AN var xxxx = content[0] & 127; if (xxxx == 0) { ac_device[8] = 0; } // ModelNr 0 if (xxxx == 1) { ac_device[8] = 1; } // ModelNr 1 if (xxxx == 2) { ac_device[8] = 2; } // ModelNr 2 ac_device[9] = content[10] & 1; // Vacant ac_device[10] = content[6] & 127; // Error Code if (value_segment.length >= 8) { ac_device[11] = indoorTempList[256 + value_segment[2]] ac_device[12] = outdoorTempList[256 + value_segment[6]] log("Test:|" + 256 + value_segment[6] + "|") } if (value_segment.length >= 11) { ac_device[13] = ((value_segment[11] << 8) + value_segment[10]) * 0.25 } else { ac_device[13] = "None" } return ac_device } function delete_account() { if (debug) { log ("Entferne Account...."); } var url = "curl -X POST http://" + IP + ":" + PORT + "/beaver/command/deleteAccountInfo -H \'Content-Type: application/json\' -d \'{" var urlb = '"apiVer":"'+api_version + '","command":"deleteAccountInfo","deviceId":"' + device_id + '","operatorId":"' + operator_id + '","contents":{"accountId":"' + operator_id + '","airconId":"' + airconId + '"},"timestamp":'+ Math.round(new Date().getTime() / 1000) + '}' url = url + urlb + "'" exec(url, async function (error, result, stderr) { if (result) { if (debug) { log ("Account erfolgreich entfernt..."); } const obj = JSON.parse(result); } else { log ("Account konnte nicht entfernt werden.") } }); } function update_account() { var url = "curl -X POST http://" + IP + ":" + PORT + "/beaver/command/updateAccountInfo -H \'Content-Type: application/json\' -d \'{" var urlb = '"apiVer":"'+api_version + '","command":"updateAccountInfo","deviceId":"' + device_id + '","operatorId":"' + operator_id + '","contents":{"accountId":"' + operator_id + '","airconId":"' + airconId + '","remote": 0,"timezone":"Europe/Berlin"},"timestamp":'+ Math.round(new Date().getTime() / 1000) + '}' url = url + urlb + "'" if (debug) { log ("Erstelle Account...."); } exec(url, async function (error, result, stderr) { if (result) { if (debug) { log ("Account erfolgreich erstellt..."); } const obj = JSON.parse(result); // log (obj); } else { log ("Account konnte nicht erstellt werden.") } }); } // ************************************************ // ******************* UTILITYS ******************* // ************************************************ function crc16ccitt(data) { var i, z, z2; data = function () { var _pj_a = [], _pj_b = data; for (var _pj_c = 0, _pj_d = _pj_b.length; _pj_c < _pj_d; _pj_c += 1) { var a = _pj_b[_pj_c]; _pj_a.push(a > 127 ? (256 - a) * -1 : a); } return _pj_a; }.call(this); i = 65535; for (var b, _pj_c = 0, _pj_a = data, _pj_b = _pj_a.length; _pj_c < _pj_b; _pj_c += 1) { b = _pj_a[_pj_c]; for (var i2 = 0, _pj_d = 8; i2 < _pj_d; i2 += 1) { z = true; z2 = (b >> 7 - i2 & 1) === 1; if ((i >> 15 & 1) !== 1) { z = false; } i = i << 1; if (z2 ^ z) { i ^= 4129; } } } return i & 65535; } function add_variable(byte_buffer) { /* Concat byte_buffer wit hveriable */ return byte_buffer + [1, 255, 255, 255, 255]; } function add_crc16(byte_buffer) { var crc; crc = crc16ccitt(this, byte_buffer); log ("CRC:'" + crc + "'") return byte_buffer + [crc & 255, crc >> 8 & 255]; } function decimalToHexString(number) { if (number < 0) { number = 0xFFFFFFFF + number + 1; } return number.toString(16).toUpperCase(); } function hexToInt(hex) { if (hex.length % 2 != 0) { hex = "0" + hex; } var num = parseInt(hex, 16); var maxVal = Math.pow(2, hex.length / 2 * 8); if (num > maxVal / 2 - 1) { num = num - maxVal } return num; } function createObjects() { createState(Pfad + '.' + airconId + '.Basisdaten.LogStat', parseFloat(basicdata[2]), {read: true, write: false, type: "number", unit:"", name: "Logstate"}); createState(Pfad + '.' + airconId + '.Basisdaten.LEDStatus', Boolean(basicdata[5]), {read: true, write: true, type: "boolean", unit:"", name: "LED"}); createState(Pfad + '.' + airconId + '.Basisdaten.AutoHeating', Boolean(basicdata[6]), {read: true, write: true, type: "boolean", unit:"", name: "autoHeating"}); createState(Pfad + '.' + airconId + '.Basisdaten.Wireless-Firmware', '' + basicdata[10], {read: true, write: false, type: "string", unit:"", name: "Wireless Firmware Version"}); createState(Pfad + '.' + airconId + '.Basisdaten.Typ', '' + basicdata[9], {read: true, write: false, type: "string", unit:"", name: "Wireless Adapter Type"}); createState(Pfad + '.' + airconId + '.Basisdaten.MCU-Firmware', '' + basicdata[11], {read: true, write: false, type: "string", unit:"", name: "MCU Firmware Version"}); createState(Pfad + '.' + airconId + '.Basisdaten.Timezone', '' + basicdata[12], {read: true, write: false, type: "string", unit:"", name: "Timezone"}); createState(Pfad + '.' + airconId + '.Basisdaten.RemoteList', '' + basicdata[13], {read: true, write: false, type: "string", unit:"", name: "Remotelist"}); createState(Pfad + '.' + airconId + '.Basisdaten.NumOfAccount', parseFloat(basicdata[14]), {read: true, write: false, type: "number", unit:"", name: "Anzahl Accounts"}); createState(Pfad + '.' + airconId + '.Basisdaten.AirconID', '' + basicdata[0], {read: true, write: false, type: "string", unit:"", name: "AirconID"}); createState(Pfad + '.' + airconId + '.Basisdaten.updatedBy', '' + basicdata[3], {read: true, write: false, type: "string", unit:"", name: "updatedBy"}); createState(Pfad + '.' + airconId + '.Basisdaten.expires', '' + basicdata[4], {read: true, write: false, type: "string", unit:"", name: "expires"}); createState(Pfad + '.' + airconId + '.Basisdaten.highTemp', '' + basicdata[7], {read: true, write: false, type: "string", unit:"", name: "highTemp"}); createState(Pfad + '.' + airconId + '.Basisdaten.lowTemp','' + basicdata[8], {read: true, write: false, type: "string", unit:"", name: "lowTemp"}); createState(Pfad + '.' + airconId + '.Basisdaten.airconStat', '' + basicdata[1], {read: true, write: false, type: "string", unit:"", name: "airconStat"}); setState(Pfad + '.' + airconId + '.Basisdaten.LogStat', parseFloat(basicdata[2]),true); setState(Pfad + '.' + airconId + '.Basisdaten.LEDStatus', Boolean(basicdata[5]),true); setState(Pfad + '.' + airconId + '.Basisdaten.AutoHeating', Boolean(basicdata[6]),true); setState(Pfad + '.' + airconId + '.Basisdaten.Wireless-Firmware', '' + basicdata[10],true); setState(Pfad + '.' + airconId + '.Basisdaten.Typ', '' + basicdata[9],true); setState(Pfad + '.' + airconId + '.Basisdaten.MCU-Firmware', '' + basicdata[11],true); setState(Pfad + '.' + airconId + '.Basisdaten.Timezone', '' + basicdata[12],true); setState(Pfad + '.' + airconId + '.Basisdaten.RemoteList', '' + '' + basicdata[13],true); setState(Pfad + '.' + airconId + '.Basisdaten.NumOfAccount', parseFloat(basicdata[14]),true); setState(Pfad + '.' + airconId + '.Basisdaten.AirconID', '' + basicdata[0],true); setState(Pfad + '.' + airconId + '.Basisdaten.updatedBy', '' + basicdata[3],true); setState(Pfad + '.' + airconId + '.Basisdaten.expires', '' + '' + basicdata[4],true); setState(Pfad + '.' + airconId + '.Basisdaten.highTemp', '' + basicdata[7],true); setState(Pfad + '.' + airconId + '.Basisdaten.lowTemp', '' + basicdata[8],true); setState(Pfad + '.' + airconId + '.Basisdaten.airconStat', '' + basicdata[1],true); createState(Pfad + '.' + airconId + '.Livedaten.running', Boolean(ac_device[0]), {read: true, write: true, type: "boolean", unit:"", name: "Klima läuft ?"}); createState(Pfad + '.' + airconId + '.Livedaten.PresetTemp', parseFloat(ac_device[1]), {read: true, write: true, type: "number", unit:"°C", name: "Preset Temperatur"}); createState(Pfad + '.' + airconId + '.Livedaten.Modus', '' + ac_device[2], {read: true, write: true, type: "string", "states": "0:Auto;1:Kühlen;2:Heizen;3:Lüften;4:Trocknen", name: "Modus"}); createState(Pfad + '.' + airconId + '.Livedaten.Fan', '' + ac_device[3], {read: true, write: true, type: "string", "states": "0:Auto;1:Niedrigste Stufe;2:Mittlere Stufe;3:Hohe Stufe;4:Höchste Stufe", name: "Geschwindigkeit Lüfter"}); createState(Pfad + '.' + airconId + '.Livedaten.WindUD', '' + ac_device[4], {read: true, write: true, type: "string", "states": "0:Auto;1:Hoch;2:Mittel;3:Tief;4:sehr Tief", name: "Klappe Links/Rechts"}); createState(Pfad + '.' + airconId + '.Livedaten.WindLR', '' + ac_device[5], {read: true, write: true, type: "string", "states": "0:Auto;1:Links/Links;2:Links/Mitte;3:Mitte/Mitte;4:Mitte/Rechts;5:Rechts/Rechts;6:Links/Rechts;7:Rechts/Links", name: "Klappe Hoch/Runter"}); createState(Pfad + '.' + airconId + '.Livedaten.3DAuto', Boolean(ac_device[6]), {read: true, write: true, type: "boolean", unit:"", name: "3D Auto"}); createState(Pfad + '.' + airconId + '.Livedaten.CoolHotJudge', Boolean(ac_device[7]), {read: true, write: true, type: "boolean", unit:"", name: "CoolHotJudge"}); createState(Pfad + '.' + airconId + '.Livedaten.ModelNr', '' + ac_device[8], {read: true, write: false, type: "string", unit:"", name: "Model Nr"}); createState(Pfad + '.' + airconId + '.Livedaten.Vacant', Boolean(ac_device[9]), {read: true, write: true, type: "boolean", unit:"", name: "Vacant"}); createState(Pfad + '.' + airconId + '.Livedaten.Error', parseFloat(ac_device[10]), {read: true, write: false, type: "number", unit:"", name: "Error"}); createState(Pfad + '.' + airconId + '.Livedaten.IndoorTemp', parseFloat(ac_device[11]), {read: true, write: false, type: "number", unit:"°C", name: "Innentemperatur"}); createState(Pfad + '.' + airconId + '.Livedaten.OutdoorTemp', parseFloat(ac_device[12]), {read: true, write: false, type: "number", unit:"°C", name: "Aussentemperatur"}); createState(Pfad + '.' + airconId + '.Livedaten.Electric', parseFloat(ac_device[13]), {read: true, write: false, type: "number", unit:"", name: "Electric"}); setState(Pfad + '.' + airconId + '.Livedaten.running', Boolean(ac_device[0]),true); setState(Pfad + '.' + airconId + '.Livedaten.PresetTemp', parseFloat(ac_device[1]),true); setState(Pfad + '.' + airconId + '.Livedaten.Modus', '' + ac_device[2],true); setState(Pfad + '.' + airconId + '.Livedaten.Fan', '' + ac_device[3],true); setState(Pfad + '.' + airconId + '.Livedaten.WindUD', '' + ac_device[4],true); setState(Pfad + '.' + airconId + '.Livedaten.WindLR', '' + ac_device[5],true); setState(Pfad + '.' + airconId + '.Livedaten.3DAuto', Boolean(ac_device[6]),true); setState(Pfad + '.' + airconId + '.Livedaten.CoolHotJudge', Boolean(ac_device[7]),true); setState(Pfad + '.' + airconId + '.Livedaten.ModelNr', '' + ac_device[8],true); setState(Pfad + '.' + airconId + '.Livedaten.Vacant', Boolean(ac_device[9]),true); setState(Pfad + '.' + airconId + '.Livedaten.Error', parseFloat(ac_device[10]),true); setState(Pfad + '.' + airconId + '.Livedaten.IndoorTemp', parseFloat(ac_device[11]),true); setState(Pfad + '.' + airconId + '.Livedaten.OutdoorTemp', parseFloat(ac_device[12]),true); setState(Pfad + '.' + airconId + '.Livedaten.Electric', parseFloat(ac_device[13]),true); preset_new = ""; running_new = ""; auto3d_new = ""; CoolHotJudge_new = ""; Fan_new = ""; Modus_new = ""; vacant_new = ""; WindLR_new = ""; WindUD_new = ""; }