defineVirtualDevice("V_switches", { title: "Virtual switches", cells: { "V_switch1": { // Гостиная type: "switch", value: false }, "V_switch2": { // Кухня type: "switch", value: false }, "V_switch3": { // Коридор type: "switch", value: false }, "V_switch4": { // Спальня type: "switch", value: false }, "V_switch5": { // Гардеробная type: "switch", value: false }, "V_switch6": { // Санузел спальни type: "switch", value: false }, "V_switch7": { // Детская type: "switch", value: false }, "V_switch8": { // Гостевая type: "switch", value: false }, "V_switch9": { // Ванная детской и гостевой type: "switch", value: false }, "V_switch10": { // Туалет детской и гостевой type: "switch", value: false }, "V_switch11": { // Прихожая type: "switch", value: false }, "V_switch12": { // Туалет гостевой type: "switch", value: false }, "V_switch13": { // Мастер выключатель type: "switch", value: false } } }); function action1_1() { // Гостиная on //log("action1_1"); dev["MR6C_4"]["K3"] = true; dev["MR6C_4"]["K5"] = true; } function action1_2() { // Гостиная off //log("action1_2"); dev["MR6C_4"]["K1"] = false; dev["MR6C_4"]["K3"] = false; dev["MR6C_4"]["K5"] = false; } function action2_1() { // Кухня on //log("action2_1"); dev["MR6C_4"]["K4"] = true; } function action2_2() { // Кухня off //log("action2_2"); dev["MR6C_4"]["K2"] = false; dev["MR6C_4"]["K4"] = false; dev["MR6C_4"]["K6"] = false; //dev["ZigBeeRelay_2.1"]["Relay L1"] = false; //dev["ZigBeeRelay_2.1"]["Relay L2"] = false; } function action3_1() { // Коридор on //log("action3_1"); dev["MR6C_1"]["K5"] = true; } function action3_2() { // Коридор off //log("action3_2"); dev["MR6C_1"]["K5"] = false; dev["MR6C_1"]["K6"] = false; dev["MR6C_2"]["K5"] = false; } function action4_1() { // Спальня on //log("action4_1"); dev["MR6C_6"]["K1"] = true; dev["MR6C_6"]["K4"] = true; dev["MR6C_6"]["K5"] = true; } function action4_2() { // Спальня off //log("action4_2"); dev["MR6C_6"]["K1"] = false; dev["MR6C_6"]["K2"] = false; dev["MR6C_6"]["K4"] = false; dev["MR6C_6"]["K5"] = false; } function action5_1() { // Гардеробная on //log("action5_1"); dev["MR6C_5"]["K2"] = true; } function action5_2() { // Гардеробная off //log("action5_2"); dev["MR6C_5"]["K1"] = false; dev["MR6C_5"]["K2"] = false; dev["MR6C_5"]["K3"] = false; dev["MR6C_5"]["K4"] = false; dev["MR6C_5"]["K5"] = false; dev["MR6C_6"]["K3"] = false; } function action6_1() { // Санузел спальни on //log("action6_1"); dev["MR6C_7"]["K3"] = true; dev["MR6C_7"]["K6"] = true; } function action6_2() { // Санузел спальни off //log("action6_2"); dev["MR6C_7"]["K1"] = false; dev["MR6C_7"]["K2"] = false; dev["MR6C_7"]["K3"] = false; dev["MR6C_7"]["K4"] = false; dev["MR6C_7"]["K5"] = false; dev["MR6C_7"]["K6"] = false; dev["MR6C_6"]["K6"] = false; dev["MR6C_12"]["K4"] = false; } function action7_1() { // Детская on //log("action7_1"); dev["MR6C_1"]["K2"] = true; } function action7_2() { // Детская off //log("action7_2"); dev["MR6C_1"]["K1"] = false; dev["MR6C_1"]["K2"] = false; dev["MR6C_1"]["K3"] = false; dev["MR6C_1"]["K4"] = false; } function action8_1() { // Гостевая on //log("action8_1"); dev["MR6C_2"]["K2"] = true; } function action8_2() { // Гостевая off //log("action8_2"); dev["MR6C_2"]["K1"] = false; dev["MR6C_2"]["K2"] = false; dev["MR6C_2"]["K3"] = false; dev["MR6C_2"]["K4"] = false; } function action9_1() { // Ванная детской и гостевой on //log("action9_1"); dev["MR6C_3"]["K3"] = true; } function action9_2() { // Ванная детской и гостевой off //log("action9_2"); dev["MR6C_3"]["K3"] = false; dev["MR6C_3"]["K4"] = false; dev["MR6C_3"]["K5"] = false; } function action10_1() { // Туалет детской и гостевой on //log("action10_1"); dev["MR6C_3"]["K1"] = true; } function action10_2() { // Туалет детской и гостевой off //log("action10_2"); dev["MR6C_3"]["K1"] = false; dev["MR6C_3"]["K2"] = false; } function action11_1() { // Прихожая on //log("action11_1"); dev["MR6C_8"]["K1"] = true; } function action11_2() { // Прихожая off //log("action11_2"); dev["MR6C_8"]["K1"] = false; dev["MR6C_8"]["K2"] = false; dev["MR6C_8"]["K3"] = false; } function action12_1() { // Туалет гостевой on //log("action12_1"); dev["MR6C_8"]["K4"] = true; } function action12_2() { // Туалет гостевой off //log("action12_2"); dev["MR6C_8"]["K4"] = false; dev["MR6C_8"]["K5"] = false; dev["MR6C_8"]["K6"] = false; dev["MR6C_12"]["K1"] = false; } function action13_1() { // Мастер выключатель on //log("action13_1"); dev["MR6C_4"]["K5"] = true; //dev["MR6C_0"]["K0"] = true; //dev["MR6C_0"]["K0"] = true; //dev["MR6C_0"]["K0"] = true; } function action13_2() { // Мастер выключатель off //log("action13_2"); action1_2(); action2_2(); action3_2(); action4_2(); action5_2(); action6_2(); action7_2(); action8_2(); action9_2(); action10_2(); action11_2(); action12_2(); } /* function action2_3() { // Кухня двойное нажатие 2.3 log("action2_3"); if (dev["V_switches"]["V_switch2"]) { action2_2(); } else { action2_1(); } } function action4_3() { // Гардеробная двойное нажатие 4.3 log("action4_3"); if (dev["V_switches"]["V_switch4"]) { action4_2(); } } function action5_4() { // Ванная двойное нажатие 5.2 log("action5_4"); if (dev["V_switches"]["V_switch5"]) { dev["wb-mr6c_199"]["K1"] = false; dev["wb-mr6c_199"]["K2"] = false; dev["wb-mr6c_199"]["K3"] = false; } } */ function ButtonTrue(ruleName, devId, devParam, func) { defineRule(ruleName, { whenChanged: devId + "/" + devParam, then: function(value, device, param) { log(ruleName + " " + devId + " " + devParam); if (value) { func(); } } }); } function ButtonFalse(ruleName, devId, devParam, func) { defineRule(ruleName, { whenChanged: devId + "/" + devParam, then: function(value, device, param) { if (!value) { func(); } } }); } function ButtonDouble(ruleName, devId, devParam, func) { var needInit = true; var prevValue = 0; defineRule(ruleName, { whenChanged: devId + "/" + devParam, then: function(newValue, device, param) { if (needInit) { prevValue = newValue; needInit = false; } else if (newValue != prevValue) { prevValue = newValue; func(); } } }); } masterChannelsArray = []; function GroupFeedback(ruleName, devId, devParam, channelsArray, master) { if (!master) { masterChannelsArray = masterChannelsArray.concat(channelsArray); //log("ruleName: " + masterChannelsArray) } var check = function() { var someIsOn = false; for (var i = 0; i < channelsArray.length; i++) { if (dev[channelsArray[i]]) { someIsOn = true; break; } } return someIsOn; } var draw = function(state) { getDevice(devId).getControl(devParam).setValue({value:state, notify:false}); } var state = check(); draw(state); defineRule(ruleName, { whenChanged: channelsArray, then: function(value, device, param) { var someIsOn = check(); if (!state && someIsOn) { state = true; draw(true); } else if (state && !someIsOn) { state = false; draw(false); } } }); } ButtonTrue("RuleVSwitch1True", "V_switches", "V_switch1", action1_1); // Гостиная on ButtonFalse("RuleVSwitch1False", "V_switches", "V_switch1", action1_2); // Гостиная off GroupFeedback("RuleVSwitch1Feedback", "V_switches", "V_switch1", ["MR6C_4/K1", "MR6C_4/K3", "MR6C_4/K5"]); ButtonTrue("RuleVSwitch2True", "V_switches", "V_switch2", action2_1); // Кухня on ButtonFalse("RuleVSwitch2False", "V_switches", "V_switch2", action2_2); // Кухня off GroupFeedback("RuleVSwitch2Feedback", "V_switches", "V_switch2", ["MR6C_4/K2", "MR6C_4/K4", "MR6C_4/K6"]); //, "ZigBeeRelay_2.1/Relay L1", "ZigBeeRelay_2.1/Relay L2" ButtonTrue("RuleVSwitch3True", "V_switches", "V_switch3", action3_1); // Коридор on ButtonFalse("RuleVSwitch3False", "V_switches", "V_switch3", action3_2); // Коридор off GroupFeedback("RuleVSwitch3Feedback", "V_switches", "V_switch3", ["MR6C_1/K5", "MR6C_1/K6", "MR6C_2/K5"]); ButtonTrue("RuleVSwitch4True", "V_switches", "V_switch4", action4_1); // Спальня on ButtonFalse("RuleVSwitch4False", "V_switches", "V_switch4", action4_2); // Спальня off GroupFeedback("RuleVSwitch4Feedback", "V_switches", "V_switch4", ["MR6C_6/K1", "MR6C_6/K2", "MR6C_6/K4", "MR6C_6/K5"]); ButtonTrue("RuleVSwitch5True", "V_switches", "V_switch5", action5_1); // Гардеробная on ButtonFalse("RuleVSwitch5False", "V_switches", "V_switch5", action5_2); // Гардеробная off GroupFeedback("RuleVSwitch5Feedback", "V_switches", "V_switch5", ["MR6C_5/K1", "MR6C_5/K2", "MR6C_5/K3", "MR6C_5/K4", "MR6C_5/K5", "MR6C_6/K3"]); ButtonTrue("RuleVSwitch6True", "V_switches", "V_switch6", action6_1); // Санузел спальни on ButtonFalse("RuleVSwitch6False", "V_switches", "V_switch6", action6_2); // Санузел спальни off GroupFeedback("RuleVSwitch6Feedback", "V_switches", "V_switch6", ["MR6C_7/K1", "MR6C_7/K2", "MR6C_7/K3", "MR6C_7/K4", "MR6C_7/K5", "MR6C_7/K6", "MR6C_6/K6", "MR6C_12/K4"]); ButtonTrue("RuleVSwitch7True", "V_switches", "V_switch7", action7_1); // Детская on ButtonFalse("RuleVSwitch7False", "V_switches", "V_switch7", action7_2); // Детская off GroupFeedback("RuleVSwitch7Feedback", "V_switches", "V_switch7", ["MR6C_1/K1", "MR6C_1/K2", "MR6C_1/K3", "MR6C_1/K4"]); ButtonTrue("RuleVSwitch8True", "V_switches", "V_switch8", action8_1); // Гостевая on ButtonFalse("RuleVSwitch8False", "V_switches", "V_switch8", action8_2); // Гостевая off GroupFeedback("RuleVSwitch8Feedback", "V_switches", "V_switch8", ["MR6C_2/K1", "MR6C_2/K2", "MR6C_2/K3", "MR6C_2/K4"]); ButtonTrue("RuleVSwitch9True", "V_switches", "V_switch9", action9_1); // Ванная детской и гостевой on ButtonFalse("RuleVSwitch9False", "V_switches", "V_switch9", action9_2); // Ванная детской и гостевой off GroupFeedback("RuleVSwitch9Feedback", "V_switches", "V_switch9", ["MR6C_3/K3", "MR6C_3/K4", "MR6C_3/K5"]); ButtonTrue("RuleVSwitch10True", "V_switches", "V_switch10", action10_1); // Туалет детской и гостевой on ButtonFalse("RuleVSwitch10False", "V_switches", "V_switch10", action10_2); // Туалет детской и гостевой off GroupFeedback("RuleVSwitch10Feedback", "V_switches", "V_switch10", ["MR6C_3/K1", "MR6C_3/K2"]); ButtonTrue("RuleVSwitch11True", "V_switches", "V_switch11", action11_1); // Прихожая on ButtonFalse("RuleVSwitch11False", "V_switches", "V_switch11", action11_2); // Прихожая off GroupFeedback("RuleVSwitch11Feedback", "V_switches", "V_switch11", ["MR6C_8/K1", "MR6C_8/K2", "MR6C_8/K3"]); ButtonTrue("RuleVSwitch12True", "V_switches", "V_switch12", action12_1); // Туалет гостевой on ButtonFalse("RuleVSwitch12False", "V_switches", "V_switch12", action12_2); // Туалет гостевой off GroupFeedback("RuleVSwitch12Feedback", "V_switches", "V_switch12", ["MR6C_8/K4", "MR6C_8/K5", "MR6C_8/K6", "MR6C_12/K1"]); ButtonTrue("RuleVSwitch13True", "V_switches", "V_switch13", action13_1); // Мастер выключатель on ButtonFalse("RuleVSwitch13False", "V_switches", "V_switch13", action13_2); // Мастер выключатель off GroupFeedback("RuleVSwitch13Feedback", "V_switches", "V_switch13", masterChannelsArray, true); //ButtonDouble("RuleDoublePress_mr6c_141_in2", "wb-mr6c_141", "Input 2 Double Press Counter", action2_3); // Кухня двойное нажатие 2.3 //ButtonDouble("RuleDoublePress_mr6c_141_in6", "wb-mr6c_141", "Input 6 Double Press Counter", action4_3); // Гардеробная двойное нажатие 4.3 //ButtonDouble("RuleDoublePress_mr6c_199_in2", "wb-mr6c_199", "Input 2 Double Press Counter", action5_4); // Ванная двойное нажатие 5.1 var k;