translator, wb_editors
4539
правок
Matveevrj (обсуждение | вклад) |
Matveevrj (обсуждение | вклад) |
||
Строка 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. | ||
The rule works like this: | The rule works like this: | ||
* when movement appears, the light turns on. If a thirty-second | * 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 | * when motion is lost, a thirty second «off» timer is started. If he manages to reach the end, the light turns off. | ||
<syntaxhighlight lang="ecmascript"> | <syntaxhighlight lang="ecmascript"> | ||
Строка 63: | Строка 61: | ||
var motion_timer_1_id = null; | var motion_timer_1_id = null; | ||
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 | 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 | 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> | ||
=== Creating similar rules === | === Creating similar rules === |