The idea to have an automated light in the bathroom using a door and a PIR sensors.
It's quite challenging, taking into account that someone from the family uses WC without closing the door during night hours or do not close the door when leave the bathroom or temporary leave the bathroom, etc.
Unfortunately, i could find a script example, so I have to made mine.
Of course, having the loges only from this particular script will help me to fine-tune it.
Code: Select all
return {
on = {
devices = {
'Bathroom 2nd Floor PIR',
'Bathroom 2nd Floor Door Sensor'
},
logging = {
level = domoticz.LOG_DEBUG,
marker = 'WC'
},
},
execute = function(domoticz, device)
domoticz.log('Device ' .. device.name .. ' was changed', domoticz.LOG_INFO)
if (device.name == 'Bathroom 2nd Floor PIR' and device.active) then
domoticz.devices('Bathroom 2nd Floor Light').switchOn().checkFirst()
domoticz.log('Hey! I got Light')
elseif (domoticz.devices('Bathroom 2nd Floor PIR').state == 'Off') then
domoticz.log('Hey! Stay Light On')
elseif (domoticz.devices('Bathroom 2nd Floor Door Sensor').state == 'Open' and (domoticz.devices('Bathroom 2nd Floor PIR').state == 'On')) then
domoticz.log('Hey! Light to be OFF')
domoticz.devices('Bathroom 2nd Floor Light').switchOff().afterSec(160)
elseif (domoticz.devices('Bathroom 2nd Floor Door Sensor').state == 'Open' and (domoticz.devices('Bathroom 2nd Floor PIR').state == 'Off')) then
domoticz.log('Hey! Light to be OFF')
domoticz.devices('Bathroom 2nd Floor Light').switchOff()
else
domoticz.log('Not definded!')
end
end
}