-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMotion Time.lua
60 lines (49 loc) · 1.79 KB
/
Motion Time.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
local function updateWakeThreshold(domoticz, value)
if domoticz.devices('Wake Threshold').text ~= tostring(value) then domoticz.devices('Wake Threshold').updateText(tostring(value)) end
end
local function allowedToAwake()
time = os.date("*t")
allowed = (time.hour >= 9) and (time.hour <= 12)
return allowed
end
local function allowedToAutoAway(domoticz)
time = os.date("*t")
return (time.hour >= 9) and (time.hour <= 21)
and not domoticz.devices('PERSON_1').active
and not domoticz.devices('PERSON_2').active
end
local function updatedLongAgo(motion)
return motion.lastUpdate.minutesAgo > 30
end
local function wakeThreshold(domoticz, motion, on)
timeSinceUpdate = motion.lastUpdate.minutesAgo
if (not on and timeSinceUpdate > 30) then
updateWakeThreshold(domoticz, 0)
elseif (on and timeSinceUpdate > 10) then
return true
end
return false
end
return {
on = {
timer = { 'every minute' }
},
logging = {
level = domoticz.LOG_FORCE,
marker = "Motion Time"
},
execute = function(domoticz, timer)
motion = domoticz.devices('Aqara Motion Sensor')
on = motion.active
if (domoticz.devices('State').state == 'Home' and not on and allowedToAutoAway(domoticz)
and updatedLongAgo(motion) and not domoticz.helpers.forcedState(domoticz)) then
domoticz.log("Away because no motion.", domoticz.LOG_FORCE)
domoticz.scenes('Away').switchOn()
end
if (domoticz.devices('State').state == 'Sleep' and allowedToAwake()
and wakeThreshold(domoticz, motion, on) and not domoticz.helpers.forcedState(domoticz)) then
domoticz.log("Wakeup because motion.", domoticz.LOG_FORCE)
domoticz.scenes('Home').switchOn()
end
end
}