Aller au contenu

Messages recommandés

Posté(e)

Ça avait arrêté de fonctionner effectivement mais depuis un reboot de la hc2 ça marche nickel... Je ne pense plus que c'est mon script du coup...

Cette variable est modifiée par un autre script que le mien qui lui ne fait que lire son état et s'active si elle est a 1...

Donc cherche ce qui la modifie aléatoirement comme ça.

Moi je la modifie avec gea en fonction de ma présence ou non...

Sent from my phone

Posté(e)

Merci pour tes conseils.

Je penche vers une corruption de la DB ou qqch du genre pour cette variable, car le scricpt de Steven me remonte parfaitement les changements de TOUTES les autres variables, sauf de celle là, qui je confirme n'est modifiée que en fonction de ma présence/absence.

Donc le script devrait me remonter une info chaque fois de je branche/débranche mon arlarme, et il ne le fait pas, malgré que la variable soit àla bonne valeur (j'ai vérifié manuellement).

Je vai donc changer son nom et modifier le script, et on verra.

Posté(e)

Effacer et recréer la variable devrait suffire, ou alors c un script que tu as oublié quelque-part...

Sent from my phone

Posté(e)

j'avais déjàessayé de détruire et recréer la variable, c'est pour ça que je vais essayer avec un autre nom (car dans la DB, il stocke le nom et pas un id)

Posté(e) (modifié)

Je viens d'implémenter la version 2.6.2.

Tout semble ok. Je ne comprends pas trop ce qui s'est passé.

Je me suis permis de faire une petite modif dans ton code de débug, afin qu'on puisse voir le jour (et pas uniqueent l'heure) du débug.

fibaro:debug(string.format('<%s style="color:%s;">%s</%s>', "span", color, os.date("%a %d/%m", os.time()).." "..message, "span")); 
[DEBUG] 23:17:36: Wed 20/05 Presence Simulator | v2.6.2
[DEBUG] 23:17:36: Wed 20/05 --------------------------------
[DEBUG] 23:17:36: Wed 20/05 Not starting Simulation (Simu_presence = 0)
[DEBUG] 23:17:36: Wed 20/05 Presence Simulator is Terminated
[DEBUG] 23:19:30: Wed 20/05 Presence Simulator | v2.6.2
[DEBUG] 23:19:30: Wed 20/05 --------------------------------
[DEBUG] 23:19:30: Wed 20/05 It's sunset time -> Simulation ON
[DEBUG] 23:19:30: Wed 20/05 Turning On always on lights:
[DEBUG] 23:19:30: Wed 20/05 Device: Lum_SalonTV On
[DEBUG] 23:19:30: Wed 20/05 Now randomizing other lights...
[DEBUG] 23:19:31: Wed 20/05 light ID:Lum_SdBEtage status:1
[DEBUG] 23:19:31: Wed 20/05 entering loop of 4.73 minutes
[DEBUG] 23:23:57: Wed 20/05 exiting loop of 4.73 minutes

Autre question : pourquoi a-t-on deux variables (Simu_presence et overideSimuSunset) car overideSimuSunset = 1 seulement si Simu_presence = 1.

On pourrait tout faire avec Simu_presence = 0 ou 1 ou 2 (= overideSimuSunset) ? et il faudrait ainsi créer 1 variable de moins (je sais, je suis une grosse fainéasse).

D'autant plus qu'en faisant des tests, je me suis trouvé avec Simu_presence = 0 et overideSimuSunset = 1 (ce qui n'a pas de sens) et mes lampes ont commencé à  faire la fête (pour des loops de 2 sec !

[DEBUG] 23:24:20: Wed 20/05 Presence Simulator | v2.6.2
[DEBUG] 23:24:20: Wed 20/05 --------------------------------
[DEBUG] 23:24:20: Wed 20/05 It's sunset time -> Simulation ON
[DEBUG] 23:24:20: Wed 20/05 Turning On always on lights:
[DEBUG] 23:24:20: Wed 20/05 Device: Lum_SalonTV On
[DEBUG] 23:24:20: Wed 20/05 Now randomizing other lights...
[DEBUG] 23:24:21: Wed 20/05 light ID:Lum_SdBEtage status:1
[DEBUG] 23:24:21: Wed 20/05 entering loop of 9.58 minutes
[DEBUG] 23:33:24: Wed 20/05 exiting loop of 9.58 minutes
[DEBUG] 23:33:25: Wed 20/05 light ID:Lum_SdBEtage status:0
[DEBUG] 23:33:25: Wed 20/05 entering loop of 2.37 minutes
[DEBUG] 23:33:26: Wed 20/05 exiting loop of 2.37 minutes
[DEBUG] 23:33:27: Wed 20/05 light ID:Prise_Bureau status:1
[DEBUG] 23:33:27: Wed 20/05 entering loop of 9.22 minutes
[DEBUG] 23:33:29: Wed 20/05 exiting loop of 9.22 minutes
[DEBUG] 23:33:30: Wed 20/05 light ID:Lum_SdBRez_Douche status:1
[DEBUG] 23:33:30: Wed 20/05 entering loop of 6.65 minutes
[DEBUG] 23:33:32: Wed 20/05 exiting loop of 6.65 minutes
[DEBUG] 23:33:33: Wed 20/05 light ID:Prise_Bureau status:0
[DEBUG] 23:33:33: Wed 20/05 entering loop of 7.55 minutes
[DEBUG] 23:33:36: Wed 20/05 exiting loop of 7.55 minutes
[DEBUG] 23:33:37: Wed 20/05 light ID:Prise_Bureau status:1
[DEBUG] 23:33:37: Wed 20/05 entering loop of 6.16 minutes
[DEBUG] 23:33:38: Wed 20/05 exiting loop of 6.16 minutes
[DEBUG] 23:33:39: Wed 20/05 light ID:Lum_SdBEtage status:1
[DEBUG] 23:33:39: Wed 20/05 entering loop of 10.99 minutes
[DEBUG] 23:33:43: Wed 20/05 exiting loop of 10.99 minutes
[DEBUG] 23:33:44: Wed 20/05 light ID:Prise_Bureau status:0
[DEBUG] 23:33:44: Wed 20/05 entering loop of 8.61 minutes
[DEBUG] 23:33:46: Wed 20/05 exiting loop of 8.61 minutes
[DEBUG] 23:33:47: Wed 20/05 light ID:Lum_SdBRez_Douche status:0
[DEBUG] 23:33:47: Wed 20/05 entering loop of 7.28 minutes
[DEBUG] 23:33:49: Wed 20/05 exiting loop of 7.28 minutes
[DEBUG] 23:33:50: Wed 20/05 light ID:Lum_SdBRez_Douche status:1
[DEBUG] 23:33:50: Wed 20/05 entering loop of 2.91 minutes
[DEBUG] 23:33:51: Wed 20/05 exiting loop of 2.91 minutes
[DEBUG] 23:33:52: Wed 20/05 light ID:Lum_SdBRez_Douche status:0
[DEBUG] 23:33:52: Wed 20/05 entering loop of 9.65 minutes
[DEBUG] 23:33:55: Wed 20/05 exiting loop of 9.65 minutes
[DEBUG] 23:33:56: Wed 20/05 light ID:Lum_SdBRez_Douche status:1
[DEBUG] 23:33:56: Wed 20/05 entering loop of 4.81 minutes
[DEBUG] 23:33:58: Wed 20/05 exiting loop of 4.81 minutes
[DEBUG] 23:33:59: Wed 20/05 light ID:Lum_SdBRez_Douche status:0
[DEBUG] 23:33:59: Wed 20/05 entering loop of 1.31 minutes
[DEBUG] 23:33:59: Wed 20/05 exiting loop of 1.31 minutes
[DEBUG] 23:34:00: Wed 20/05 light ID:Lum_SdBEtage status:0
[DEBUG] 23:34:00: Wed 20/05 entering loop of 2.62 minutes
[DEBUG] 23:34:01: Wed 20/05 exiting loop of 2.62 minutes
[DEBUG] 23:34:02: Wed 20/05 light ID:Prise_Bureau status:1
[DEBUG] 23:34:02: Wed 20/05 entering loop of 10.07 minutes
[DEBUG] 23:34:05: Wed 20/05 exiting loop of 10.07 minutes
[DEBUG] 23:34:06: Wed 20/05 light ID:Prise_Bureau status:0
[DEBUG] 23:34:06: Wed 20/05 entering loop of 3.55 minutes
[DEBUG] 23:34:07: Wed 20/05 exiting loop of 3.55 minutes
[DEBUG] 23:34:08: Wed 20/05 light ID:Prise_Bureau status:0
[DEBUG] 23:34:08: Wed 20/05 entering loop of 6.29 minutes
[DEBUG] 23:34:10: Wed 20/05 exiting loop of 6.29 minutes
[DEBUG] 23:34:11: Wed 20/05 light ID:Prise_Bureau status:1
[DEBUG] 23:34:11: Wed 20/05 entering loop of 11.67 minutes
[DEBUG] 23:34:14: Wed 20/05 exiting loop of 11.67 minutes
[DEBUG] 23:34:15: Wed 20/05 light ID:Lum_SdBRez_Douche status:1
[DEBUG] 23:34:15: Wed 20/05 entering loop of 9.26 minutes
[DEBUG] 23:34:18: Wed 20/05 exiting loop of 9.26 minutes
[DEBUG] 23:34:19: Wed 20/05 light ID:Prise_Bureau status:0
[DEBUG] 23:34:19: Wed 20/05 entering loop of 9.24 minutes
[DEBUG] 23:34:22: Wed 20/05 exiting loop of 9.24 minutes
[DEBUG] 23:34:23: Wed 20/05 light ID:Prise_Bureau status:1
[DEBUG] 23:34:23: Wed 20/05 entering loop of 10.7 minutes
[DEBUG] 23:34:26: Wed 20/05 exiting loop of 10.7 minutes
[DEBUG] 23:34:27: Wed 20/05 light ID:Lum_SdBRez_Douche status:0
[DEBUG] 23:34:27: Wed 20/05 entering loop of 4.23 minutes
[DEBUG] 23:34:29: Wed 20/05 exiting loop of 4.23 minutes
Modifié par jojo
Posté(e)

Simu presence fait que la simulation est active entre le coucher du soleil et l'heure de fin définie et est normalement toujours a 1 (sauf si on est présent évidemment)

Override permet que la simu tourne a n'importe quelle heure, du moment qu'elle est a 1

Donc ce n'est pas inutile (pour moi.)

Sent from my phone

Posté(e)

pour prolonger la réflexion.

Overide, n'a d'utilité que si Simu_presence est à  1 (et permet en effet de lancer la simu avant le couché du soleil) (c'est comme cela que je l'ai compris en tout cas)

Donc évidemment que c'est utile, mais on pourrait avoir le même résultat (selon moi) avec 1 variable et 3 valeurs (Simu_presence = 2 aurait la signification de l'actuel Simu_presence =  1 et overide = 1)

Posté(e)

Hmmm, oui tout est possible mais penses que le process qui force la simu ne connait pas nécessairement le process qui active ou non.

 

dans mon cas gea active la simulation si les conditions de présence sont remplies

 

et j'ai un vd qui me permet de forcer la simu manuellement.

 

Exemple de cas: Le VD qui force la simu, quand il se désactive, dans ton exemple, il met 0 ou 1 ? (seul gea le sait)

Comment gea sais s'il doit/ne doit pas activer la simu si elle est forcée ?

 

Alors oui, un autre fonctionnement est possible probablement, mais sans doute moins simple.

Posté(e)

toujours partage d'idées, sans aucune prétention :

  • absent + forcé => 2 (avant simu 1, overide 1)
  • présent => 0 (avant simu 0, overide 0)
  • absent + non forcé => 1 (avant simu 1 , overide 0)

 

 

Exemple de cas: Le Virtual Device qui force la simu, quand il se désactive, dans ton exemple, il met 0 ou 1 ? (seul gea le sait)

lorsque je force la simu, je suis à  2. Si je désactive la simu (forcée ou pas), je mets à  0. Si je veux juste désactiver le forçage, je passe à  1.

 

Mais de toute façon, je ne peux pas avoir overide = 1 et simu = 0, car alors YAPS perd les pédales, et avec "ma" proposition ce n'est pas possible.

 

Au niveau des process :

  • activer simu si >= 1
  • forcer simu si = 2

Pour moi, c'est génial comme c'est, et je sais que je dois faire attention à  ne pas entrer la combinaison overide = 1 et simu = 0

Posté(e)

Si je veux juste désactiver le forçage, je passe à  1.

 

Et comment tu sais que GEA ne l'a pas mis à  0 entre-temps ?

Pour faire ça, tu dois faire "communiquer les deux processus"

Et donc avant toute action, aller lire le status de la VG avant d'agir dessus...

Gea doit vérifier que la VG n'est pas à  deux avant d'activer YAPS à  l'heure voulue... mais doit aussi gérer le cas si la vg est remise de 2 à  1, ou de 2 à  0, doit t'il s'activer ou non ?

Le VD, les boutons, le bouton override, doit deviner le status voulu par GEA pour savoir si'il faut remettre 0 ou 1...

 

-> plus compliqué -> moins d'utilisateurs potentiels de YAPS ;-)

 

Pour le problème de YAPS qui perd les pédales quand  overide = 1 et simu = 0, je vais voir pour patcher le code.

 

A+ !  :) 

  • 2 semaines après...
Posté(e)

Sebcbien,

On est sorti hier soir, et malheureusement le YAPS n'a pas démarré comme il faut.

Voici le log :

[DEBUG] 18:47:11: Sat 06/06 Presence Simulator | v2.6.2
[DEBUG] 18:47:11: Sat 06/06 --------------------------------
[DEBUG] 18:47:11: Sat 06/06 Waiting for next Sunset: 21:50 -> Simulation OFF.
[DEBUG] 19:47:11: Sat 06/06 Waiting for next Sunset: 21:50 -> Simulation OFF.
[DEBUG] 20:47:12: Sat 06/06 Waiting for next Sunset: 21:50 -> Simulation OFF.
[DEBUG] 21:47:12: Sat 06/06 Waiting for next Sunset: 21:50 -> Simulation OFF.
[DEBUG] 23:31:13: Sat 06/06 Presence Simulator is Terminated
[DEBUG] 23:31:13: Sat 06/06 Simu = 0, Exit from scene

On voit bien qu'il a détecté que nous sommes parti à  18h47 : ok

à  18h47, il attend le prochain couché du soleil qui aura lieu à  21h50 : ok

à  18h57, 20h47, 21h47 : il refait le test. Pourquoi? puisque il sait que c'est à  21h50 qui doit commencer.

à  21h50 : RIEN  :(

à  23h31 il détecte bien notre retour, et je confirme physiquement qu'il n'y avait aucune lampe allumée.

 

Maintenant, quand je fais avec overide = ON, cela fonctionne :

[DEBUG] 08:05:04: Sun 07/06 Presence Simulator | v2.6.2
[DEBUG] 08:05:04: Sun 07/06 --------------------------------
[DEBUG] 08:05:04: Sun 07/06 Manual Override Activated -> Simulation ON
[DEBUG] 08:05:04: Sun 07/06 Turning On always on lights:
[DEBUG] 08:05:04: Sun 07/06 Device: Lum_SalonTV On
[DEBUG] 08:05:04: Sun 07/06 Now randomizing other lights...
[DEBUG] 08:05:05: Sun 07/06 light ID:Lum_SdBEtage status:1
[DEBUG] 08:05:05: Sun 07/06 entering loop of 9.58 minutes

Cela devrait provenir du process de déclenchement au couché du soleil qui aurait un problème ?

Posté(e)

sebcbien,

J'ai une bonne et une mauvaise nouvelle:

  • la bonne : j'ai trouvé ce qui faisait que la simulation ne démarrait pas : en fait j'avais heure de fin 00h10, et avec 23h10, pas de problème => il interprète "mal" les heures après minuit
  • la mauvaise : tu devrais être capable de reproduire l'erreur, et donc de la corriger. J'ai regardé dans le script, mais c'est beaucoup trop compliqué pour moi.

MERCI

Posté(e)

Bien, ça fait avancer le schmilblick :-)

 

Moi j'ai 1h10 (et tout va bien)

 

Vu que nous ne sommes quasi jamais absents pour le moment, et que quand nous le sommes, je n'ai pas le temps de débuguer, je ferai ça durant mes vacances de juillet/aout :-)

le code est un peu loin dans ma mémoire et je vais devoir m'y replonger.

Enfin, maintenant c'est moins bloquant que tu as trouvé.

Tu peux essayer avec 23h50, 00h30 etc pour comptrendre exactement la période ou ça bloque.

A+

Posté(e)

@sebcbien,

je ne comprends rien, j'ai tout remis EXACTEMENT comme avant, et le simulateur fonctionne parfaitement...

Peut-être fallait-il faire une modif àla scène pour qu'elle se réinitialise correctement.

Je reste sur ma fin, car je n'ai pas d'expllication pourquoi ça ne fonctionnait pas, et que maintenant ok.

Excuse-moi de t'avoir dérangé pour ça et merci pour ta disponibilité.

Posté(e)

Je préfère ça :-)

Tu as peut être mis un O à  la place du 0, ou une petite corruption du script dans la DB suite à  une migration...

 

Content pour toi, A+

  • 2 semaines après...
Posté(e)

sebcbien,

Nous sommes sorti hier soir (reconstitution Waterloo2015), et j'ai pu confirmer que je simulateur fonctionnait  :74:  :74:

Cependant, j'ai observé 2 points à  améliorer (selon moi) :

  1. lampe always on after simu : j'aurais pensé que c'était une lampe qui s'allumait automatiquement lorsque la variable Simu = 0. En fait elle s'est allumée dès la fin de la simulation programmée à  l'heure que j'avais donnée (0h10), et ce jusqu'au moment où je l'ai éteinte manuellement. C'est pas cool, cela, entre-autre, consomme énormément d'électricité, surtout si tu es parti plusieurs jours (dans le cas présent elle serait resté allumée de 0h10 à  21h58 (=prochain sunset). Je ne pense pas que c'était ton idée initiale.
  2. la simu ne s'est pas arrêtée à  0h10, mais à  0h18, après l'exécution du dernier loop aléatoire. Quand j'y repense, c'est cool, car cela signifie une fin de simulation à  une heure qui varie aléatoirement entre la date de fin définie et le rdnmaxtime.

Donc il me semble que la seule chose à  "améliorer" est le point 1.

 

Voici l'extrait de mon debug pour illustrer :

[DEBUG] 00:09:27: Sat 20/06 light ID:Prise_Bureau status:1
[DEBUG] 00:09:27: Sat 20/06 entering loop of 9.24 minutes
[DEBUG] 00:18:41: Sat 20/06 exiting loop of 9.24 minutes
[DEBUG] 00:18:41: Sat 20/06 TurnOff All lights!
[DEBUG] 00:18:41: Sat 20/06 Device: Lum_SdBRez_Douche Off
[DEBUG] 00:18:41: Sat 20/06 Device: Lum_SalleManger Off
[DEBUG] 00:18:41: Sat 20/06 Device: Prise_Bureau Off
[DEBUG] 00:18:41: Sat 20/06 Device: Lum_SdBEtage Off
[DEBUG] 00:18:41: Sat 20/06 Device: Lum_SalonTV Off
[DEBUG] 00:18:41: Sat 20/06 Manual Light Settings: Turned On light: Lum_HallEntrée
[DEBUG] 00:18:41: Sat 20/06 Simulation is deactivated
[DEBUG] 00:18:41: Sat 20/06 Presence Simulator will Restart tomorrow around 21:58
[DEBUG] 00:20:41: Sat 20/06 Waiting for next Sunset: 21:58 -> Simulation OFF.
[DEBUG] 00:30:41: Sat 20/06 Presence Simulator is Terminated
[DEBUG] 00:30:41: Sat 20/06 Simu = 0, Exit from scene
Posté(e)

Effectivement, j'ai rajouté les lampes àallumer par la suite àcause de demandes mais je n'ai pas pensé àce cas de figure... En fait chez moi J'allume une lampe qui s'éteint de toute façon toute seule après X minutes.

Je dois ajouter un test avant de les allumer.

Je mets ça dans ma todo.

Sent from my SM-N910F using Tapatalk

  • Upvote 1
Posté(e)

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
Posté(e)

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
  • 5 semaines après...
Posté(e)

Merci Sebcbien,, je viens seulement de recevoir àl'instant les notifs de tes posts ... je teste ce soir ton dernier script et te confirme

Merci

×
×
  • Créer...