YAPS - Présence Simulator, Un De Plus ... ?     Voici un petit script qui améliore (enfin pour moi en tout cas) les scripts de simulation de présence existants.   Je me suis basé sur celui-ci: http://forum.fibaro.com/viewtopic.php?p=52734#52734 que j'ai amélioré depuis quelques temps mais sur le forum officiel. Ce script enclenche la simulation au coucher du soleil et la termine à  heure fixe définie dans les variables: local stop_hour = "01" local stop_minute = "10"; Pas besoin d'utiliser le VirtualDevice pour activer et désactiver, définir la Variable Globale  "Simu_presence" (via GEA par exemple) enclenche ou déclenche la scène Le Virtual device surveille aussi l'état de la VG et se modifie en fonction pour afficher la bonne icône et le status en toutes lettres.   Pour cela, j'ai modifié le script pour qu'il tourne dans une scène (appuyer sur les boutons des VD via script me gave, les boutons changent d'id, en cas de reset complet de la box il faut retrouver les id etc... J'ai ajouté un mode "marche forcée" J'ai ajouter l'exit immédiat en cas de changement de Variables Globales J'ai ajouté la possibilité d'allumer une lampe en fin de script J'ai corrigé pas mal de bugs du script d'origine, je pense qu'il n'y en a plus actuellement   Soit, rien de tel que les VG et les scènes, très faciles pour utiliser avec GEA, scènes en mode block etc. Je garde les Virtual Devices pour l'apparence et les commandes (via modification de VG) Avantages: Portabilité, interaction avec d'autres scripts possibles, migration aisée.   Première étape:   Créer une Variable Globale prédéfinie "Simu_presence" avec les valeurs  0 et 1 Créer une Variable Globale prédéfinie "overideSimuSunset" avec les valeurs  0 et 1   Deuxième étape:   Créer le Virtual Device: Pour cela, importer le fichier: Presence_Simulator.vfib (ajouter nouveau virtual device)   Pour avoir une idée: Voici le bouton ON:
fibaro:setGlobal("Simu_presence", "1") fibaro:setGlobal("overideSimuSunset", "0") OFF:
fibaro:setGlobal("Simu_presence", "0") fibaro:setGlobal("overideSimuSunset", "0") Override:
fibaro:setGlobal("Simu_presence", "1") fibaro:setGlobal("overideSimuSunset", "1") et le main loop:
-------------------------------- -- YAPS Presence Simulator V2.0 -- SebcBien -- Janvier 2015 -------------------------------- local thismodule = fibaro:getSelfId();  local presence = fibaro:getGlobal("Simu_presence") local overide = fibaro:getGlobal("overideSimuSunset") --fibaro:debug(presence) --fibaro:debug(overide) if presence == "1" then presencemsg = "ON" else presencemsg = "OFF" end if overide == "1" then overidemsg = "ON" else overidemsg = "OFF" end fibaro:log(presencemsg .. " (Overide " .. overidemsg .. ")") fibaro:call(thismodule, "setProperty", "ui.status.value", "Presence: " .. presencemsg .. " (Overide " .. overidemsg .. ")"); --fibaro:debug(thismodule); if presence == "1" then  fibaro:call(thismodule, "setProperty", "currentIcon", 1026) end if presence == "0" then  fibaro:call(thismodule, "setProperty", "currentIcon", 1027) end fibaro:sleep(5000);       Troisième étape: Créer une nouvelle scène lua et y mettre ce code: Attention, ce n'est plus la dernière version, voir les pages suivantes pour les mises à  jour. LA DERNIERE VERSION SERA TOUJOURS SUR GITHUB !!!: https://github.com/sjauquet Ensuite Allez sur YAPS.scene.lua et télécharger avec le bouton RAW si vous ne voulez pas installer un client GIT (SmartGit est top ;-) ) --[[ %% autostart %% properties %% globals Simu_presence --]] -------------------------------- -- YAPS Presence Simulator V2.0 -- SebcBien -- Janvier 2015 -------------------------------- if (fibaro:countScenes() > 1) then fibaro:debug("More than one scene active, exiting!"); fibaro:abort(); end --------------------- USER SETTINGS -------------------------------- local id = { LAMPE_SDB = 16, LAMPE_CH_AMIS = 24, LAMPE_SALON = 45, LAMPE_BUREAU = 49, LAMPE_HALL = 52, LAMPE_CELLIER = 56, LAMPE_CH_EMILIEN = 58 } local stop_hour = "01"; -- Hour when you want simulation to stop local stop_minute = "10"; -- Minute of the hour you want simulation to stop -- note 1: the script will not exit while waiting the random time of the last light turned on. So end time can be longer than specified end time -- note 2: if the global variable changes during the same wait time as above, it will exit immediately (when back home while simulation runs) local rndmaxtime = 30 -- random time of light change in minutes --> here each device is on maximum 30min local ID_devices_lights = {id["LAMPE_SDB"],id["LAMPE_HALL"],id["LAMPE_BUREAU"],id["LAMPE_CELLIER"],id["LAMPE_CH_AMIS"]} -- IDs of lights to use in simulation --local ID_devices_lights = {id["LAMPE_HALL"],id["LAMPE_BUREAU"],id["LAMPE_CELLIER"]} -- IDs of lights to use in simulation local activatePush = true; -- activate push when simulation starts and stops local ID_Smartphone = 53; -- ID of your smartphone local ID_On_After_Simu = id["LAMPE_HALL"] -- Only One ID of a lamp to turn on after simulation ends (set 0 to disable) --------------------- USER SETTINGS END ---------------------------- ----------------------ADVANCED SETTINGS----------------------------- local showStandardDebugInfo = true; -- Debug shown in white local showExtraDebugInfo = true; -- Debug shown in orange local numbers_lights = #ID_devices_lights -- numbers of light devices listed above local manualOveride = fibaro:getGlobal("overideSimuSunset"); -- if = 1 then the simulation is forced -------------------------------------------------------------------- ----------------------------------- ----- Do not change code below ---- ----------------------------------- local simu = fibaro:getGlobal("Simu_presence"); --value of the global value: simulation is on or off local start_simu = fibaro:getValue(1, "sunsetHour"); --Start simulation when sunset --local start_simu = "22:28" local endtime version = "1.1.0" SimulatorPresenceEngine = {}; -- debug function Debug = function ( color, message ) fibaro:debug(string.format('<%s style="color:%s;">%s</%s>', "span", color, message, "span")); end ExtraDebug = function (debugMessage) if ( showExtraDebugInfo ) then Debug( "orange", debugMessage); end end StandardDebug = function (debugMessage) if ( showStandardDebugInfo ) then Debug( "white", debugMessage); end end -- function push message to mobile pushMessage = function (sendPush) if (activatePush) then ExtraDebug("Push info sent to mobile") fibaro:call(ID_Smartphone, 'sendPush', sendPush); end end -- function to switch off devices in the list function SimulatorPresenceEngine:TurnOff(group) Debug("red","TurnOff All lights!") local name, id2; local ID_devices_group = group; for i=1, #ID_devices_group do id2 = tonumber(ID_devices_group[i]); fibaro:call(id2, "turnOff"); name = fibaro:getName(id2); if (name == nil or name == string.char(0)) then name = "Unknown" end StandardDebug("Device:" .. name .. " Off "); end if ID_On_After_Simu ~= 0 then fibaro:call(ID_On_After_Simu, "turnOn"); end end -- function to calculate endtime function SimulatorPresenceEngine:EndTimeCalc() local start = os.date("%H:%M") local time = os.time() local date = os.date("*t", time) local year = date.year local month = date.month local day = date.day endtime = os.time{year=year, month=month, day=day, hour=stop_hour, min=stop_minute, sec=sec} --ExtraDebug ("CurrentTime" ..os.time()) --ExtraDebug ("Original EndTime " ..endtime) if endtime < os.time() then endtime = endtime + 24*60*60 -- ExtraDebug ("Modified Endtime " ..endtime) end end -- function to simulate a presence function SimulatorPresenceEngine:Launch() ExtraDebug( "Simulation will stop: "..stop_hour..":"..stop_minute ); if (os.time() >= endtime) or (simu == "0") or (manualOveride == "0") then ExtraDebug("Simulation stopped") SimulatorPresenceEngine:TurnOff(ID_devices_lights) end pushMessage("Lights simulation started") while ((os.time() <= endtime) and (simu == "1")) or ((manualOveride == "1")) do -- original code: while ((os.time() <= endtime) and (simu == "1")) or ((os.time() <= endtime) and (simu == "1") and (manualOveride == "1")) do if time == endtime then StandardDebug("time and endtime same value -> end") end 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 StandardDebug('light ID:'..random_light..' status:'..lightstatus) local sleeptime = math.random(rndmaxtime*60000) --random sleep fibaro:debug("entering loop of " .. sleeptime/60000 .. "minutes") -- This modification allows to exit the scene if the Simu_presence global var changes to 0 during the random sleep local counterexitsimu = 200 while (counterexitsimu > 0) do counterexitsimu = counterexitsimu - 1; test_presence_state = fibaro:getGlobal("Simu_presence") simu = tonumber(test_presence_state); --verify the global value, if the virtual device is deactivated, the scene stops. --fibaro:debug("simu var state : " .. simu) if simu == 0 then counterexitsimu = 0 end fibaro:sleep(sleeptime/200) end fibaro:debug("exiting loop of " .. sleeptime/60000 .. "minutes") local sleeptimemin = math.abs(sleeptime/60000) StandardDebug('sleeptime:'..sleeptimemin) simu = fibaro:getGlobal("Simu_presence"); --verify the global value, if the virtual device is deactivated, the scene stops. manualOveride = fibaro:getGlobalValue("overideSimuSunset") end end -- Main Script beginning SimulatorPresenceEngine:EndTimeCalc(); if (simu == "1") then Debug("green", "Simulate Presence at Home | v" .. version ); Debug( "green", "--------------------------------------------------"); ExtraDebug("Today's sunset: "..fibaro:getValue(1, "sunsetHour")) end if (simu == "1") then Debug("grey", "Simulate Presence will start at "..start_simu) pushMessage("Simulate Presence will start at "..start_simu) end -- Main Loop while (simu=="1") do -- Condition to start simulation simu = fibaro:getGlobal("Simu_presence"); manualOveride = fibaro:getGlobal("overideSimuSunset"); if (os.date("%H:%M") >= start_simu) then sunset = 1 else sunset = 0 end if ((simu == "1") and os.time() <= endtime and sunset == 1 ) or ((simu == "1") and manualOveride == "1" ) then SimulatorPresenceEngine:Launch(); --launch the simulation. if manualOveride == "1" and sunset == 0 then Debug("grey", "Manual override activated") elseif sunset == 1 then Debug("grey", "It's sunset time, starting simulation") end if sunset == 0 and manualOveride == "0" then Debug("grey", "Not manual override so Presence Simulation will not be activated"); elseif os.time() >= endtime then Debug("grey", "Time is now after:"..stop_hour..":"..stop_minute.."deactivating"); SimulatorPresenceEngine:TurnOff(ID_devices_lights); Debug("red","Simulation is deactivated") pushMessage("Lights simulation stopped") end end end -- Condition to end simulation if (simu == "0") then SimulatorPresenceEngine:TurnOff(ID_devices_lights); Debug("red","Simulation is deactivated") pushMessage("Lights simulation stopped") end Debug("red","Exit from scene") Dans user settings vous pouvez y mettre votre liste d'id "format GEA" (ça facilite quand il faut tout réinstaller hein    ) Pour définir la variable rndmaxtime, pensez que ce script n'allume pas une lampe après en avoir éteint une autre, mais il y en aura tantôt 3 d'allumées, puis 1 s'éteint etc. c'est donc plutôt une variable qui définit le "mouvement" dans la maison, il n'y a pas d'effet sapin de noà«l qui clignotte S'il y a une demande je pourrais considérer de traduire le code en français, mais je pense que avec des rudiments d'anglais ça se lit facilement ;-)   Les icônes viennent du post 6 de ce fil: http://www.domotique-fibaro.fr/index.php/topic/198-simulation-de-pr%C3%A9sence/   pour les id des icônes pour remplacer dans le mainloop du virtual device,   
if presence == "1" then  fibaro:call(thismodule, "setProperty", "currentIcon", 1026) end if presence == "0" then  fibaro:call(thismodule, "setProperty", "currentIcon", 1027) end je l'ai fait à  l'arrache mais apparemment il y a une méthode plus scientifique en utilisant le toolkit de Krikroff... si une bonne âme la connait, feel free to post  Enjoy !   icônes pour VD et Scène: