-
Notifications
You must be signed in to change notification settings - Fork 13
/
presence_simulation.lua
46 lines (32 loc) · 1.34 KB
/
presence_simulation.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
--[[
%% properties
%% globals
--]]
fibaro:debug('start')
fibaro:call(11, 'sendPush', "Lights simulation started")
local minute = 60000 --in miliseconds
local rndmaxtime = 10 --random time of light change in minutes
local runtime = 120 --how long to run simulation in minutes
local lights = {37, 100, 43, 94, 109, 4, 29, 130} --IDs of lights to use in simulation
local nrlights = #lights --nr of light devices listed above
local start = os.time()
local endtime = start + runtime*minute/1000 -- after how many minutes exit simulation
while os.time() < endtime do
local rndlight = tonumber(lights[math.random(nrlights)])
local rnd = math.random(nrlights) --make it more random
local lightstatus = fibaro:getValue(rndlight, 'value')
fibaro:debug('light ID:'..rndlight..' status:'..lightstatus)
-- turn on the light if off or turn off if on
if tonumber(lightstatus) == 0 then fibaro:call(rndlight, 'turnOn') else fibaro:call(rndlight, 'turnOff') end
local sleeptime = math.random(rndmaxtime*minute)
fibaro:sleep(sleeptime)
local sleeptimemin = math.abs(sleeptime/60000)
fibaro:debug('sleeptime:'..sleeptimemin)
end
--turn Off all lights
for i = 1, nrlights do
rndlight = tonumber(lights[i])
fibaro:call(rndlight, 'turnOff')
end
fibaro:call(11, 'sendPush', "Lights simulation stopped")
fibaro:debug('END')