-
Compteur de contenus
4 189 -
Inscription
-
Dernière visite
-
Jours gagnés
85
Tout ce qui a été posté par sebcbien
-
oui, mais à minuit le sunset change d'heure et j'ai du trouver des parades pour que le script ne s'arrête pas à minuit une partie est calculée dans la function SimulatorPresenceEngine:EndTimeCalc() cette variable: wait_for_tomorrow permet de savoir si le recalcul des heures à déjà été effectué ou non etc... Si le endtime avait été toujours avant minuit, ça aurais grandement facilité les choses. mais certains veulent que ça puisse se terminer après minuit (dontm oi) maintenant endtime n'est plus fixe et donc ça complique le recalcul. bref... ce qui est bien c'est que ça garde mon neurône en activité ;-)
-
Elle ne tourne pas toutes les 2 heures, il y a une notification toutes les deux heures. elle fait un test toutes les 4 minutes et après 30 tests fait une notification
-
oui j'ai remarqué aussi :-/ Avec tous ces ajouts et modifications, il y a des problèmes de timing qui sont apparus. Cela peut avoir un impact dépendant du temps à laquelle le script à été lancé, du temps d'attente entre les vérifications et de l'heure du coucher du soleil... un problème de timming et le script rate la vérification du coucher du soleil (problème qui sont apparus avec la fonctionnalité de bouclage sur plusieurs jours, et le besoin de recalculer les heures) Je suis occupé avec la V3, j'ai ajouté la fonction d'extinction randomisée et progressive et je pense avoir trouvé le problème. J'ai modifié la scène pour qu'elle tourne "comme si j'étais en vacances" afin de pouvoir débugger et vérifier ce qui se passe lorsque la simulation n'est pas désactivée sur plusieurs jours. Un des soucis que j'avais identifié est que maintenant les jours raccourcissent, donc j'ai du rajouter un > en plus du < ainsi qu'une fourchette de test plus longue car le décalage est de plus d'une minute d'un jour a l'autre (le jours raccourcissent à des vitesses différentes au cours de l'année) Et dire que j'ai horreur de jouer avec les jours heures et dates :-/ La V3.0.1 est disponible sur github, je posterai la prochaine version d'ici une bonne semaine probablement, j'espère alors que j'aurai pu tester et débugger tous les cas de figure. En attendant, si tu veux, le code est sur github (V3.0.1)
-
j'ai posté les icônes dans le premier post
-
C cool, ça me facilite le travail :-) Je suis occupé à faire la prochaine version, je l'ai déjà inclus, mais j'ai toujours ce problème de simulation qui ne se lance plus le deuxième jour si on ne interromps pas entre-temps... ça marchais pourtant. Bref, dès que la 2.6.6 fonctionnera, je posterai ça avec free sms intégré. edit: Et la V3, ce sera avec l'extinction randomisée :-) @pepite Oui c ça
-
À l'aise :-) @pepite sorry, je l'avais lu puis j'ai oublié. Je regarderai demain, promis En gros, pour tester, tu peux les mettre dans les fonctions "launch" et "light off" ( pas sûr des noms exacts). Tu peux insérer tes lignes au début de ces fonctions. C'est basique mais ça devrait marcher Sent from my SM-N910F using Tapatalk
-
Sinon y'a mon YAPS qui fait ça aussi ;-) Sent from my SM-N910F using Tapatalk
-
Tiens je viens de penser que pour l'extinction en fin "normale" de simulation, ne pas éteindre toutes les lampes de la maison en même temps pourrait ajouter du réalisme. Par exemple, un paramètre temps_extinction_after_simu, àdiviser par le nombre de lampes ? Exemple: 15 minutes, àdiviser par 5 lampes = 3 minutes entre chaque extinction. Des intéressés ? :-) Sent from my SM-N910F using Tapatalk
-
voili voilou, deux bugs corrigés pour @pepite et @jojo :-) j'ai mis le showExtraDebugInfo à true, mettez le à false si tout va bien J'ai égalment fixé (j'espère) un bug lorsque le simulateur devait boucler plusieurs jours sans interruption (car les jours diminuent maintenant et le calcul ne le prenait pas en compte) --[[ %% autostart %% properties %% globals Simu_presence --]] --------------------------------- -- YAPS Presence Simulator V2.6.5 -- SebcBien -- August 2015 --------------------------------- --V2.6.5 -- Fixed bug when rndmaxendtime = 0 -- Probably fixed endtime bug calculation when looping for days due to days that are shorter now than the previous day -- Fixed bug not turning on ID_On_After_Simu when exiting simulation --V2.6.4 -- added random end time + small stability changes and cleaning --V2.6.3 -- Added array of lights to turn on after simu, ONLY if Simu_presence = 1 (normal ending, not ended by setting Simu_presence to 0) --V2.6.2 -- Added the possibility to not have an always on lamp --V2.6.1 -- Added naming of devices in the debug during simulation --V2.6.0 -- Added the possibility to select always on light during simulation --V2.5.0 -- fixed simulation starting if restarted between endtime & midnight --v2.4.1 -- fixed big bug simulator restarting after end time --V2.3.1 -- small notification and debug changes --V2.3 -- Rewriting the engine -- now relaunch automatically the next day, even if Simu_presence has not changed --V2.2 -- Added Manual Stop variable -- added list of mobiles if (fibaro:countScenes() > 1) then fibaro:debug("Scene already active, exiting this new occurence !!"); 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, LAMPE_COULOIR = 1316, PHONE_SEB = 1347, PHONE_GG = 1327 } local stop_hour = "01"; -- Hour when you want simulation to stop local stop_minute = "15"; -- 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. (even more with var rndmaxendtime) -- 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 = 20; -- random time of light change in minutes --> here each device is on maximum 30min local rndmaxendtime = 15; -- random time to add at the stop hour+stop minute so the simulation can be more variable (0 to deactivate) local ID_devices_lights_always_on = {id["LAMPE_BUREAU"],id["LAMPE_COULOIR"]} -- IDs of lights who will always stay on during simulation - leave empty array if none -> {} local ID_devices_lights = {id["LAMPE_SDB"],id["LAMPE_HALL"],id["LAMPE_CELLIER"],id["LAMPE_CH_AMIS"]} -- IDs of lights to use in simulation --local ID_devices_lights = {id["LAMPE_BUREAU"],id["LAMPE_CELLIER"]} -- Reduced set for test purposes local activatePush = true; -- activate push when simulation starts and stops --local ID_Smartphones = {id["PHONE_SEB"],id["PHONE_GG"]}; local ID_Smartphones = {id["PHONE_SEB"]}; -- list of device receiving Push local ID_On_After_Simu = 0; -- If next line is commented, no light will turn on after simulation ends local ID_On_After_Simu = id["LAMPE_COULOIR"]; -- ID of a light (Only One) to turn on after simulation ends (at specified stop_hour & stop_minute). Comment this line to turn off this feature local ID_On_When_Simu_Deactivated = 0; -- If next line is commented, no light will turn on after simulation is stopped (by putting Simu_presence to 0) local ID_On_When_Simu_Deactivated = id["LAMPE_HALL"]; -- ID of a light (Only One) to turn on after simulation is stopped (Simu_). Comment this line to turn off this feature --------------------- 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 version = "2.6.5"; 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 endtime; local wait_for_tomorrow = 1; local NotifLoop = 30; SimulatorPresenceEngine = {}; -- FONCTIONS Debug = function ( color, message ) --fibaro:debug(string.format('<%s style="color:%s;">%s</%s>', "span", color, message, "span")); fibaro:debug(string.format('<%s style="color:%s;">%s</%s>', "span", color, os.date("%a %d/%m", os.time()).." "..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 round = function (num, idp) local mult = 10^(idp or 0) return math.floor(num * mult + 0.5) / mult end -- Push message to mobile pushMessage = function (sendPush) if (activatePush) then for i=1, #ID_Smartphones do fibaro:call(tonumber(ID_Smartphones[i]), 'sendPush', sendPush); ExtraDebug("Push message ("..sendPush..") sent to mobile: "..tonumber(ID_Smartphones[i])); end end end -- 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} -- to calculate when it's daytime local currentHour = os.date("*t") local sunrise = tonumber(string.sub (fibaro:getValue(1,'sunriseHour'), 1 , 2) ) * 60 + tonumber(string.sub(fibaro:getValue(1,'sunriseHour'), 4) ) local sunset = tonumber(string.sub (fibaro:getValue(1,'sunsetHour'), 1 , 2) ) * 60 + tonumber(string.sub(fibaro:getValue(1,'sunsetHour'), 4) ) local now = currentHour.hour * 60 + currentHour.min; --ExtraDebug ("debug info: Sunrise : " .. sunrise .. " Sunset : "..sunset .. " Now : " ..now); --ExtraDebug ("debug info: Current OS Time" ..os.time()) --ExtraDebug ("debug info: Original planed EndTime " ..endtime) --ExtraDebug ("debug info: os.date: "..os.date("%H:%M").. " sunrisehour: "..fibaro:getValue(1, "sunriseHour")) if ((wait_for_tomorrow == 0) and (endtime+(5*60) < os.time())) then -- if endtime (+5 min to avoid sunset shifting) is gone and it's the first launch of simulator endtime = endtime + 24*60*60 -- add 24h at endtime after the night is gone start_simu = fibaro:getValue(1, "sunsetHour"); -- recalculate for next day ExtraDebug ("Added 24H to Endtime (first start ending after midnignt)"); ExtraDebug ("Recalculated Simulation StartHour (Sunset): " .. start_simu); wait_for_tomorrow = 1 end if (wait_for_tomorrow == 1 and (endtime+(5*60) < os.time()) and ((now >= sunrise) and (now <= sunset))) then -- if it looping days and endtime (+5 min to avoid sunset shifting) is gone and we are daytime endtime = endtime + 24*60*60 -- add 24h at endtime after the night is gone start_simu = fibaro:getValue(1, "sunsetHour"); -- recalculate for next day ExtraDebug ("Added One Day to Endtime: " .. endtime); ExtraDebug ("Recalculated Simulation StartHour (Sunset): " .. start_simu); end --ExtraDebug ("debug info: Recalculated planed EndTime " ..endtime) end -- Simulate Presence Main function SimulatorPresenceEngine:Launch() -- pushMessage("Lights simulation started, will stop at: "..stop_hour..":"..stop_minute ) pushMessage("Lights simulation started, will stop at: "..stop_hour..":"..stop_minute.."+ random of "..rndmaxendtime) -- ExtraDebug("Lights simulation started, will stop at: "..stop_hour..":"..stop_minute ); ExtraDebug("Lights simulation started, will stop at: "..stop_hour..":"..stop_minute.."+ random of "..rndmaxendtime); if ID_devices_lights_always_on[1] ~= nil then SimulatorPresenceEngine:TurnOn(ID_devices_lights_always_on); end --rndmaxendtime = tonumber(rndmaxendtime) + 1 if rndmaxendtime ~= 0 then -- add random minutes to end hour endtime2 = endtime + math.random(rndmaxendtime) else endtime2 = endtime end ExtraDebug("old endtime : ".. endtime .. " endtime2 (+random): " .. endtime2) while ((os.time() <= endtime2) 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:'.. fibaro:getName(random_light) ..' status:'..lightstatus); local sleeptime = math.random(rndmaxtime*60000) --random sleep StandardDebug("entering loop of " .. round(sleeptime/60000,2) .. " 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 StandardDebug("exiting loop of " .. round(sleeptime/60000,2) .. " 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 function SimulatorPresenceEngine:EndSimulation() if ID_devices_lights_always_on[1] ~= nil then SimulatorPresenceEngine:TurnOff(ID_devices_lights,ID_devices_lights_always_on); end Debug("red","Simulation is deactivated"); if (simu == "1") then Debug("grey", "Presence Simulator will Restart tomorrow around ".. fibaro:getValue(1, "sunsetHour")); pushMessage("Presence Simulator will Restart tomorrow around ".. fibaro:getValue(1, "sunsetHour")); wait_for_tomorrow = 1 -- will make EndTimeCalc add 24h to endtime during daytime end end function SimulatorPresenceEngine:ExitSimulation() Debug("red","Presence Simulator is Terminated"); pushMessage("Presence Simulator is Terminated"); end -- Switch off devices in the list function SimulatorPresenceEngine:TurnOff(group,group2) Debug("red","TurnOff All Simulation 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 Debug("red","TurnOff All Always on lights!"); local ID_devices_group = group2; 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 and simu == "1" then fibaro:call(ID_On_After_Simu, "turnOn"); name = fibaro:getName(ID_On_After_Simu); if (name == nil or name == string.char(0)) then name = "Unknown" end Debug("red","Turned On light ID_On_After_Simu: " .. name); end if ID_On_When_Simu_Deactivated ~= 0 and simu == "0" then fibaro:call(ID_On_When_Simu_Deactivated, "turnOn"); name = fibaro:getName(ID_On_When_Simu_Deactivated); if (name == nil or name == string.char(0)) then name = "Unknown" end Debug("red","Turned On light ID_On_When_Simu_Deactivated: " .. name); end end -- Switch on devices in the list function SimulatorPresenceEngine:TurnOn(group) Debug("red","Turning On always on 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, "turnOn"); name = fibaro:getName(id2); if (name == nil or name == string.char(0)) then name = "Unknown" end StandardDebug("Device: " .. name .. " On "); end Debug("red","Now randomizing other lights..."); end Debug("green", "Presence Simulator | v" .. version ); Debug( "green", "--------------------------------"); if tonumber(stop_hour) <= 12 then wait_for_tomorrow = 0 end -- if stop hour is between 00 and 12h then will consider that stop hour is before midnight ------------------------ Main Loop ---------------------------------- if (simu == "0") then -- check before the while loop below... remove ?. Debug("red","Not starting Simulation (Simu_presence = 0)"); SimulatorPresenceEngine:ExitSimulation(); fibaro:abort(); end pushMessage("Scheduled Simulation starting time: " .. start_simu); ExtraDebug("Today's sunset is at "..fibaro:getValue(1, "sunsetHour").." - End of Simulation at "..stop_hour..":"..stop_minute); --while (simu=="1" or simu=="0" ) do while true do -- boucle infinie SimulatorPresenceEngine:EndTimeCalc(); -- local start_simu = "00:01" -- uncomment this line when testing to force a start hour (only for the first loop) if (os.date("%H:%M") >= start_simu) then -- define if nighttime (sunset = 1) sunset = 1 else sunset = 0 end if (simu == "1") then if sunset == 1 and (os.time() <= endtime) then Debug("grey", "It's sunset time -> Simulation ON"); SimulatorPresenceEngine:Launch(); SimulatorPresenceEngine:EndSimulation(); end if manualOveride == "1" then Debug("grey", "Manual Override Activated -> Simulation ON"); SimulatorPresenceEngine:Launch(); SimulatorPresenceEngine:EndSimulation(); end --fibaro:debug("sunset: "..sunset .. "endtime: " .. endtime .. "ostime: " .. os.time()); if manualOveride == "0" and sunset == 0 and NotifLoop == 30 then Debug("grey", "Waiting for next Sunset: " .. start_simu .. " -> Simulation OFF."); end end if sunset == 1 and (os.time() >= endtime) and (os.time() <= (endtime + 60)) then Debug("grey","Simulation ended for this night."); end if (simu == "0") then -- Condition to end simulation SimulatorPresenceEngine:ExitSimulation(); Debug("red","Simu = 0, Exit from scene"); fibaro:abort(); end if NotifLoop <= 30 then --a waiting xx times the fibaro sleep below before checking again if NotifLoop == 30 then NotifLoop = 0 end if NotifLoop == 0 then ExtraDebug("Looping to check for changes every 4 min") end NotifLoop = NotifLoop + 1 end fibaro:sleep(4*60*1000); -- wait 4 minutes before testing again the global vars below simu = fibaro:getGlobal("Simu_presence"); manualOveride = fibaro:getGlobal("overideSimuSunset"); end
-
@jojo, si tu ne poste pas tes paramètres je vais avoir du mal àt'aider ;-) ceci dit avec ma config (postée) mon installation àexactement le comportement que tu souhaites... @pepite, le 0 je ne l'ai pas testé effectivement, je met ça dans ma todo. En attendant tu peux mettre 1 ça ne ralongera endtime que de max 1 minute. Sent from my SM-N910F using Tapatalk
-
L'icône que j'ai mise pour la scène est la même que pour le vd.... Je la posterai bientôt Sent from my SM-N910F using Tapatalk
-
Non, git n'a pas la dernière version, je ne sais pas le faire pour le moment :-/ Sent from my SM-N910F using Tapatalk
-
J'ai pu également tester et tout semble ok, voici également une nouvelle version avec la possibilité de randomiser la fin de la simulation via la variable rndmaxendtime Il y a aussi des améliorations du code pour plus de stabilité. @jojo , Pour tes questions, j'ai amélioré les commentaires dans le code. En gros, YAPS fait maintenant la différence quand le script est arrété en cours de simulation par le changement de la variable globale simu_presence. et quand le script est arrêté normalement car il a atteint l'heure de fin de simulation. dans ce cas, moi je laisse la lumière du couloir allumée (et je l'éteint via gea le matin). La lumière du hall (qui s'éteint chez moi de toute façon automatiquement après 5 minutes) est elle allumée quand le script est terminé par changement de VG (quand je rentre chez moi tard le soir) --[[ %% autostart %% properties %% globals Simu_presence --]] --------------------------------- -- YAPS Presence Simulator V2.6.4 -- SebcBien -- Avril 2015 --------------------------------- --V2.6.4 -- added random end time + small stability changes and cleaning --V2.6.3 -- Added array of lights to turn on after simu, ONLY if Simu_presence = 1 (normal ending, not ended by setting Simu_presence to 0) --V2.6.2 -- Added the possibility to not have an always on lamp --V2.6.1 -- Added naming of devices in the debug during simulation --V2.6.0 -- Added the possibility to select always on light during simulation --V2.5.0 -- fixed simulation starting if restarted between endtime & midnight --v2.4.1 -- fixed big bug simulator restarting after end time --V2.3.1 -- small notification and debug changes --V2.3 -- Rewriting the engine -- now relaunch automatically the next day, even if Simu_presence has not changed --V2.2 -- Added Manual Stop variable -- added list of mobiles if (fibaro:countScenes() > 1) then fibaro:debug("Scene already active, exiting this new occurence !!"); 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, LAMPE_COULOIR = 1316, PHONE_SEB = 1347, PHONE_GG = 1327 } local stop_hour = "01"; -- Hour when you want simulation to stop local stop_minute = "15"; -- 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. (even more with var rndmaxendtime) -- 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 = 20; -- random time of light change in minutes --> here each device is on maximum 30min local rndmaxendtime = 15; -- random time to add at the stop hour+stop minute so the simulation can be more variable (0 to deactivate) local ID_devices_lights_always_on = {id["LAMPE_BUREAU"],id["LAMPE_COULOIR"]} -- IDs of lights who will always stay on during simulation - leave empty array if none -> {} local ID_devices_lights = {id["LAMPE_SDB"],id["LAMPE_HALL"],id["LAMPE_CELLIER"],id["LAMPE_CH_AMIS"]} -- IDs of lights to use in simulation --local ID_devices_lights = {id["LAMPE_BUREAU"],id["LAMPE_CELLIER"]} -- Reduced set for test purposes local activatePush = true; -- activate push when simulation starts and stops --local ID_Smartphones = {id["PHONE_SEB"],id["PHONE_GG"]}; local ID_Smartphones = {id["PHONE_SEB"]}; -- list of device receiving Push local ID_On_After_Simu = 0; -- If next line is commented, no light will turn on after simulation ends local ID_On_After_Simu = id["LAMPE_COULOIR"]; -- ID of a light (Only One) to turn on after simulation ends (at specified stop_hour & stop_minute). Comment this line to turn off this feature local ID_On_When_Simu_Deactivated = 0; -- If next line is commented, no light will turn on after simulation is stopped (by putting Simu_presence to 0) local ID_On_When_Simu_Deactivated = id["LAMPE_HALL"]; -- ID of a light (Only One) to turn on after simulation is stopped (Simu_). Comment this line to turn off this feature --------------------- USER SETTINGS END ---------------------------- ----------------------ADVANCED SETTINGS----------------------------- local showStandardDebugInfo = true; -- Debug shown in white local showExtraDebugInfo = false; -- 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 version = "2.6.4"; 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 endtime; local wait_for_tomorrow = 1; local NotifLoop = 30; SimulatorPresenceEngine = {}; -- FONCTIONS Debug = function ( color, message ) --fibaro:debug(string.format('<%s style="color:%s;">%s</%s>', "span", color, message, "span")); fibaro:debug(string.format('<%s style="color:%s;">%s</%s>', "span", color, os.date("%a %d/%m", os.time()).." "..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 round = function (num, idp) local mult = 10^(idp or 0) return math.floor(num * mult + 0.5) / mult end -- Push message to mobile pushMessage = function (sendPush) if (activatePush) then for i=1, #ID_Smartphones do fibaro:call(tonumber(ID_Smartphones[i]), 'sendPush', sendPush); ExtraDebug("Push message ("..sendPush..") sent to mobile: "..tonumber(ID_Smartphones[i])); end end end -- 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} -- to calculate when it's daytime local currentHour = os.date("*t") local sunrise = tonumber(string.sub (fibaro:getValue(1,'sunriseHour'), 1 , 2) ) * 60 + tonumber(string.sub(fibaro:getValue(1,'sunriseHour'), 4) ) local sunset = tonumber(string.sub (fibaro:getValue(1,'sunsetHour'), 1 , 2) ) * 60 + tonumber(string.sub(fibaro:getValue(1,'sunsetHour'), 4) ) local now = currentHour.hour * 60 + currentHour.min; --ExtraDebug ("debug info: Sunrise : " .. sunrise .. " Sunset : "..sunset .. " Now : " ..now); --ExtraDebug ("debug info: Current OS Time" ..os.time()) --ExtraDebug ("debug info: Original planed EndTime " ..endtime) --ExtraDebug ("debug info: os.date: "..os.date("%H:%M").. " sunrisehour: "..fibaro:getValue(1, "sunriseHour")) if ((wait_for_tomorrow == 0) and (endtime < os.time())) then -- if endtime is gone and it's the first launch of simulator endtime = endtime + 24*60*60 -- add 24h at endtime after the night is gone start_simu = fibaro:getValue(1, "sunsetHour"); -- recalculate for next day ExtraDebug ("Added 24H to Endtime (first start ending after midnignt)"); ExtraDebug ("Recalculated Simulation StartHour (Sunset): " .. start_simu); wait_for_tomorrow = 1 end if (wait_for_tomorrow == 1 and (endtime < os.time()) and ((now >= sunrise) and (now <= sunset))) then -- if it looping days and endtime is gone and we are daytime endtime = endtime + 24*60*60 -- add 24h at endtime after the night is gone start_simu = fibaro:getValue(1, "sunsetHour"); -- recalculate for next day ExtraDebug ("Added One Day to Endtime: " .. endtime); ExtraDebug ("Recalculated Simulation StartHour (Sunset): " .. start_simu); end --ExtraDebug ("debug info: Recalculated planed EndTime " ..endtime) end -- Simulate Presence Main function SimulatorPresenceEngine:Launch() -- pushMessage("Lights simulation started, will stop at: "..stop_hour..":"..stop_minute ) pushMessage("Lights simulation started, will stop at: "..stop_hour..":"..stop_minute.."+ random of "..rndmaxendtime) -- ExtraDebug("Lights simulation started, will stop at: "..stop_hour..":"..stop_minute ); ExtraDebug("Lights simulation started, will stop at: "..stop_hour..":"..stop_minute.."+ random of "..rndmaxendtime); if ID_devices_lights_always_on[1] ~= nil then SimulatorPresenceEngine:TurnOn(ID_devices_lights_always_on); end endtime = endtime + math.random(rndmaxendtime+(1/10)) -- add random minutes to end hour 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:'.. fibaro:getName(random_light) ..' status:'..lightstatus); local sleeptime = math.random(rndmaxtime*60000) --random sleep StandardDebug("entering loop of " .. round(sleeptime/60000,2) .. " 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 StandardDebug("exiting loop of " .. round(sleeptime/60000,2) .. " 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 function SimulatorPresenceEngine:EndSimulation() if ID_devices_lights_always_on[1] ~= nil then SimulatorPresenceEngine:TurnOff(ID_devices_lights,ID_devices_lights_always_on); end Debug("red","Simulation is deactivated"); if (simu == "1") then Debug("grey", "Presence Simulator will Restart tomorrow around ".. fibaro:getValue(1, "sunsetHour")); pushMessage("Presence Simulator will Restart tomorrow around ".. fibaro:getValue(1, "sunsetHour")); wait_for_tomorrow = 1 -- will make EndTimeCalc add 24h to endtime during daytime end end function SimulatorPresenceEngine:ExitSimulation() Debug("red","Presence Simulator is Terminated"); pushMessage("Presence Simulator is Terminated"); end -- Switch off devices in the list function SimulatorPresenceEngine:TurnOff(group,group2) 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 local ID_devices_group = group2; 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"); name = fibaro:getName(ID_On_After_Simu); if (name == nil or name == string.char(0)) then name = "Unknown" end Debug("red","Manual Light Settings: Turned On light: " .. name); end if ID_On_When_Simu_Deactivated ~= 0 and Simu_presence == 0 then fibaro:call(ID_On_When_Simu_Deactivated, "turnOn"); name = fibaro:getName(ID_On_When_Simu_Deactivated); if (name == nil or name == string.char(0)) then name = "Unknown" end Debug("red","Manual Light Settings: Turned On light: " .. name); end end -- Switch on devices in the list function SimulatorPresenceEngine:TurnOn(group) Debug("red","Turning On always on 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, "turnOn"); name = fibaro:getName(id2); if (name == nil or name == string.char(0)) then name = "Unknown" end StandardDebug("Device: " .. name .. " On "); end Debug("red","Now randomizing other lights..."); end Debug("green", "Presence Simulator | v" .. version ); Debug( "green", "--------------------------------"); if tonumber(stop_hour) <= 12 then wait_for_tomorrow = 0 end -- if stop hour is between 00 and 12h then will consider that stop hour is before midnight ------------------------ Main Loop ---------------------------------- if (simu == "0") then -- check before the while loop below... remove ?. Debug("red","Not starting Simulation (Simu_presence = 0)"); SimulatorPresenceEngine:ExitSimulation(); fibaro:abort(); end pushMessage("Scheduled Simulation starting time: " .. start_simu); ExtraDebug("Today's sunset is at "..fibaro:getValue(1, "sunsetHour").." - End of Simulation at "..stop_hour..":"..stop_minute); --while (simu=="1" or simu=="0" ) do while true do -- boucle infinie SimulatorPresenceEngine:EndTimeCalc(); -- local start_simu = "00:01" -- uncomment this line when testing to force a start hour (only for the first loop) if (os.date("%H:%M") >= start_simu) then -- define if nighttime (sunset = 1) sunset = 1 else sunset = 0 end if (simu == "1") then if sunset == 1 and (os.time() <= endtime) then Debug("grey", "It's sunset time -> Simulation ON"); SimulatorPresenceEngine:Launch(); SimulatorPresenceEngine:EndSimulation(); end if manualOveride == "1" then Debug("grey", "Manual Override Activated -> Simulation ON"); SimulatorPresenceEngine:Launch(); SimulatorPresenceEngine:EndSimulation(); end --fibaro:debug("sunset: "..sunset .. "endtime: " .. endtime .. "ostime: " .. os.time()); if manualOveride == "0" and sunset == 0 and NotifLoop == 30 then Debug("grey", "Waiting for next Sunset: " .. start_simu .. " -> Simulation OFF."); end end if sunset == 1 and (os.time() >= endtime) and (os.time() <= (endtime + 60)) then Debug("grey","Simulation ended for this night."); end if (simu == "0") then -- Condition to end simulation SimulatorPresenceEngine:ExitSimulation(); Debug("red","Simu = 0, Exit from scene"); fibaro:abort(); end if NotifLoop <= 30 then --a waiting xx times the fibaro sleep below before checking again if NotifLoop == 30 then NotifLoop = 0 end if NotifLoop == 0 then ExtraDebug("Looping to check for changes every 4 min") end NotifLoop = NotifLoop + 1 end fibaro:sleep(4*60*1000); -- wait 4 minutes before testing again the global vars below simu = fibaro:getGlobal("Simu_presence"); manualOveride = fibaro:getGlobal("overideSimuSunset"); end
-
Content de voir que mon script est portable Sent from my SM-N910F using Tapatalk
-
pour les vacances, l'intérêt est certain ;-) Moi c fini :-/ mais ça a bien marché :-)
-
@jojo De mon côté ça fonctionne avec le dernier script.
-
Steven est VIVANT !!! Halleluia ! Et il a posté une mise à jour de GEA (V5.4) qui "corrige" les lenteurs sur HC2 en V4 et + Voir Github dans ma signature :-)
- 12 330 réponses
-
- 5
-
-
- support
- script lua
-
(et 1 en plus)
Étiqueté avec :
-
je fais une gestion similaire, tu peux t'inspirer de cet exemple dans le showoom gea: http://www.domotique-fibaro.fr/index.php/topic/2143-showroom-configs-gea/#entry48677
- 12 330 réponses
-
- support
- script lua
-
(et 1 en plus)
Étiqueté avec :
-
tu as essayé de recréer une scène from scratch et d'y mettre un code gea tout propre tout neuf qui vient du github de ma signature ? ;-)
- 12 330 réponses
-
- support
- script lua
-
(et 1 en plus)
Étiqueté avec :
-
et si tu convertis ta scène block en lua et que tu sauve ? Marchera t'elle toujours ?
- 12 330 réponses
-
- support
- script lua
-
(et 1 en plus)
Étiqueté avec :
-
Blague àpart, qqun àdes traces de vie récente des deux zigotos? C étonnant qd même... Sent from my SM-N910F using Tapatalk
-
Eh bien si on te le demande, tu diras que tu ne le sais pas ;-) Sent from my SM-N910F using Tapatalk
-
@jojo tu as testé ?
-
salut Jojo, Voici pour toi, j'ai fait une V2.6.3, vite fait et non testé... J'ai rajouté ton débug avec les jours et une nouvelle variable pour des lampes àn'allumer que en cas de fin de simulation forcée (passage de Simu_presence à0) Dis-moi si ça stroumphe --[[ %% autostart %% properties %% globals Simu_presence --]] --------------------------------- -- YAPS Presence Simulator V2.6.3 -- SebcBien -- Avril 2015 --------------------------------- --V2.6.3 -- Added array of lights to turn on after simu, ONLY if Simu_presence = 1 (normal ending, not ended by setting Simu_presence to 0) --V2.6.2 -- Added the possibility to not have an always on lamp --V2.6.1 -- Added naming of devices in the debug during simulation --V2.6.0 -- Added the possibility to select always on light during simulation --V2.5.0 -- fixed simulation starting if restarted between endtime & midnight --v2.4.1 -- fixed big bug simulator restarting after end time --V2.3.1 -- small notification and debug changes --V2.3 -- Rewriting the engine -- now relaunch automatically the next day, even if Simu_presence has not changed --V2.2 -- Added Manual Stop variable -- added list of mobiles 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, LAMPE_COULOIR = 1316, PHONE_SEB = 1347, PHONE_GG = 1327, } 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 = 20; -- random time of light change in minutes --> here each device is on maximum 30min local ID_devices_lights_always_on = {id["LAMPE_BUREAU"],id["LAMPE_COULOIR"]} -- IDs of lights who will always stay on during simulation - leave empty array if none -> {} local ID_devices_lights = {id["LAMPE_SDB"],id["LAMPE_HALL"],id["LAMPE_CELLIER"],id["LAMPE_CH_AMIS"]} -- IDs of lights to use in simulation --local ID_devices_lights = {id["LAMPE_BUREAU"],id["LAMPE_CELLIER"]} -- Reduced set for test purposes local activatePush = true; -- activate push when simulation starts and stops --local ID_Smartphones = {id["PHONE_SEB"],id["PHONE_GG"]}; local ID_Smartphones = {id["PHONE_SEB"]}; -- list of device receiving Push local ID_On_After_Simu = 0; -- If next line is commented, no light will turn on after simulation ends local ID_On_After_Simu = id["LAMPE_HALL"]; -- Only One ID of a light to turn on after simulation ends. Comment this line to turn off this feature local ID_On_When_Simu_Deactivated = 0; -- If next line is commented, no light will turn on after simulation is stopped (by putting Simu_presence to 0) local ID_On_When_Simu_Deactivated = id["LAMPE_HALL"]; -- Only One ID of a light to turn on after simulation is stopped. Comment this line to turn off this feature --------------------- USER SETTINGS END ---------------------------- ----------------------ADVANCED SETTINGS----------------------------- local showStandardDebugInfo = true; -- Debug shown in white local showExtraDebugInfo = false; -- 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 version = "2.6.3"; 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 endtime; local wait_for_tomorrow = 1; local NotifLoop = 30; SimulatorPresenceEngine = {}; -- FONCTIONS Debug = function ( color, message ) --fibaro:debug(string.format('<%s style="color:%s;">%s</%s>', "span", color, message, "span")); fibaro:debug(string.format('<%s style="color:%s;">%s</%s>', "span", color, os.date("%a %d/%m", os.time()).." "..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 round = function (num, idp) local mult = 10^(idp or 0) return math.floor(num * mult + 0.5) / mult end -- Push message to mobile pushMessage = function (sendPush) if (activatePush) then for i=1, #ID_Smartphones do fibaro:call(tonumber(ID_Smartphones[i]), 'sendPush', sendPush); ExtraDebug("Push message ("..sendPush..") sent to mobile: "..tonumber(ID_Smartphones[i])); end end end -- 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} -- to calculate when it's daytime local currentHour = os.date("*t") local sunrise = tonumber(string.sub (fibaro:getValue(1,'sunriseHour'), 1 , 2) ) * 60 + tonumber(string.sub(fibaro:getValue(1,'sunriseHour'), 4) ) local sunset = tonumber(string.sub (fibaro:getValue(1,'sunsetHour'), 1 , 2) ) * 60 + tonumber(string.sub(fibaro:getValue(1,'sunsetHour'), 4) ) local now = currentHour.hour * 60 + currentHour.min; --ExtraDebug ("debug info: Sunrise : " .. sunrise .. " Sunset : "..sunset .. " Now : " ..now); --ExtraDebug ("debug info: Current OS Time" ..os.time()) --ExtraDebug ("debug info: Original planed EndTime " ..endtime) --ExtraDebug ("debug info: os.date: "..os.date("%H:%M").. " sunrisehour: "..fibaro:getValue(1, "sunriseHour")) if ((wait_for_tomorrow == 0) and (endtime < os.time())) then -- if endtime is gone and it's the first launch of simulator endtime = endtime + 24*60*60 -- add 24h at endtime after the night is gone start_simu = fibaro:getValue(1, "sunsetHour"); -- recalculate for next day ExtraDebug ("Added 24H to Endtime (first start ending after midnignt)"); ExtraDebug ("Recalculated Simulation StartHour (Sunset): " .. start_simu); wait_for_tomorrow = 1 end if (wait_for_tomorrow == 1 and (endtime < os.time()) and ((now >= sunrise) and (now <= sunset))) then -- if it looping days and endtime is gone and we are daytime endtime = endtime + 24*60*60 -- add 24h at endtime after the night is gone start_simu = fibaro:getValue(1, "sunsetHour"); -- recalculate for next day ExtraDebug ("Added One Day to Endtime: " .. endtime); ExtraDebug ("Recalculated Simulation StartHour (Sunset): " .. start_simu); end --ExtraDebug ("debug info: Recalculated planed EndTime " ..endtime) end -- Simulate Presence Main function SimulatorPresenceEngine:Launch() pushMessage("Lights simulation started, will stop at: "..stop_hour..":"..stop_minute) ExtraDebug("Lights simulation started, will stop at: "..stop_hour..":"..stop_minute ); if ID_devices_lights_always_on[1] ~= nil then SimulatorPresenceEngine:TurnOn(ID_devices_lights_always_on); end 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:'.. fibaro:getName(random_light) ..' status:'..lightstatus); local sleeptime = math.random(rndmaxtime*60000) --random sleep StandardDebug("entering loop of " .. round(sleeptime/60000,2) .. " 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 StandardDebug("exiting loop of " .. round(sleeptime/60000,2) .. " 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 function SimulatorPresenceEngine:EndSimulation() if ID_devices_lights_always_on[1] ~= nil then SimulatorPresenceEngine:TurnOff(ID_devices_lights,ID_devices_lights_always_on); end Debug("red","Simulation is deactivated"); if (simu == "1") then Debug("grey", "Presence Simulator will Restart tomorrow around ".. fibaro:getValue(1, "sunsetHour")); pushMessage("Presence Simulator will Restart tomorrow around ".. fibaro:getValue(1, "sunsetHour")); wait_for_tomorrow = 1 -- will make EndTimeCalc add 24h to endtime during daytime end end function SimulatorPresenceEngine:ExitSimulation() Debug("red","Presence Simulator is Terminated"); pushMessage("Presence Simulator is Terminated"); end -- Switch off devices in the list function SimulatorPresenceEngine:TurnOff(group,group2) 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 local ID_devices_group = group2; 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"); name = fibaro:getName(ID_On_After_Simu); if (name == nil or name == string.char(0)) then name = "Unknown" end Debug("red","Manual Light Settings: Turned On light: " .. name); end simu = fibaro:getGlobal("Simu_presence"); if ID_On_When_Simu_Deactivated ~= 0 and simu == 0 then fibaro:call(ID_On_When_Simu_Deactivated, "turnOn"); name = fibaro:getName(ID_On_When_Simu_Deactivated); if (name == nil or name == string.char(0)) then name = "Unknown" end Debug("red","Manual Light Settings: Turned On light: " .. name); end end -- Switch on devices in the list function SimulatorPresenceEngine:TurnOn(group) Debug("red","Turning On always on 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, "turnOn"); name = fibaro:getName(id2); if (name == nil or name == string.char(0)) then name = "Unknown" end StandardDebug("Device: " .. name .. " On "); end Debug("red","Now randomizing other lights..."); end Debug("green", "Presence Simulator | v" .. version ); Debug( "green", "--------------------------------"); if tonumber(stop_hour) <= 12 then wait_for_tomorrow = 0 end -- if stop hour is between 00 and 12h then will consider that stop hour is before midnight ------------------------ Main Loop ---------------------------------- if (simu == "0") then Debug("red","Not starting Simulation (Simu_presence = 0)"); SimulatorPresenceEngine:ExitSimulation(); fibaro:abort(); end pushMessage("Scheduled Simulation starting time: " .. start_simu); ExtraDebug("Today's sunset is at "..fibaro:getValue(1, "sunsetHour").." - End of Simulation at "..stop_hour..":"..stop_minute); while (simu=="1" or simu=="0" ) do SimulatorPresenceEngine:EndTimeCalc(); -- local start_simu = "00:01" -- uncomment this line when testing to force a start hour (for the first loop) if (os.date("%H:%M") >= start_simu) then -- define if nighttime (sunset) sunset = 1 else sunset = 0 end if (simu == "1") then if sunset == 1 and (os.time() <= endtime) then Debug("grey", "It's sunset time -> Simulation ON"); SimulatorPresenceEngine:Launch(); SimulatorPresenceEngine:EndSimulation(); end if manualOveride == "1" then Debug("grey", "Manual Override Activated -> Simulation ON"); SimulatorPresenceEngine:Launch(); SimulatorPresenceEngine:EndSimulation(); end --fibaro:debug("sunset: "..sunset .. "endtime: " .. endtime .. "ostime: " .. os.time()); if manualOveride == "0" and sunset == 0 and NotifLoop == 30 then Debug("grey", "Waiting for next Sunset: " .. start_simu .. " -> Simulation OFF."); end end if sunset == 1 and (os.time() >= endtime) and (os.time() <= (endtime + 60)) then Debug("grey","Simulation ended for this night."); end if (simu == "0") then -- Condition to end simulation SimulatorPresenceEngine:ExitSimulation(); Debug("red","Simu = 0, Exit from scene"); fibaro:abort(); end if NotifLoop <= 30 then if NotifLoop == 30 then NotifLoop = 0 end if NotifLoop == 0 then ExtraDebug("Looping to check for changes every 2min") end NotifLoop = NotifLoop + 1 end fibaro:sleep(2*60*1000); simu = fibaro:getGlobal("Simu_presence"); manualOveride = fibaro:getGlobal("overideSimuSunset"); end
-
salut Jojo, Voici pour toi, j'ai fait une V2.6.3, vite fait et non testé... J'ai rajouté ton débug avec les jours et une nouvelle variable pour des lampes àn'allumer que en cas de fin de simulation forcée (passage de Simu_presence à0) Dis-moi si ça stroumphe --[[ %% autostart %% properties %% globals Simu_presence --]] --------------------------------- -- YAPS Presence Simulator V2.6.2 -- SebcBien -- Avril 2015 --------------------------------- --V2.6.3 -- Added array of lights to turn on after simu, ONLY if Simu_presence = 1 (normal ending, not ended by setting Simu_presence to 0) --V2.6.2 -- Added the possibility to not have an always on lamp --V2.6.1 -- Added naming of devices in the debug during simulation --V2.6.0 -- Added the possibility to select always on light during simulation --V2.5.0 -- fixed simulation starting if restarted between endtime & midnight --v2.4.1 -- fixed big bug simulator restarting after end time --V2.3.1 -- small notification and debug changes --V2.3 -- Rewriting the engine -- now relaunch automatically the next day, even if Simu_presence has not changed --V2.2 -- Added Manual Stop variable -- added list of mobiles 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, LAMPE_COULOIR = 1316, PHONE_SEB = 1323, PHONE_GG = 1347, } 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 = 20; -- random time of light change in minutes --> here each device is on maximum 30min local ID_devices_lights_always_on = {id["LAMPE_BUREAU"],id["LAMPE_COULOIR"]} -- IDs of lights who will always stay on during simulation - leave empty array if none -> {} local ID_devices_lights = {id["LAMPE_SDB"],id["LAMPE_HALL"],id["LAMPE_CELLIER"],id["LAMPE_CH_AMIS"]} -- IDs of lights to use in simulation --local ID_devices_lights = {id["LAMPE_BUREAU"],id["LAMPE_CELLIER"]} -- Reduced set for test purposes local activatePush = true; -- activate push when simulation starts and stops --local ID_Smartphones = {id["PHONE_SEB"],id["PHONE_GG"]}; local ID_Smartphones = {id["PHONE_SEB"]}; -- list of device receiving Push local ID_On_After_Simu = 0; -- If next line is commented, no light will turn on after simulation ends local ID_On_After_Simu = id["LAMPE_HALL"]; -- Only One ID of a light to turn on after simulation ends. Comment this line to turn off this feature local ID_On_When_Simu_Deactivated = 0; -- If next line is commented, no light will turn on after simulation is stopped (by putting Simu_presence to 0) local ID_On_When_Simu_Deactivated = id["LAMPE_HALL"]; -- Only One ID of a light to turn on after simulation is stopped. Comment this line to turn off this feature --------------------- USER SETTINGS END ---------------------------- ----------------------ADVANCED SETTINGS----------------------------- local showStandardDebugInfo = true; -- Debug shown in white local showExtraDebugInfo = false; -- 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 version = "2.6.3"; 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 endtime; local wait_for_tomorrow = 1; local NotifLoop = 30; SimulatorPresenceEngine = {}; -- FONCTIONS Debug = function ( color, message ) --fibaro:debug(string.format('<%s style="color:%s;">%s</%s>', "span", color, message, "span")); fibaro:debug(string.format('<%s style="color:%s;">%s</%s>', "span", color, os.date("%a %d/%m", os.time()).." "..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 round = function (num, idp) local mult = 10^(idp or 0) return math.floor(num * mult + 0.5) / mult end -- Push message to mobile pushMessage = function (sendPush) if (activatePush) then for i=1, #ID_Smartphones do fibaro:call(tonumber(ID_Smartphones[i]), 'sendPush', sendPush); ExtraDebug("Push message ("..sendPush..") sent to mobile: "..tonumber(ID_Smartphones[i])); end end end -- 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} -- to calculate when it's daytime local currentHour = os.date("*t") local sunrise = tonumber(string.sub (fibaro:getValue(1,'sunriseHour'), 1 , 2) ) * 60 + tonumber(string.sub(fibaro:getValue(1,'sunriseHour'), 4) ) local sunset = tonumber(string.sub (fibaro:getValue(1,'sunsetHour'), 1 , 2) ) * 60 + tonumber(string.sub(fibaro:getValue(1,'sunsetHour'), 4) ) local now = currentHour.hour * 60 + currentHour.min; --ExtraDebug ("debug info: Sunrise : " .. sunrise .. " Sunset : "..sunset .. " Now : " ..now); --ExtraDebug ("debug info: Current OS Time" ..os.time()) --ExtraDebug ("debug info: Original planed EndTime " ..endtime) --ExtraDebug ("debug info: os.date: "..os.date("%H:%M").. " sunrisehour: "..fibaro:getValue(1, "sunriseHour")) if ((wait_for_tomorrow == 0) and (endtime < os.time())) then -- if endtime is gone and it's the first launch of simulator endtime = endtime + 24*60*60 -- add 24h at endtime after the night is gone start_simu = fibaro:getValue(1, "sunsetHour"); -- recalculate for next day ExtraDebug ("Added 24H to Endtime (first start ending after midnignt)"); ExtraDebug ("Recalculated Simulation StartHour (Sunset): " .. start_simu); wait_for_tomorrow = 1 end if (wait_for_tomorrow == 1 and (endtime < os.time()) and ((now >= sunrise) and (now <= sunset))) then -- if it looping days and endtime is gone and we are daytime endtime = endtime + 24*60*60 -- add 24h at endtime after the night is gone start_simu = fibaro:getValue(1, "sunsetHour"); -- recalculate for next day ExtraDebug ("Added One Day to Endtime: " .. endtime); ExtraDebug ("Recalculated Simulation StartHour (Sunset): " .. start_simu); end --ExtraDebug ("debug info: Recalculated planed EndTime " ..endtime) end -- Simulate Presence Main function SimulatorPresenceEngine:Launch() pushMessage("Lights simulation started, will stop at: "..stop_hour..":"..stop_minute) ExtraDebug("Lights simulation started, will stop at: "..stop_hour..":"..stop_minute ); if ID_devices_lights_always_on[1] ~= nil then SimulatorPresenceEngine:TurnOn(ID_devices_lights_always_on); end 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:'.. fibaro:getName(random_light) ..' status:'..lightstatus); local sleeptime = math.random(rndmaxtime*60000) --random sleep StandardDebug("entering loop of " .. round(sleeptime/60000,2) .. " 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 StandardDebug("exiting loop of " .. round(sleeptime/60000,2) .. " 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 function SimulatorPresenceEngine:EndSimulation() if ID_devices_lights_always_on[1] ~= nil then SimulatorPresenceEngine:TurnOff(ID_devices_lights,ID_devices_lights_always_on); end Debug("red","Simulation is deactivated"); if (simu == "1") then Debug("grey", "Presence Simulator will Restart tomorrow around ".. fibaro:getValue(1, "sunsetHour")); pushMessage("Presence Simulator will Restart tomorrow around ".. fibaro:getValue(1, "sunsetHour")); wait_for_tomorrow = 1 -- will make EndTimeCalc add 24h to endtime during daytime end end function SimulatorPresenceEngine:ExitSimulation() Debug("red","Presence Simulator is Terminated"); pushMessage("Presence Simulator is Terminated"); end -- Switch off devices in the list function SimulatorPresenceEngine:TurnOff(group,group2) 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 local ID_devices_group = group2; 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"); name = fibaro:getName(ID_On_After_Simu); if (name == nil or name == string.char(0)) then name = "Unknown" end Debug("red","Manual Light Settings: Turned On light: " .. name); end if ID_On_When_Simu_Deactivated ~= 0 and Simu_presence == 0 then fibaro:call(ID_On_When_Simu_Deactivated, "turnOn"); name = fibaro:getName(ID_On_When_Simu_Deactivated); if (name == nil or name == string.char(0)) then name = "Unknown" end Debug("red","Manual Light Settings: Turned On light: " .. name); end end -- Switch on devices in the list function SimulatorPresenceEngine:TurnOn(group) Debug("red","Turning On always on 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, "turnOn"); name = fibaro:getName(id2); if (name == nil or name == string.char(0)) then name = "Unknown" end StandardDebug("Device: " .. name .. " On "); end Debug("red","Now randomizing other lights..."); end Debug("green", "Presence Simulator | v" .. version ); Debug( "green", "--------------------------------"); if tonumber(stop_hour) <= 12 then wait_for_tomorrow = 0 end -- if stop hour is between 00 and 12h then will consider that stop hour is before midnight ------------------------ Main Loop ---------------------------------- if (simu == "0") then Debug("red","Not starting Simulation (Simu_presence = 0)"); SimulatorPresenceEngine:ExitSimulation(); fibaro:abort(); end pushMessage("Scheduled Simulation starting time: " .. start_simu); ExtraDebug("Today's sunset is at "..fibaro:getValue(1, "sunsetHour").." - End of Simulation at "..stop_hour..":"..stop_minute); while (simu=="1" or simu=="0" ) do SimulatorPresenceEngine:EndTimeCalc(); -- local start_simu = "00:01" -- uncomment this line when testing to force a start hour (for the first loop) if (os.date("%H:%M") >= start_simu) then -- define if nighttime (sunset) sunset = 1 else sunset = 0 end if (simu == "1") then if sunset == 1 and (os.time() <= endtime) then Debug("grey", "It's sunset time -> Simulation ON"); SimulatorPresenceEngine:Launch(); SimulatorPresenceEngine:EndSimulation(); end if manualOveride == "1" then Debug("grey", "Manual Override Activated -> Simulation ON"); SimulatorPresenceEngine:Launch(); SimulatorPresenceEngine:EndSimulation(); end --fibaro:debug("sunset: "..sunset .. "endtime: " .. endtime .. "ostime: " .. os.time()); if manualOveride == "0" and sunset == 0 and NotifLoop == 30 then Debug("grey", "Waiting for next Sunset: " .. start_simu .. " -> Simulation OFF."); end end if sunset == 1 and (os.time() >= endtime) and (os.time() <= (endtime + 60)) then Debug("grey","Simulation ended for this night."); end if (simu == "0") then -- Condition to end simulation SimulatorPresenceEngine:ExitSimulation(); Debug("red","Simu = 0, Exit from scene"); fibaro:abort(); end if NotifLoop <= 30 then if NotifLoop == 30 then NotifLoop = 0 end if NotifLoop == 0 then ExtraDebug("Looping to check for changes every 2min") end NotifLoop = NotifLoop + 1 end fibaro:sleep(2*60*1000); simu = fibaro:getGlobal("Simu_presence"); manualOveride = fibaro:getGlobal("overideSimuSunset"); end