Rechercher dans la communauté
Affichage des résultats pour les étiquettes 'simulation'.
1 résultat trouvé
-
Script de Clarkkent609 posté ici : http://forum.fibaro.com/viewtopic.php?t=3009 1ere étape: Créer une variable prédéfinie :"Simu_presence" avec les valeurs "On" and "Off" 2eme étape: créer un module virtuel 3eme étape: copier et coller ce code: --[[ %% properties %% globals --]] fibaro:setGlobal("Simu_presence", "On"); --fibaro:debug("Simulation de présence activée"); fibaro:log("Simulation de présence activée"); fibaro:call(30, "setProperty", "ui.status.value", "activée"); --fibaro:debug(fibaro:getValue(30, "ui.status.value")) 30 =ID du module virtuel coller ce code dans le second bouton: --[[ %% properties %% globals --]] fibaro:setGlobal("Simu_presence", "Off"); --fibaro:debug("Simulation de présence désactivée"); fibaro:log("Simulation de présence désactivée"); fibaro:call(30, "setProperty", "ui.status.value", "désactivée"); --fibaro:debug(fibaro:getValue(30, "ui.status.value")) 30 =ID module virtuel. Attention : ID du Label doit contenir "status" : voir photo: 4eme étape copier et coller ce code dans le MAIN LOOP et remplacer par vos valeurs utilisateur --[[ %% properties %% globals --]] -- LUA - Presence Simulator V1.0.0 -- -- simulate a presence when you're on vacation. -- A part of code is reused, it can found here. Thanx to Richo: http://forum.fibaro.com/viewtopic.php?t=1892&postdays=0&postorder=asc&highlight=presence&start=15 and here thx to Krikroff http://forum.fibaro.com/viewtopic.php?t=1656 -- USER SETTINGS : local start_hour = 19; --hour to start simulation local start_minute = 30; --minute to start simulation, example 19:30 local rndmaxtime = 20 --random time of light change in minutes --> here each device is on max 20min local runtime = 90 --how long to run simulation in minutes local ID_devices_lights = {17, 13} --IDs of lights to use in simulation local numbers_lights = #ID_devices_lights --numbers of light devices listed above local activated_push = true; --activate push when simulation starts and stops local ID_Smartphone = 7; --ID of your smartphone local simu = fibaro:getGlobal("Simu_presence"); --value of the global value: simulation is on or off local debug = true; --activate the debug mode -- DO NOT EDIT THE CODE BELOW (except to suit your needs) -- local minute = 60000 --in milliseconds local currentDate = os.date("*t"); SimulatorPresenceEngine = { version = "1.0.0" }; -- function to switch off devices in the list function SimulatorPresenceEngine:TurnOff(group) local name, id; local ID_devices_group = group; for i=1, #ID_devices_group do id = tonumber(ID_devices_group[i]); fibaro:call(id, "turnOff"); if (debug) then name = fibaro:getName(id); if (name == nil or name == string.char(0)) then name = "Unknown" end fibaro:debug("Device:" .. name .. " On "); end end end -- function to simulate a presence function SimulatorPresenceEngine:Launch() local start = os.time() local endtime = start + runtime*minute/1000 -- after how many minutes exit simulation if (activated_push) then fibaro:call(ID_Smartphone, 'sendPush', "Lights simulation started") ; --send push notification if (debug) then fibaro:debug("push start sent") end end while ((os.time() < endtime) and (simu == "On")) do local random_light = tonumber(ID_devices_lights[math.random(numbers_lights)]) --choose a random light in the list local lightstatus = fibaro:getValue(random_light, 'value') --get the value of the random light in the list -- turn on the light if off or turn off if on if tonumber(lightstatus) == 0 then fibaro:call(random_light, 'turnOn') else fibaro:call(random_light, 'turnOff') end fibaro:sleep(1000) ; --necessary to get back the new status, because HC2 is too fast :-) lightstatus = fibaro:getValue(random_light, 'value') --get the value of the random light after his update if (debug) then fibaro:debug('light ID:'..random_light..' status:'..lightstatus) end local sleeptime = math.random(rndmaxtime*minute) --random sleep fibaro:sleep(sleeptime) local sleeptimemin = math.abs(sleeptime/60000) if (debug) then fibaro:debug('sleeptime:'..sleeptimemin) end simu = fibaro:getGlobal("Simu_presence"); --verify the global value, if the virtual device is deactivated, the scene stops. end --turn Off all lights SimulatorPresenceEngine:TurnOff(ID_devices_lights); fibaro:call(ID_Smartphone, 'sendPush', "Lights simulation stopped") ; --send push notification if (debug) then fibaro:debug("push stop sent") end fibaro:sleep(60000); end -- Condition to start simulation if ((simu == "On")and (currentDate.hour == start_hour ) and (currentDate.min == start_minute))then SimulatorPresenceEngine:Launch(); --launch the simulation when virtual device is on, and the current time is triggered. end
- 62 réponses
-
- 4
-
- présence
- Script lua
-
(et %d en plus)
Étiqueté avec :