I'm trying to script two motion sensors for the kitchen. The following script that I contribute works fine, but if I turn off the light manually using the switch, the "kitchen light" device logically goes off. But since the two sensors are still "on" a strange situation occurs. When the first sensor goes "off" this sensor triggers the script again and as the second sensor is still "on" for a few seconds, the result is that the kitchen light turns on for a few seconds and turns off.
Code: Select all
return {
on = {
devices = { 'movimiento cocina' , 'movimiento cocina2' }
},
execute = function(domoticz, device)
if ((domoticz.devices('movimiento cocina').state == 'On') or (domoticz.devices('movimiento cocina2').state == 'On')) then
domoticz.devices('Luz cocina').switchOn()
end
-------------------------------------- APAGADO
if (domoticz.devices('movimiento cocina').state == 'Off') and (domoticz.devices('movimiento cocina2').state == 'Off') and (domoticz.devices('cocina indefinido').state == 'Off') then
domoticz.devices('Luz cocina').switchOff().checkFirst()
elseif (domoticz.devices('movimiento cocina').state == 'Off') and (domoticz.devices('movimiento cocina2').state == 'Off') and (domoticz.devices('cocina indefinido').state == 'On') then
domoticz.devices('Luz cocina').switchOff().afterSec(300)
domoticz.devices('cocina indefinido').switchOff().afterSec(360)
end
end
}
I have tried to make a similar script with "item", but when one of the two sensors goes "off" then the kitchen light turns off and the other sensor is still "on" for a few seconds, I would like the light to continues on and that go to off when both sensors are "off"
Code: Select all
return {
on = {
devices = { 'movimiento cocina' , 'movimiento cocina2' }
},
execute = function(domoticz, item)
if (item.isDevice and item.active) then
domoticz.devices('Luz cocina').switchOn()
end
if item.state == "Off" then
domoticz.devices('Luz cocina').switchOff()
elseif item.state == "Off" and domoticz.devices('Luz cocina').state == 'On' then -- and (domoticz.devices('cocina indefinido').state == 'On')
domoticz.devices('Luz cocina').switchOff().afterSec(300).checkFirst()
domoticz.devices('cocina indefinido').switchOff().afterSec(306).checkFirst()
---------- si yo la apago manualmente si el interruptor indefinido cocina = on pues apaga la luz a los 300 segundos (que ya esta apagada) y apaga el interruptor indefinido
elseif item.state == "Off" and (domoticz.devices('cocina indefinido').state == 'On') and domoticz.devices('Luz cocina').state == 'Off' then
domoticz.devices('Luz cocina').switchOff().afterSec(300).checkFirst()
domoticz.devices('cocina indefinido').switchOff().afterSec(306).checkFirst()
end
end
}