Aller au contenu
Rem's

Erreur scène porte d'entrée

Recommended Posts

Bonjour à tous, 

j'espère que la communauté va bien ...

 

Je sollicite un coup de main car j'ai voulu modifié je ne sais pas quoi et ma scène est en erreur

 

D'avance merci, bon week end à tous !

 

--[[
%% properties
772 value
Jour-Nuit
%% globals
--]]
 
-- Ce scénario sera executé uniquement à l'ouverture / fermeture
-- du décteur de porte ID 772 (porte d'entrée)

local door = 772
local light = 459 -- Spots hall
-- local startSource = fibaro:getSourceTrigger();

local heure = os.date("%R");
date = os.date("%d/%m/%Y");
local Message = string.format("Lancement du %s a %s", date, heure)
    fibaro:debug(Message)

-- local heure = string.format(os.date("%H"), "%2d")..string.format(os.date("%M"), "%2d")
-- local heureValable = heure >= "1830" or heure < "2115"
local enAlerte = (tonumber(fibaro:getValue(door, "value")) > 0)
local heureValable = fibaro:getGlobalValue("Jour-Nuit")== ("Jour") -- à partir de 6h30
local heureValable1 = fibaro:getGlobalValue("Jour-Nuit")== ("Matin") -- à partir de 9h00
local heureValable2 = fibaro:getGlobalValue("Jour-Nuit")== ("Midi") -- à partir de 12h00
local heureValable3 = fibaro:getGlobalValue("Jour-Nuit")== ("Après-midi") -- à partir de 14h300
local heureValable4 = fibaro:getGlobalValue("Jour-Nuit")== ("Soir") -- à partir de 17h00
local heureValable5 = fibaro:getGlobalValue("Jour-Nuit")== ("Soirée") -- à partir de 21h00
local heureValable6 = fibaro:getGlobalValue("Jour-Nuit")== ("Nuit") -- à partir de 23h59

  if enAlerte and heureValable -- Jour --
then
   -- fibaro:startScene(370);
     fibaro:call(light, "turnOn") 
  else
     fibaro:call(light, "turnOff") -- Spot Hall
  end
 if fibaro:getGlobalValue("TV")== ("On")
 then
   fibaro:call(56, "pressButton", "1")
   fibaro:debug("TV extinction")
   else
   fibaro:debug("TV déjà éteinte")
   fibaro:debug("Porte ouverte Jour")
  end
  elseif enAlerte and heureValable1 -- Matin --
then
  if tonumber(fibaro:getValue(459, "value")) > 0
    then fibaro:debug("lumière déjà allumée")
    fibaro:killScenes(439)
    else
   fibaro:call(light, "setValue", "30"); -- Spots Hall
     fibaro:sleep(15*1000);
   fibaro:call(light, "turnOff") -- Spot Hall
     fibaro:debug("Porte ouverte matin")
   end
  elseif enAlerte and heureValable2 -- Midi --
then
  fibaro:sleep(10*1000);
       fibaro:debug("Porte ouverte à midi") 

  elseif enAlerte and heureValable3 -- Après-midi --
then
     -- fibaro:call(401, "pressButton", "8") -- Annonce Petula
       fibaro:debug("Porte ouverte à Après-midi") 

  elseif enAlerte and heureValable4 -- Soir --
then
  if tonumber(fibaro:getValue(459, "value")) > 0
    then fibaro:debug("lumière déjà allumée")
    fibaro:killScenes(439)
    else
   fibaro:call(light, "setValue", "40"); -- Spots Hall
     fibaro:sleep(15*1000);
    fibaro:call(light, "turnOff") -- Spot Hall
    fibaro:debug("Porte ouverte le soir") 

  elseif enAlerte and heureValable5 -- Soirée
then
  if tonumber(fibaro:getValue(459, "value")) > 0
    then fibaro:debug("lumière déjà allumée")
    fibaro:killScenes(439)
    else
  fibaro:call(light, "setValue", "50"); -- Spots Hall
     fibaro:sleep(15*1000);
  fibaro:call(light, "turnOff")  -- Spot Hall
     fibaro:debug("Porte ouverte en soirée")

  elseif enAlerte and heureValable6 -- Nuit --
then
    fibaro:call(light, "setValue", "20"); -- Spots Hall
    fibaro:sleep(15*1000);
  fibaro:call(659, "turnOff")  -- Lampe boule
    fibaro:debug("Porte ouverte la nuit") -- Nuit --

     -- fibaro:killScenes(439)
else
     fibaro:debug("Porte fermée")
    end

Partager ce message


Lien à poster
Partager sur d’autres sites

La syntaxe du if then else n'est pas :

 if fibaro:getGlobalValue("TV")== ("On")
 then
   fibaro:call(56, "pressButton", "1")
   fibaro:debug("TV extinction")
   else
   fibaro:debug("TV déjà éteinte")
   fibaro:debug("Porte ouverte Jour")
  end
  elseif enAlerte and heureValable1 -- Matin --
then

mais ta scène devrait plutôt avoir la structure suivante :

if enAlerte and heureValable then -- Jour --
	-- traitement pour le jour
elseif enAlerte and heureValable1 then	-- Matin --
	-- traitement pour le matin
elseif enAlerte and heureValable2 then -- Midi --
	-- traitement pour le midi
elseif enAlerte and heureValable4 then -- Soir --
	-- traitement pour le soir
elseif enAlerte and heureValable5 then -- Soirée
	-- traitement pour la soirée 
elseif enAlerte and heureValable6 then -- Nuit --
	-- traitement pour la nuit 
else
	fibaro:debug('Global "Jour-nuit", valeur inconnue");
end

Remarque :

  1. Si la scène est en erreur, il serait normal de mentionner le message d'erreur.
  2. N'hésite pas à utiliser l'insertion de code "</>" (en sélectionnant LUA), cela rend les messages plus lisibles.
  3. Enfin, une présentation du code avec les bons décalages (indentation en jargon globish) facilite la compréhension, et la détection des erreurs de syntaxe.

Partager ce message


Lien à poster
Partager sur d’autres sites

Merci pour ta réponse Barelle !!

J'ai essayé de faire le ménage mais j'ai une erreur :

[DEBUG] 16:42:53: 2021-12-11 16:42:53.320872 [ fatal] Unknown exception: /opt/fibaro/scenes/100.lua:44: 'end' expected (to close 'if' at line 31) near 'elseif'

 

--[[
%% properties
772 value
Jour-Nuit
%% globals
--]]

local door = 772
local light = 459 -- Spots hall
-- local startSource = fibaro:getSourceTrigger();

local heure = os.date("%R");
date = os.date("%d/%m/%Y");
local Message = string.format("Lancement du %s a %s", date, heure)
    fibaro:debug(Message)

local enAlerte = (tonumber(fibaro:getValue(door, "value")) > 0)
local heureValable = fibaro:getGlobalValue("Jour-Nuit")== ("Jour") -- à partir de 6h30
local heureValable1 = fibaro:getGlobalValue("Jour-Nuit")== ("Matin") -- à partir de 9h00
local heureValable2 = fibaro:getGlobalValue("Jour-Nuit")== ("Midi") -- à partir de 12h00
local heureValable3 = fibaro:getGlobalValue("Jour-Nuit")== ("Après-midi") -- à partir de 14h300
local heureValable4 = fibaro:getGlobalValue("Jour-Nuit")== ("Soir") -- à partir de 17h00
local heureValable5 = fibaro:getGlobalValue("Jour-Nuit")== ("Soirée") -- à partir de 21h00
local heureValable6 = fibaro:getGlobalValue("Jour-Nuit")== ("Nuit") -- à partir de 23h59

  if enAlerte and heureValable -- Jour --
then
     fibaro:call(light, "turnOn") 
  else
     fibaro:call(light, "turnOff") -- Spot Hall
   elseif enAlerte and heureValable1 -- Matin --
then
  if tonumber(fibaro:getValue(459, "value")) > 0
    then fibaro:debug("lumière déjà allumée")
       else
   fibaro:call(light, "setValue", "30"); -- Spots Hall
     fibaro:sleep(15*1000);
   fibaro:call(light, "turnOff") -- Spot Hall
       fibaro:debug("Porte ouverte matin")
  elseif enAlerte and heureValable2 -- Midi --
then
  fibaro:sleep(10*1000);
       fibaro:debug("Porte ouverte à midi") 

  elseif enAlerte and heureValable3 -- Après-midi --
then
  fibaro:call(401, "pressButton", "8") -- Annonce Petula
       fibaro:debug("Porte ouverte à Après-midi") 

  elseif enAlerte and heureValable4 -- Soir --
then
  if tonumber(fibaro:getValue(459, "value")) > 0
    then fibaro:debug("lumière déjà allumée")
    fibaro:killScenes(439)
    else
   fibaro:call(light, "setValue", "40"); -- Spots Hall
     fibaro:sleep(15*1000);
    fibaro:call(light, "turnOff") -- Spot Hall
    fibaro:debug("Porte ouverte le soir") 

  elseif enAlerte and heureValable5 -- Soirée
then
  if tonumber(fibaro:getValue(459, "value")) > 0
    then fibaro:debug("lumière déjà allumée")
    fibaro:killScenes(439)
    else
  fibaro:call(light, "setValue", "50"); -- Spots Hall
     fibaro:sleep(15*1000);
  fibaro:call(light, "turnOff")  -- Spot Hall
     fibaro:debug("Porte ouverte en soirée")

  elseif enAlerte and heureValable6 -- Nuit --
then
    fibaro:call(light, "setValue", "20"); -- Spots Hall
    fibaro:sleep(15*1000);
  fibaro:call(659, "turnOff")  -- Lampe boule
    fibaro:debug("Porte ouverte la nuit") -- Nuit --

     -- fibaro:killScenes(439)
else
     fibaro:debug("Porte fermée")
    end

Partager ce message


Lien à poster
Partager sur d’autres sites
--[[
%% properties
772 value
Jour-Nuit
%% globals
--]]
 
-- Ce scénario sera executé uniquement à l'ouverture / fermeture
-- du décteur de porte ID 772 (porte d'entrée)

local door = 772
local light = 459 -- Spots hall
-- local startSource = fibaro:getSourceTrigger();

local heure = os.date("%R");
date = os.date("%d/%m/%Y");
local Message = string.format("Lancement du %s a %s", date, heure)
    fibaro:debug(Message)

-- local heure = string.format(os.date("%H"), "%2d")..string.format(os.date("%M"), "%2d")
-- local heureValable = heure >= "1830" or heure < "2115"
local enAlerte = (tonumber(fibaro:getValue(door, "value")) > 0)
local heureValable = fibaro:getGlobalValue("Jour-Nuit")== ("Jour") -- à partir de 6h30
local heureValable1 = fibaro:getGlobalValue("Jour-Nuit")== ("Matin") -- à partir de 9h00
local heureValable2 = fibaro:getGlobalValue("Jour-Nuit")== ("Midi") -- à partir de 12h00
local heureValable3 = fibaro:getGlobalValue("Jour-Nuit")== ("Après-midi") -- à partir de 14h300
local heureValable4 = fibaro:getGlobalValue("Jour-Nuit")== ("Soir") -- à partir de 17h00
local heureValable5 = fibaro:getGlobalValue("Jour-Nuit")== ("Soirée") -- à partir de 21h00
local heureValable6 = fibaro:getGlobalValue("Jour-Nuit")== ("Nuit") -- à partir de 23h59

  if enAlerte and heureValable -- Jour --
then
   -- fibaro:startScene(370);
     fibaro:call(light, "turnOn") 
  else
     fibaro:call(light, "turnOff") -- Spot Hall
 -- if fibaro:getGlobalValue("TV")== ("On")
 -- then
   -- fibaro:call(56, "pressButton", "1")
   -- fibaro:debug("TV extinction")
   -- else
   -- fibaro:debug("TV déjà éteinte")
   -- fibaro:debug("Porte ouverte Jour")
  elseif enAlerte and heureValable1 -- Matin --
then
  if tonumber(fibaro:getValue(459, "value")) > 0
    then fibaro:debug("lumière déjà allumée")
    fibaro:killScenes(439)
    else
   fibaro:call(light, "setValue", "30"); -- Spots Hall
     fibaro:sleep(15*1000);
   fibaro:call(light, "turnOff") -- Spot Hall
     fibaro:debug("Porte ouverte matin")
  elseif enAlerte and heureValable2 -- Midi --
then
  fibaro:sleep(10*1000);
       fibaro:debug("Porte ouverte à midi") 

  elseif enAlerte and heureValable3 -- Après-midi --
then
     -- fibaro:call(401, "pressButton", "8") -- Annonce Petula
       fibaro:debug("Porte ouverte à Après-midi") 

  elseif enAlerte and heureValable4 -- Soir --
then
  if tonumber(fibaro:getValue(459, "value")) > 0
    then fibaro:debug("lumière déjà allumée")
    fibaro:killScenes(439)
    else
   fibaro:call(light, "setValue", "40"); -- Spots Hall
     fibaro:sleep(15*1000);
    fibaro:call(light, "turnOff") -- Spot Hall
    fibaro:debug("Porte ouverte le soir") 

  elseif enAlerte and heureValable5 -- Soirée
then
  if tonumber(fibaro:getValue(459, "value")) > 0
    then fibaro:debug("lumière déjà allumée")
    fibaro:killScenes(439)
    else
  fibaro:call(light, "setValue", "50"); -- Spots Hall
     fibaro:sleep(15*1000);
  fibaro:call(light, "turnOff")  -- Spot Hall
     fibaro:debug("Porte ouverte en soirée")

  elseif enAlerte and heureValable6 -- Nuit --
then
    fibaro:call(light, "setValue", "20"); -- Spots Hall
    fibaro:sleep(15*1000);
  fibaro:call(659, "turnOff")  -- Lampe boule
    fibaro:debug("Porte ouverte la nuit") -- Nuit --

     -- fibaro:killScenes(439)
else
     fibaro:debug("Porte fermée")
    end

J'ai retrouvé le bouton, et le code Lua !!

Partager ce message


Lien à poster
Partager sur d’autres sites

Structure la présentation de ton code et tu verras tout de suite que le elseif de ta ligne 44 qui suit un else n'a aucun sens...

Partager ce message


Lien à poster
Partager sur d’autres sites

J'ai essayé de simplifier la scène pour m'y retrouver et suivre tes conseils ...

Ça donne ça

--[[
%% properties
772 value
%% globals
--]]

local door = 772
local light = 459 -- Spots hall
local startSource = fibaro:getSourceTrigger(); 

local heure = string.format(os.date("%H"), "%2d")..string.format(os.date("%M"), "%2d")
local enAlerte = (tonumber(fibaro:getValue(door, "value")) > 0)
local heureValable = fibaro:getGlobalValue("Jour-Nuit")== ("Jour") -- à partir de 6h30
local heureValable1 = fibaro:getGlobalValue("Jour-Nuit")== ("Matin") -- à partir de 9h00
local heureValable2 = fibaro:getGlobalValue("Jour-Nuit")== ("Midi") -- à partir de 12h00
local heureValable3 = fibaro:getGlobalValue("Jour-Nuit")== ("Après-midi") -- à partir de 14h30
local heureValable4 = fibaro:getGlobalValue("Jour-Nuit")== ("Soir") -- à partir de 17h00
local heureValable5 = fibaro:getGlobalValue("Jour-Nuit")== ("Soirée") -- à partir de 21h00
local heureValable6 = fibaro:getGlobalValue("Jour-Nuit")== ("Nuit") -- à partir de 23h59

if enAlerte and heureValable then
 fibaro:call(459, "setValue", "40") -- Spots Hall
   fibaro:sleep(2*1000);
 fibaro:call(592, "turnOn") -- Plante 1
 fibaro:call(593, "turnOn") -- Plante 2
   fibaro:debug("Porte ouverte")
  else
 fibaro:call(592, "turnOff") -- Plante 1
 fibaro:call(593, "turnOff") -- Plante 2
    fibaro:sleep(2*1000);
 fibaro:call(459, "turnOff") -- Spot Hall
    fibaro:debug("Porte fermée")
  end
   elseif enAlerte and heureValable4 then
   if tonumber(fibaro:getValue(459, "value")) > 0
    then fibaro:debug("lumière déjà allumée")
    fibaro:killScenes(427)
    else
   fibaro:call(light, "setValue", "30"); -- Spots Hall
     fibaro:sleep(15*1000);
   fibaro:call(light, "turnOff") -- Spot Hall
     fibaro:debug("Porte ouverte matin")
      end
   fibaro:debug("Fin de script")
     fibaro:sleep(60*1000);
end

 

D'avance merci de ton aide, précieuse !!

Partager ce message


Lien à poster
Partager sur d’autres sites

DEBUG] 17:50:29: 2021-12-11 17:50:29.640256 [ fatal] Unknown exception: /opt/fibaro/scenes/427.lua:38: expected near 'elseif'
 

Partager ce message


Lien à poster
Partager sur d’autres sites

Même réponse...

Cela devrait plutôt être quelque chose comme cela :

-[[
%% properties
772 value
%% globals
--]]

local door = 772
local light = 459 -- Spots hall
local startSource = fibaro:getSourceTrigger(); 

local heure = string.format(os.date("%H"), "%2d")..string.format(os.date("%M"), "%2d")
local enAlerte = (tonumber(fibaro:getValue(door, "value")) > 0)
local heureValable = fibaro:getGlobalValue("Jour-Nuit")== ("Jour") -- à partir de 6h30
local heureValable1 = fibaro:getGlobalValue("Jour-Nuit")== ("Matin") -- à partir de 9h00
local heureValable2 = fibaro:getGlobalValue("Jour-Nuit")== ("Midi") -- à partir de 12h00
local heureValable3 = fibaro:getGlobalValue("Jour-Nuit")== ("Après-midi") -- à partir de 14h30
local heureValable4 = fibaro:getGlobalValue("Jour-Nuit")== ("Soir") -- à partir de 17h00
local heureValable5 = fibaro:getGlobalValue("Jour-Nuit")== ("Soirée") -- à partir de 21h00
local heureValable6 = fibaro:getGlobalValue("Jour-Nuit")== ("Nuit") -- à partir de 23h59

if enAlerte and heureValable then
    fibaro:call(459, "setValue", "40") -- Spots Hall
    fibaro:sleep(2*1000);
    fibaro:call(592, "turnOn") -- Plante 1
    fibaro:call(593, "turnOn") -- Plante 2
    fibaro:debug("Porte ouverte")
elseif enAlerte and heureValable4 then
    if tonumber(fibaro:getValue(459, "value")) > 0 then
        fibaro:debug("lumière déjà allumée")
        fibaro:killScenes(427)
    else
        fibaro:call(light, "setValue", "30"); -- Spots Hall
        fibaro:sleep(15*1000);
        fibaro:call(light, "turnOff") -- Spot Hall
        fibaro:debug("Porte ouverte matin")
    end
    fibaro:debug("Fin de script")
    fibaro:sleep(60*1000);
else
    fibaro:call(592, "turnOff") -- Plante 1
    fibaro:call(593, "turnOff") -- Plante 2
    fibaro:sleep(2*1000);
    fibaro:call(459, "turnOff") -- Spot Hall
    fibaro:debug("Porte fermée")
end

 

Partager ce message


Lien à poster
Partager sur d’autres sites

En fait , dans le 1er cas après fermeture de la porte (else, je voudrais éteindre les lampes

 

--[[
%% properties
772 value
%% globals
--]]

local door = 772
local light = 459 -- Spots hall
local startSource = fibaro:getSourceTrigger(); 

local heure = string.format(os.date("%H"), "%2d")..string.format(os.date("%M"), "%2d")
local enAlerte = (tonumber(fibaro:getValue(door, "value")) > 0)
local heureValable = fibaro:getGlobalValue("Jour-Nuit")== ("Jour") -- à partir de 6h30
local heureValable1 = fibaro:getGlobalValue("Jour-Nuit")== ("Matin") -- à partir de 9h00
local heureValable2 = fibaro:getGlobalValue("Jour-Nuit")== ("Midi") -- à partir de 12h00
local heureValable3 = fibaro:getGlobalValue("Jour-Nuit")== ("Après-midi") -- à partir de 14h30
local heureValable4 = fibaro:getGlobalValue("Jour-Nuit")== ("Soir") -- à partir de 17h00
local heureValable5 = fibaro:getGlobalValue("Jour-Nuit")== ("Soirée") -- à partir de 21h00
local heureValable6 = fibaro:getGlobalValue("Jour-Nuit")== ("Nuit") -- à partir de 23h59

if enAlerte and heureValable then
    fibaro:call(459, "setValue", "40") -- Spots Hall
    fibaro:sleep(2*1000);
    fibaro:call(592, "turnOn") -- Plante 1
    fibaro:call(593, "turnOn") -- Plante 2
    fibaro:debug("Porte ouverte")
  else
    fibaro:call(592, "turnOff") -- Plante 1
    fibaro:call(593, "turnOff") -- Plante 2
    fibaro:sleep(2*1000);
    fibaro:call(459, "turnOff") -- Spot Hall
    fibaro:debug("Porte fermée Var")
end
elseif enAlerte and heureValable4 then
    if tonumber(fibaro:getValue(459, "value")) > 0 then
        fibaro:debug("lumière déjà allumée")
        fibaro:killScenes(427)
    else
        fibaro:call(light, "setValue", "30"); -- Spots Hall
        fibaro:sleep(15*1000);
        fibaro:call(light, "turnOff") -- Spot Hall
        fibaro:debug("Porte fermée Var4")
    end
    fibaro:debug("Fin de script")
    fibaro:sleep(60*1000);

DEBUG] 20:07:56: 2021-12-11 20:07:56.868878 [ fatal] Unknown exception: /opt/fibaro/scenes/427.lua:34: expected near 'elseif'
 

Encore merci pour ton aide

Partager ce message


Lien à poster
Partager sur d’autres sites

Comme te l'a répété @Barelle ta structure de code n'est pas bonne.

Par exemple, tu ne peux pas avoir un else if après ton end...

if
  blabla
then
  blabla
elseif
  blabla
then
  blabla
end

La structure a de l'importance...

Modifié par Fredmas
  • Like 1

Partager ce message


Lien à poster
Partager sur d’autres sites

De retour après un WE chargé ... j'ai compris vos remarques !!

Ça marche !!

Je peaufine tout ça et vous fait un retour.

Merci

Partager ce message


Lien à poster
Partager sur d’autres sites

 :2:

Modifié par Fredmas
  • Haha 1

Partager ce message


Lien à poster
Partager sur d’autres sites

×