Page 2 sur 3

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

Publié : 01 mars 2020, 17:24
par f0emm
Salut,
Après quelques heures de recherche et d'essai je bloque !
Message d'erreur dans le log :
2020-03-01 17:17:04.757 Error: EventSystem: commandArray in script 22 Script éclairage 3*8 should only return ['string']='actionstring' or [integer]={['string']='actionstring'}
Je ne dois pas en être loin mais ça coince à ce niveau :

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:10' 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
	
	elseif 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
	
	elseif 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

return commandArray
A mon avis l'écriture n'est pas bonne :

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

Un avis ?
Merci
Bonne fin de journée.
A+
Fab

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

Publié : 01 mars 2020, 17:40
par denis_brasseur
f0emm a écrit : 01 mars 2020, 17:24
A mon avis l'écriture n'est pas bonne :

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

Code : Tout sélectionner

if num == 3 or num == 6 or num == 9 or num == 12 ....etc..... then

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

Publié : 01 mars 2020, 17:43
par f0emm
Salut
Merci pour votre réponse.
J'ai déjà essayé, je retente je m'étais peut être trompé quelque part
Verdict dans quelques minutes :)

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

Publié : 01 mars 2020, 17:58
par denis_brasseur
Tu peux aussi utiliser modulo (reste de la division par)

Code : Tout sélectionner

if num % 3 == 0 then

else if (num - 1) % 3 then

else if (num + 1) % 3 then

end

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

Publié : 01 mars 2020, 18:01
par f0emm
Salut
Ne fonctionne pas.
Si je ne mets que if num == 8 par exemple ça fonctionne, dès que je cumul ça déconne, il doit manquer quelque chose ?
Et j'ai toujours ce message d'erreur :

2020-03-01 17:56:14.608 Error: EventSystem: commandArray in script Variable semaine 3*8 should only return ['string']='actionstring' or [integer]={['string']='actionstring'}

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

Publié : 01 mars 2020, 18:16
par denis_brasseur
f0emm a écrit : 01 mars 2020, 18:01
2020-03-01 17:56:14.608 Error: EventSystem: commandArray in script Variable semaine 3*8 should only return ['string']='actionstring' or [integer]={['string']='actionstring'}
Ton erreur n'et pas dans la condition, mais dans commandArray, ligne 22
2020-03-01 17:17:04.757 Error: EventSystem: commandArray in script 22 Script éclairage 3*8 should only return ['string']='actionstring' or [integer]={['string']='actionstring'}

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

Publié : 01 mars 2020, 18:33
par f0emm
Salut,
Le message d'erreur est résolu

Je pense que l'on approche du but mais il y a encore un bug

Code : Tout sélectionner

commandArray = {}

local semaine = (os.date("%W"))

--- pour essai
local num = semaine +3

    
	if num % 3 == 0 then
	    commandArray['Variable:Semaine 3*8']=tostring(1)
	  
	
	elseif (num - 1) % 3 then
	    commandArray['Variable:Semaine 3*8']=tostring(2)
	   
	
	elseif (num + 1) % 3 then
	    commandArray['Variable:Semaine 3*8']=tostring(3)
end
	
return commandArray
Si je laisse num = semaine (soit num=8 ) ma variable passe à 2
Si je mets num = semaine +1 (soit num=9 ) ma variable passe à 1
Si je met num = semaine +2 (soit num=10 ) ma variable passe à 2

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

Publié : 01 mars 2020, 18:45
par denis_brasseur

Code : Tout sélectionner

commandArray = {}

local semaine = (os.date("%W"))

--- pour essai
--local num = semaine +3

    
if num % 3 == 0 then
	    commandArray['Variable:Semaine 3*8']=tostring(1)
elseif (num - 1) % 3 == 0 then
	    commandArray['Variable:Semaine 3*8']=tostring(2)
elseif (num + 1) % 3 == 0 then
	    commandArray['Variable:Semaine 3*8']=tostring(3)
end
	
return commandArray

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

Publié : 01 mars 2020, 18:51
par f0emm
Merci beaucoup !

Il manquait == 0

Ça fonctionne

Code : Tout sélectionner

commandArray = {}

local semaine = (os.date("%W"))

--- pour essai
local num = semaine +2

-- 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
	
return commandArray
J'aurais au moins appris quelque chose
Un grand merci
Bonne soirée
A+
Fab

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

Publié : 01 mars 2020, 18:58
par f0emm
Le script complet
On verra demain s'il fonctionne

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