(function() { var knx_vdev_obj = { title: "KNX Group Addresses", cells: { // ------ ТРЕНАЖЕРКА ----- // "3-1-0": { //AC on/off Fb type: "switch", value: false, readonly : true }, "3-1-7": { //Setpoint Fb type: "temperature", value: 0, knx_type: "wide" }, "3-1-8": { //Current Temp type: "temperature", value: 0, knx_type: "wide" }, "3-1-11": { //Heating type: "switch", value: false, readonly : true }, "3-1-12": { //Cooling type: "switch", value: false, readonly : true }, "3-1-6": { //Mode type: "range", value: 0, max: 3, readonly : false }, // ------ ГОСТИНАЯ ----- // "3-2-0": { //AC on/off Fb type: "switch", value: false, readonly : true }, "3-2-7": { //Setpoint Fb type: "temperature", value: 0, knx_type: "wide" }, "3-2-8": { //Current Temp type: "temperature", value: 0, knx_type: "wide" }, "3-2-11": { //Heating type: "switch", value: false, readonly : true }, "3-2-12": { //Cooling type: "switch", value: false, readonly : true }, "3-2-6": { //Mode type: "range", value: 0, max: 3, readonly : false }, // ------ ГОСТЕВАЯ ----- // "3-3-0": { //AC on/off Fb type: "switch", value: false, readonly : true }, "3-3-7": { //Setpoint Fb type: "temperature", value: 0, knx_type: "wide" }, "3-3-8": { //Current Temp type: "temperature", value: 0, knx_type: "wide" }, "3-3-11": { //Heating type: "switch", value: false, readonly : true }, "3-3-12": { //Cooling type: "switch", value: false, readonly : true }, "3-3-6": { //Mode type: "range", value: 0, max: 3, readonly : false }, // ------ РОЗЕТКИ ----- // "2-1-0": { //Розетки ММ ВКЛ / ВЫКЛ Постирочная type: "pushbutton", value: true, readonly : false }, "2-1-1": { //Розетки ММ ВКЛ / ВЫКЛ Гостиная type: "pushbutton", value: true, readonly : false }, "2-1-2": { //Розетки ММ ВКЛ / ВЫКЛ Кухня type: "pushbutton", value: true, readonly : false }, "2-1-3": { //Розетки ММ ВКЛ / ВЫКЛ Спальня type: "pushbutton", value: true, readonly : false }, "2-1-4": { //Розетки ММ ВКЛ / ВЫКЛ Кабинет type: "pushbutton", value: true, readonly : false }, "2-1-5": { //Розетки ММ ВКЛ / ВЫКЛ Шкаф СС type: "pushbutton", value: true, readonly : false } } }; var vdev_when_changed = []; var vdev_devid = "knx_group_addrs"; for (var control_id in knx_vdev_obj.cells) { if (knx_vdev_obj.cells.hasOwnProperty(control_id)) { vdev_when_changed.push("knx_group_addrs/" + control_id); } } defineVirtualDevice(vdev_devid, knx_vdev_obj); defineRule("knx_vdev_feedback", { whenChanged: vdev_when_changed, then: function(newValue, devName, cellName) { var group_address = cellName.split("-").join("/"); var value = +newValue; log("knx vdev rule {} {} {} {}", newValue, devName, cellName, value); var write_str = ""; if (knx_vdev_obj.cells[cellName].knx_type == "wide") { while (value > 0) { var rem = value % 256; value = Math.floor(value / 256); write_str = rem + " " + write_str; } write_str = "0 " + write_str; } else { write_str = "" + value; } if (write_str) { /* if (knx_vdev_obj.cells[cellName].dpt == 9){ log("value = {}",write_str); dev["knx/data"] = "g:{} GroupValueWrite {}".format(group_address, toEIS(write_str)); log("value = {}",toEIS(write_str)); } */ dev["knx/data"] = "g:{} GroupValueWrite {}".format(group_address, write_str); } } }); defineRule("knx_vdev_incoming", { whenChanged: "knx/data", then: function(newValue, devName, cellName) { var arr = newValue.split(/\s/); var sourceAddr = arr[0].split(/i\:|\,/); var groupAddr = arr[1].split(/g\:|\,/); var arr1 = newValue.split(/GroupValueWrite/); var value = arr1[1]; if ((sourceAddr[1] == "0/0/0") || (sourceAddr[1] == "1/1/255")) { // skip local echo return; } log("knx vdev incoming rule {}", newValue); if (value.length <=6) { dev[vdev_devid][groupAddr[1].split("/").join("-")] = parseInt(value, 16); } else{ dev[vdev_devid][groupAddr[1].split("/").join("-")] = fromEIS(value); } } }); })() function fromEIS(encoded) { var decimals = 2; encoded = encoded.replace(/ 0x/g,''); encoded = '0x' + encoded; log("encoded={}",encoded); var int = encoded; var sign = !!(int & 0x8000); var exp = (int & 0x7800) >> 11; var mant = int & 0x7FF; if (sign) { mant = -(~(mant - 1) & 0x07FF); } var value = (0.01 * mant) * Math.pow(2, exp); return parseFloat(value.toFixed(decimals)); }; /* function toEIS(value) { value = value.replace(/0 /g,''); var sign = 0; var exp = 0; if (value < 0) { sign = 1; } var mant = Math.floor(value * 100); while ((mant < -2048) || (mant > 2047)) { mant = mant >> 1; exp += 1 } var data = (sign << 15) | (exp << 11) | (mant & 0x07ff); return '0b110111' + ' 0x' + (data+0x10000).toString(16).substr(1,2) + ' 0x' + (data+0x100).toString(16).substr(-2); }; */