defineVirtualDevice("CurrentValue2", { title: "Rs-485-1-errors", cells: { dev_46: {type: "value", value: 0, forceDefault: false}, dev_reboot: {type: "switch", value: false, forceDefault: false}, } }); defineRule("rebootAllDevices-1",{ asSoonAs: function() { return (dev["CurrentValue2/dev_reboot"] == true); }, then: function () { setTimeout(function () { setTimeout(function () { dev["wb-mr6c_46/reboot_control"] = 1; }, 1000); dev["CurrentValue2/dev_reboot"] = false; }, 1000); } }); function check_relay2(id) { defineRule("check-relay-{}".format(id), { whenChanged: function () { return (dev["wb-mr6c_{}".format(id)]["Supply Voltage#error"]); }, then: function (newValue) { setTimeout(function () { log (newValue); }, 500); if (newValue == "r") { setTimeout(function () { log('Ошибка связи с реле: wb-mr6c_{}'.format(id)); dev["CurrentValue2"]["dev_{}".format(id)] = 0; }, 30); } if (newValue != "r") { dev["CurrentValue2"]["dev_{}".format(id)] = 1; log('Связь с реле: wb-mr6c_{} присутствует на шине'.format(id)); log (newValue); } log ('Устройство "wb-mr6c_{}" в работе'.format(id)) } }); } check_relay2(46);