wb_editors
14 457
правок
Matveevrj (обсуждение | вклад) |
FuzzyBot (обсуждение | вклад) (Обновление для соответствия новой версии исходной страницы.) |
||
(не показано 7 промежуточных версий 1 участника) | |||
Строка 1: | Строка 1: | ||
<languages/> | <languages/> | ||
{{DISPLAYTITLE: Rule Examples}} | |||
=== Control tracking === | === Control tracking === | ||
Строка 292: | Строка 293: | ||
}); | }); | ||
defineRule("water_meter_1", { | defineRule("water_meter_1", { | ||
whenChanged: "wb-mcm8_29/Input 1 counter", | whenChanged: "wb-mcm8_29/Input 1 counter", | ||
then: function(newValue, devName, cellName) { | then: function(newValue, devName, cellName) { | ||
if(newValue){ | if(newValue){ | ||
dev["water_meters | dev["water_meters/water_meter_1"] = ((parseInt(newValue) - counterCorrection) * inpulseValue) + meterCorrection; // We multiply the value of the counter by the number of liters / pulse and add the correction value. | ||
} | } | ||
} | } | ||
}); | }); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== Handling click counters == | == Handling click counters == | ||
Строка 430: | Строка 429: | ||
var co2_bad = newValue > 1001; | var co2_bad = newValue > 1001; | ||
if (co2_good) { | |||
if (co2_good) { | dev["devName/Green LED"] = true; | ||
dev[devName | dev["devName/Red LED"] = false; | ||
dev[devName | dev["devName/LED Period (s)"] = 10; | ||
dev[devName | |||
} | } | ||
if (co2_middle) { | if (co2_middle) { | ||
dev[devName | dev["devName/Green LED"] = true; | ||
dev[devName | dev["devName/Red LED"] = true; | ||
dev[devName | dev["devName/LED Period (s)"] = 5; | ||
} | } | ||
if (co2_bad) { | if (co2_bad) { | ||
dev[devName | dev["devName/Green LED"] = false; | ||
dev[devName | dev["devName/Red LED"] = true; | ||
dev[devName | dev["devName/LED Period (s)"] = 1; | ||
} | } | ||
} | } | ||
Строка 452: | Строка 450: | ||
=== Max Motion === | === Max Motion === | ||
"Max Motion" - the maximum value of the motion sensor for N time. Time from 1 to 60 seconds can be set in register 282. The default is 10 seconds. When the Max Motion value reaches 50, we check whether the room is sufficiently lit, if not, turn on the light. As soon as the Max Motion value drops below 50, turn off the light. | "Max Motion" - the maximum value of the motion sensor for N time. Time from 1 to 60 seconds can be set in register 282. The default is 10 seconds. When the Max Motion value reaches 50, we check whether the room is sufficiently lit, if not, turn on the light. As soon as the Max Motion value drops below 50, turn off the light. | ||
<div class="NavFrame"> | <div class="NavFrame"> | ||
<div class="NavContent"> | <div class="NavContent"> | ||
Строка 462: | Строка 458: | ||
then: function(newValue, devName, cellName) { | then: function(newValue, devName, cellName) { | ||
if (newValue > 50) { | if (newValue > 50) { | ||
if (dev["wb-msw-v3_97 | if (dev["wb-msw-v3_97/Illuminance"] < 50) { | ||
dev["wb-mr3_11 | dev["wb-mr3_11/K1"] = true; | ||
} | } | ||
} else { | } else { | ||
dev["wb-mr3_11 | dev["wb-mr3_11/K1"] = false; | ||
} | } | ||
} | } | ||
}); | }); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
</div> | </div> | ||
</div> | </div> | ||
Строка 584: | Строка 579: | ||
defineRule("_system_track_vin", { | defineRule("_system_track_vin", { | ||
whenChanged: "wb-adc/Vin", | whenChanged: "wb-adc/Vin", | ||
then: function() { | then: function() { | ||
if (dev["wb-adc | if (dev["wb-adc/Vin"] < dev["wb-adc/BAT"] ) { | ||
dev["power_status | dev["power_status/Vin"] = 0; | ||
} else { | } else { | ||
dev["power_status | dev["power_status/Vin"] = dev["wb-adc/Vin"] ; | ||
} | } | ||
} | } | ||
}); | }); | ||
defineRule("_system_dc_on", { | defineRule("_system_dc_on", { | ||
asSoonAs: function () { | asSoonAs: function () { | ||
return dev["wb-adc | return dev["wb-adc/Vin"] > dev["wb-adc/BAT"]; | ||
}, | }, | ||
then: function () { | then: function () { | ||
dev["power_status | dev["power_status/working on battery"] = false; | ||
} | } | ||
}); | }); | ||
defineRule("_system_dc_off", { | defineRule("_system_dc_off", { | ||
asSoonAs: function () { | asSoonAs: function () { | ||
return dev["wb-adc | return dev["wb-adc/Vin"] <= dev["wb-adc/BAT"]; | ||
}, | }, | ||
then: function () { | then: function () { | ||
dev["power_status | dev["power_status/working on battery"] = true; | ||
} | } | ||
}); | }); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Строка 942: | Строка 931: | ||
Not cron-rules are used for schedules, but the libschedule. The libschedule enables and disables rules, which, unlike cron rules, are executed continuously when enabled. | Not cron-rules are used for schedules, but the libschedule. The libschedule enables and disables rules, which, unlike cron rules, are executed continuously when enabled. | ||
For example, we want the lighting to be on from 10 to 17h. The libschedule will follow the «turn on the lights» rule once a minute from 10 am to 17 PM. | |||
For example, we want the lighting to be on from 10 to 17h. The libschedule will follow the | |||
This means that even if the controller is running intermittently and missed the transition time between schedules (10 am), the controller will still turn on the lights at the first opportunity. | This means that even if the controller is running intermittently and missed the transition time between schedules (10 am), the controller will still turn on the lights at the first opportunity. |