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.

77 lines
2.9 KiB

return {
on = {
timer = { 'every hour' }
},
data = {
old_value = { initial = 0 },
error_counter = { initial = 0 }
},
execute = function(domoticz, triggeredItem)
local update_time_short = 240
local update_time_long = 1440
local error_counter_max = 5
-- Test sensors for Time-Out
local dev_shortTimeout = { -- List of devices with short time outs. Every device needs a user variable *_st.
'Lichtstaerke_Wohnzimmer',
'Temperatur_Bad',
'Temperatur_Gaestebad',
}
local dev_longTimeout = { -- List of devices with long time outs.
'Tuer_Balkon',
'Rockrobo_Status'
}
local check_list_timeout_short = domoticz.devices().filter(dev_shortTimeout)
local check_list_timeout_long = domoticz.devices().filter(dev_longTimeout)
local function checktimeout(dev, timeout)
if (dev.lastUpdate.minutesAgo > timeout) then
if (domoticz.variables(dev.name .. '_timeout').value == 0) then
domoticz.variables(dev.name .. '_timeout').set(1)
domoticz.log(dev.name .. ' hat ein Time-Out.', domoticz.LOG_ERROR)
domoticz.email(dev.name, dev.name .. ' hat ein Time-Out.', 'pi@homeauto')
end
else
domoticz.log(dev.name .. ' hat sich gemeldet.', domoticz.LOG_INFO)
domoticz.variables(dev.name .. '_timeout').set(0)
end
end
check_list_timeout_short.forEach(function(device)
checktimeout(device, update_time_short)
end)
check_list_timeout_long.forEach(function(device)
checktimeout(device, update_time_long)
end)
-- Test temperatur sensor for stuck value
current_value = domoticz.devices('Temperatur_Balkon').temperature
if (current_value == domoticz.data.old_value) then
if (domoticz.data.error_counter < error_counter_max) then
domoticz.data.error_counter = domoticz.data.error_counter + 1
end
else
domoticz.data.error_counter = 0
end
if (domoticz.data.error_counter >= error_counter_max) then
if (domoticz.variables('Temperatur_Balkon_stuck').value == 0) then
domoticz.variables('Temperatur_Balkon_stuck').set(1)
domoticz.log(domoticz.devices('Temperatur_Balkon').name .. ' aendert den Wert nicht.', domoticz.LOG_ERROR)
domoticz.email(domoticz.devices('Temperatur_Balkon').name, domoticz.devices('Temperatur_Balkon').name .. ' aendert den Wert nicht.', 'pi@homeauto')
end
elseif (domoticz.data.error_counter == 0) then
domoticz.variables('Temperatur_Balkon_stuck').set(0)
end
domoticz.data.old_value = current_value
end
}