--[[ -- Lampa + czujnik Skrypt po naruszeniu PIR aktywuje lampe na ustawiony czas kazde nastepne naruszenia w tym czasie resetuja licznik i czas liczony jest od nowa po wlaczeniu lampy prez przycisk, lub z poziomu Domoticz (brak aktywnego PIR), lampa pozostaje wlaczona do czasu jej recznego wylaczenia ]]-- return { on = { devices = { 'sonoff', -- nazwa wlacznik w domoticz 'PIR ' -- nazwa czujnika w domoticz } }, data = { warunek = { initial = false }, }, logging = { level = domoticz.LOG_ERROR, marker = 'PIR Lampa', }, execute = function(dz, item) local maxSeconds = 120 local motion = dz.devices('PIR') -- nazwa czujnika local switch = dz.devices('sonoff') -- nazwa włacznika if item == motion then -- detekcja aktywna if motion.state == 'On' and switch.state == 'Off' then -- detekcja wyzwala skrypt dz.data.warunek = true switch.cancelQueuedCommands() switch.switchOn().checkFirst() elseif motion.state == 'On' and switch.state == 'On' and dz.data.warunek == true then switch.cancelQueuedCommands() elseif motion.state == 'Off' and dz.data.warunek == true then switch.switchOff().afterSec(maxSeconds).checkFirst() end elseif item == switch and item.state == 'On' and motion.state == 'Off' then dz.data.warunek = false end end }