-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMotion Device.lua
More file actions
77 lines (60 loc) · 2.64 KB
/
Motion Device.lua
File metadata and controls
77 lines (60 loc) · 2.64 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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")
return (time.hour >= 9) and (time.hour <= 12)
end
local function wakeThreshold(domoticz)
newThreshold = tonumber(domoticz.devices('Wake Threshold').text) + 1
updateWakeThreshold(domoticz, newThreshold)
reached = newThreshold >= 3
if reached then
updateWakeThreshold(domoticz, 0)
return true
end
return false
end
local function nightLightMakesSense(domoticz)
lux = domoticz.devices('Xiaomi Gateway Lux').lux
return lux <= 350 and not domoticz.devices('Xiaomy Gateway Brightness').active
end
return {
on = {
devices = { 'Aqara Motion Sensor' }
},
logging = {
level = domoticz.LOG_FORCE,
marker = "Motion Device"
},
execute = function(domoticz, device)
if (device.active)
then
if (domoticz.devices('State').state == 'Away' and not domoticz.helpers.forcedState(domoticz))
then
domoticz.log("Home because motion.", domoticz.LOG_FORCE)
domoticz.scenes('Home').switchOn()
domoticz.helpers.sendSms(domoticz, 'Motion')
domoticz.devices('Cam Shot').switchOn().afterSec(2)
end
if (domoticz.devices('State').state == 'Sleep' and nightLightMakesSense(domoticz))
then
domoticz.log("Night light.", domoticz.LOG_FORCE)
domoticz.devices('Xiaomy Gateway Color').cancelQueuedCommands()
domoticz.devices('Xiaomy Gateway Brightness').cancelQueuedCommands()
domoticz.devices('Xiaomi RGB Gateway').cancelQueuedCommands()
domoticz.devices('Xiaomy Gateway Color').switchSelector(20)
domoticz.devices('Xiaomy Gateway Brightness').switchSelector(20)
domoticz.devices('Xiaomy Gateway Color').switchOff().silent().afterSec(120)
domoticz.devices('Xiaomy Gateway Brightness').switchOff().silent().afterSec(120)
domoticz.devices('Xiaomi RGB Gateway').switchOff().afterSec(120)
end
if (domoticz.devices('State').state == 'Sleep' and allowedToAwake() and not domoticz.helpers.forcedState(domoticz) and wakeThreshold(domoticz))
then
domoticz.log("Wakeup because motion.", domoticz.LOG_FORCE)
domoticz.scenes('Home').switchOn()
end
end
if (not device.active) then updateWakeThreshold(domoticz, 0) end
end
}