Перейти к содержанию

Навигация

Rule Examples/en: различия между версиями

Нет описания правки
Строка 53: Строка 53:
The lighting is connected via a built-in relay corresponding to the <code>wb-gpio/Relay_1</code> channel.
The lighting is connected via a built-in relay corresponding to the <code>wb-gpio/Relay_1</code> channel.


<div class="mw-translate-fuzzy">
The rule works like this:
The rule works like this:
* when movement appears, the light turns on. If a thirty-second "off" timer was previously started, this timer is disabled;
* when movement appears, the light turns on. If a thirty-second «off» timer was previously started, this timer is disabled;
* when motion is lost, a thirty second "off" timer is started. If he manages to reach the end, the light turns off.
* when motion is lost, a thirty second «off» timer is started. If he manages to reach the end, the light turns off.
</div>


<syntaxhighlight lang="ecmascript">
<syntaxhighlight lang="ecmascript">
Строка 63: Строка 61:
var motion_timer_1_id = null;
var motion_timer_1_id = null;


<div class="mw-translate-fuzzy">
defineRule("motion_detector_1", {
defineRule("motion_detector_1", {
     whenChanged: "wb-gpio/D2_IN",
     whenChanged: "wb-gpio/D2_IN",
     then: function (newValue, devName, cellName) {
     then: function (newValue, devName, cellName) {
         if (newValue) {
         if (newValue) {
             dev["wb-gpio"]["Relay_1"] = true;
             dev["wb-gpio/Relay_1"] = true;
             if (motion_timer_1_id) {
             if (motion_timer_1_id) {
                 clearTimeout(motion_timer_1_id);
                 clearTimeout(motion_timer_1_id);
             }
             }
             motion_timer_1_id = setTimeout(function () {
             motion_timer_1_id = setTimeout(function () {
                 dev["wb-gpio"]["Relay_1"] = false;
                 dev["wb-gpio/Relay_1"] = false;
                 motion_timer_1_id = null;
                 motion_timer_1_id = null;
             }, motion_timer_1_timeout_ms);
             }, motion_timer_1_timeout_ms);
Строка 80: Строка 77:
});
});
</syntaxhighlight>
</syntaxhighlight>
</div>


=== Creating similar rules ===
=== Creating similar rules ===
translator, wb_editors
4265

правок