Scripts for my smart home setup.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
2.2 KiB

return {
on = {
devices = {
'Tuer_Balkon'
}
},
data = {
old_state = { initial = 0},
old_lvl = { initial = 0},
unlock_time = { initial = 0}
},
execute = function(domoticz, item)
local lvl_min = 30
local update_time_max = 2 -- If the door is open for longer than this time, do not command the roller blinds down again.
current_state = domoticz.devices('Tuer_Balkon').state
current_lvl = domoticz.devices('Rollladen_Wohnzimmer3').level
trigger_time = domoticz.time
-- Initialisation.
if (domoticz.data.unlock_time == 0) then
domoticz.data.unlock_time = domoticz.time
end
if (current_state == 'Unlocked' and domoticz.data.old_state == 'Locked' and current_lvl >= lvl_min and current_lvl < 99) then -- Sometimes an open roller blind is shown with 99%?
domoticz.data.old_lvl = current_lvl -- Save current position.
domoticz.data.unlock_time = domoticz.time -- Save current time.
domoticz.log('Lüften, mache die Rollladen hoch. Gespeicherte Position: ' .. domoticz.data.old_lvl .. '%. Gespeicherte Zeit: ' .. domoticz.data.unlock_time.rawTime, domoticz.LOG_INFO)
domoticz.devices('Rollladen_Wohnzimmer3').switchOff()
elseif (current_state == 'Locked' and domoticz.data.old_state == 'Unlocked' and domoticz.time.compare(domoticz.data.unlock_time).mins < update_time_max) then
domoticz.log('Lüften vorbei, stelle die Rollladen auf die gespeicherte Position: ' .. domoticz.data.old_lvl .. '%', domoticz.LOG_INFO)
domoticz.devices('Rollladen_Wohnzimmer3').dimTo(domoticz.data.old_lvl)
domoticz.data.old_lvl = 0 -- Reset the saved position.
domoticz.data.unlock_time = domoticz.time -- Reset the saved time.
elseif (current_state == 'Locked' and domoticz.data.old_state == 'Unlocked' and domoticz.time.compare(domoticz.data.unlock_time).mins >= update_time_max) then
domoticz.log('Tür war zu lange offen, alles wird zurückgesetzt.', domoticz.LOG_INFO)
domoticz.data.old_lvl = 0
domoticz.data.unlock_time = domoticz.time
end
domoticz.data.old_state = current_state
end
}