[Résolu] Eclairage en fonction de la semaine ( Horaire 3*8 )

Forum dédié aux problématiques concernant les scripts pour DomoticZ.
Entourez votre code et les logs avec les balises nommées code grâce au bouton <\>.
f0emm
Messages : 64
Inscription : 23 déc. 2015, 20:52

[Résolu] Eclairage en fonction de la semaine ( Horaire 3*8 )

Message par f0emm »

Bonjour,
Travaillant en 3*8 je souhaiterais automatiser mon éclairage en fonction de ma semaine de travail mais je bloque un peu.
Effectivement, changeant chaque semaine d'horaire j'aurais souhaité pouvoir récupérer le N° de la semaine dans domoticz ou établir un planning toute les 3 semaines mais je ne trouve rien à ce sujet.
Quelqu'un aurait il une idée ?
Je vous en remercie d'avance.
Bonne fin de journée.
A+
Fab

Script à jour
Ne pas oublier de créer la variable

Code : Tout sélectionner

commandArray = {}

local heure = os.date("%H:%M")
local semaine = (os.date("%W"))
local num = semaine +1 --- le numéro de la semaine ayant une semaine de retard
local horaire = uservariables['Semaine 3*8']

-- retourne le jour actuel en français ex: "mardi"
days = {"dimanche","lundi","mardi","mercredi","jeudi","vendredi","samedi"}
jour = days[(os.date("%w")+1)]
-- il fait nuit
nightTime = timeofday['Nighttime']


if heure == '00:05' then
    
-- Matin    
	if num % 3 == 0 then
	    commandArray['Variable:Semaine 3*8']=tostring(1)
	  
-- Nuit	
	elseif (num - 1) % 3 == 0 then
	    commandArray['Variable:Semaine 3*8']=tostring(2)
	   
-- Après midi	
	elseif (num + 1) % 3 == 0 then
	    commandArray['Variable:Semaine 3*8']=tostring(3)
    end 
	
end

---------------------------------------------------------------------------------------

if nightTime and otherdevices['Congé']=='Off' and otherdevices['Férié']=='Off' then

-- Eclairage huit du matin

    if heure == "04:18" and horaire == 1 and (jour ~= "samedi" and jour ~= "dimanche") then
        
        commandArray['Eclairage entréé']='On for 5'
        commandArray['Eclairage séjour']='On for 5'
        commandArray['Eclairage préau']='On for 3'
    end
    
-- Eclairage huit de nuit

    if heure == "05:30" and horaire == 2 and (jour ~= "samedi" and jour ~= "dimanche" and jour ~= "lundi") then
       
        commandArray['Eclairage entréé']='On for 5'
        commandArray['Eclairage séjour']='On for 5'
        commandArray['Eclairage préau']='On for 3'
    end
    
    if heure == "23:30" and horaire == 2 and jour == "vendredi" then
       
        commandArray['Eclairage entréé']='On for 5'
        commandArray['Eclairage séjour']='On for 5'
        commandArray['Eclairage préau']='On for 3'
    end
    
-- Eclairage huit d' après midi

    if heure == "21:30" and horaire == 3 and (jour ~= "vendredi" and jour ~= "samedi" and jour ~= "dimanche") then
       
        commandArray['Eclairage entréé']='On for 5'
        commandArray['Eclairage séjour']='On for 5'
        commandArray['Eclairage préau']='On for 3'
    end
end

return commandArray
Dernière modification par f0emm le 01 mars 2020, 19:04, modifié 1 fois.
Wolfen38
Messages : 1983
Inscription : 19 oct. 2017, 14:49

Re: Eclairage en fonction de la semaine ( Horaire 3*8 )

Message par Wolfen38 »

Salut,

Tu vas dans configuration-plus d'option-plan-profil de gestion

Tu crées autant de profil que t'as de semaines différentes, semaine1, semaine2....

Et apres, pour chaque semaine, tu paramètres tes interrupteurs en mettant un planing.
f0emm
Messages : 64
Inscription : 23 déc. 2015, 20:52

Re: Eclairage en fonction de la semaine ( Horaire 3*8 )

Message par f0emm »

Salut,
Je viens d'aller voir mais ne comprends pas de trop !
Par exemple qu'est ce qui déclenche semaine N°10 de l’année = semaine de nuit ?
Merci
Bonne soirée
A+
Fab
Wolfen38
Messages : 1983
Inscription : 19 oct. 2017, 14:49

Re: Eclairage en fonction de la semaine ( Horaire 3*8 )

Message par Wolfen38 »

La semaine active est ensuite dans configuration-parametre-calendrier.

Soit tu vas dans cette rubrique et tu la changes manuellement, soit tu fais un bout de programme pour que ça change tout seul en fonction de la périodicité de ton planning.
f0emm
Messages : 64
Inscription : 23 déc. 2015, 20:52

Re: Eclairage en fonction de la semaine ( Horaire 3*8 )

Message par f0emm »

Salut,
Merci pour ta réponse, du coup j'ai trouvé ceci -> http://domo-attitude.fr/domoticz-editeur-de-planning/
Mais je ne pense pas que cela change ma situation étant donné qu'il me faut automatiser le changement de semaine.
Ce que je recherche c'est comment connaitre le N° de la semaine en cours, à partir de cela tout est réglé, un script LUA et c'est bon.
Je vais voir si je peux créer un compteur, avec remise à 1 une fois 52 passé.
Vivement que je passe en 2*8 ce sera beaucoup plus simple.
Merci
Bon dimanche
A+
Fab
thier
Messages : 807
Inscription : 26 sept. 2015, 10:32
Localisation : charente

Re: Eclairage en fonction de la semaine ( Horaire 3*8 )

Message par thier »

Pas testé mais à priori os.date("%W") donne le numéro de semaine. Si c'est bon il n'y a pas besoin de compteur.
Dernière modification par thier le 01 mars 2020, 12:32, modifié 1 fois.
PI3+, Buster, Domoticz V2020.2, rflink, zwave, chauffage piloté par qubino, sondes oregon et Vil1d, boite aux lettres détection passage facteur, volets roulants qubino fibaro.
f0emm
Messages : 64
Inscription : 23 déc. 2015, 20:52

Re: Eclairage en fonction de la semaine ( Horaire 3*8 )

Message par f0emm »

Salut,
Effectivement c'est ce que je viens de voir après recherche.
Je vais essayer de mettre ça en application.
Merci
Bon dimanche
A+
Fab
thier
Messages : 807
Inscription : 26 sept. 2015, 10:32
Localisation : charente

Re: Eclairage en fonction de la semaine ( Horaire 3*8 )

Message par thier »

je verrai un truc du genre

Code : Tout sélectionner

local semaine = {}
semaine["01"]="matin";
semaine["02"]="nuit";
semaine["03"]="apresmidi";
semaine["04"]="matin";
semaine["05"]="nuit";
semaine["06"]="apresmidi";
semaine["07"]="matin";
semaine["08"]="nuit";
semaine["09"]="apresmidi";
--etc jusqu'à semaine 52

commandArray = {}
local numerosemaine = os.date("%W")
print ('numerosemaine '..numerosemaine)

local faction = semaine[os.date("%W")]
print('faction '..faction)

return commandArray
PI3+, Buster, Domoticz V2020.2, rflink, zwave, chauffage piloté par qubino, sondes oregon et Vil1d, boite aux lettres détection passage facteur, volets roulants qubino fibaro.
f0emm
Messages : 64
Inscription : 23 déc. 2015, 20:52

Re: Eclairage en fonction de la semaine ( Horaire 3*8 )

Message par f0emm »

Salut,
Voilà le script TIME que je viens de faire :

Code : Tout sélectionner

commandArray = {}

local heure = os.date("%H:%M")
local semaine = tonumber (os.date("%W"))
local num = semaine +1
local horaire = uservariables['Semaine 3*8']

-- retourne le jour actuel en français ex: "mardi"
days = {"dimanche","lundi","mardi","mercredi","jeudi","vendredi","samedi"}
jour = days[(os.date("%w")+1)]
-- il fait nuit
nightTime = timeofday['Nighttime']


if heure == '00:01' then
    
	if num == 3 or 6 or 9 or 12 or 15 or 18 or 21 or 24 or 27 or 30 or 33 or 36 or 39 or 42 or 45 or 48 or 51 then
	    commandArray['Variable:Semaine 3*8']=tostring(1)
	    commandArray['UpdateVariable'] = 5
	end
	
	if num == 4 or 7 or 10 or 13 or 16 or 19 or 22 or 25 or 28 or 31 or 34 or 37 or 40 or 43 or 46 or 49 or 52 then
	    commandArray['Variable:Semaine 3*8']=tostring(2)
	    commandArray['UpdateVariable'] = 5
	end 
	
	if num == 2 or 5 or 8 or 11 or 14 or 17 or 20 or 23 or 26 or 29 or 32 or 35 or 38 or 41 or 44 or 47 or 50 or 53 then
	    commandArray['Variable:Semaine 3*8']=tostring(3)
	    commandArray['UpdateVariable'] = 5
	end 
	
end

---------------------------------------------------------------------------------------

if nightTime and otherdevices['Congé']=='Off' and otherdevices['Férié']=='Off' then

-- Eclairage huit du matin

    if heure == "04:18" and horaire == 1 and (jour ~= "samedi" and jour ~= "dimanche") then
        
        commandArray['Eclairage entréé']='On for 5'
        commandArray['Eclairage séjour']='On for 5'
        commandArray['Eclairage préau']='On for 3'
    end
    
-- Eclairage huit de nuit

    if heure == "05:30" and horaire == 2 and (jour ~= "samedi" and jour ~= "dimanche" and jour ~= "lundi") then
       
        commandArray['Eclairage entréé']='On for 5'
        commandArray['Eclairage séjour']='On for 5'
        commandArray['Eclairage préau']='On for 3'
    end
    
    if heure == "23:30" and horaire == 2 and jour == "vendredi" then
       
        commandArray['Eclairage entréé']='On for 5'
        commandArray['Eclairage séjour']='On for 5'
        commandArray['Eclairage préau']='On for 3'
    end
-- Eclairage huit d' après midi

    if heure == "21:30" and horaire == 3 and (jour ~= "vendredi" and jour ~= "samedi" and jour ~= "dimanche") then
       
        commandArray['Eclairage entréé']='On for 5'
        commandArray['Eclairage séjour']='On for 5'
        commandArray['Eclairage préau']='On for 3'
    end
end

return commandArray
Il y a surement des corrections à apporter.
A+
Fab
f0emm
Messages : 64
Inscription : 23 déc. 2015, 20:52

Re: Eclairage en fonction de la semaine ( Horaire 3*8 )

Message par f0emm »

Salut,
Comme convenu je rencontre un soucis ici :

Code : Tout sélectionner

if num == 3 or 6 or 9 or 12 or 15 or 18 or 21 or 24 or 27 or 30 or 33 or 36 or 39 or 42 or 45 or 48 or 51 then
	    commandArray['Variable:Semaine 3*8']=tostring(1)
	    commandArray['UpdateVariable'] = 5
Je dois louper quelque chose ?
Merci
Bon après midi
A+
Fab
Répondre