Aller au contenu

Passage Bloc En Lua


Fredric

Messages recommandés

Pourquoi àla conversion bloc vers LUA, il y a doublement des instructions ?

--[[
%% autostart
%% properties
%% globals
--]]

local sourceTrigger = fibaro:getSourceTrigger();
if (sourceTrigger["type"] == "autostart") then
while true do

local currentDate = os.date("*t");
local startSource = fibaro:getSourceTrigger();
if (
 ( ((currentDate.wday == 1 or currentDate.wday == 2 or currentDate.wday == 3 or currentDate.wday == 4 or currentDate.wday == 5 or currentDate.wday == 6 or currentDate.wday == 7) and string.format("%02d", currentDate.hour) .. ":" .. string.format("%02d", currentDate.min) == "22:00") )
)
then
	fibaro:call(50, "pressButton", "1");
	fibaro:call(53, "sendDefinedPushNotification", "11");
	fibaro:call(58, "sendDefinedPushNotification", "11");
	fibaro:call(62, "sendDefinedPushNotification", "11");
	fibaro:call(127, "pressButton", "1");
end

fibaro:sleep(60*1000);
end
else

---je ne comprends pas pourquoi il rénette cette partie

local currentDate = os.date("*t");
local startSource = fibaro:getSourceTrigger();
if (
startSource["type"] == "other"
)
then
	fibaro:call(50, "pressButton", "1");
	fibaro:call(53, "sendDefinedPushNotification", "11");
	fibaro:call(58, "sendDefinedPushNotification", "11");
	fibaro:call(62, "sendDefinedPushNotification", "11");
	fibaro:call(127, "pressButton", "1");
end

end

Lien vers le commentaire
Partager sur d’autres sites

C'est normal.

 

En autostart, cela exécute ton code tout les jours à  22:00 sinon, sur appel*, tu l’exécutes une seul fois. Ce code a du sens.

 

* Par exemple, si toi tu lance le scénario manuellement.

  • Upvote 1
Lien vers le commentaire
Partager sur d’autres sites

Oui ça a du sens mais enfin c'est vraiment pas propre ni optimisé tout cela !

 

Pourquoi n'ont ils pas fait tout simplement:

function codeXYZ()
  fibaro:call(50, "pressButton", "1");
  fibaro:call(53, "sendDefinedPushNotification", "11");
  fibaro:call(58, "sendDefinedPushNotification", "11");
  fibaro:call(62, "sendDefinedPushNotification", "11");
  fibaro:call(127, "pressButton", "1");
end

et appeler la fonction dans les conditions histoire d'être plus lisible :rolleyes:

 

:98:

Lien vers le commentaire
Partager sur d’autres sites

Voila ce que j'en ai fait:

 

comme il y a une recrudescence de home jacking, j'active mes capteurs de fenêtres et portes d'entré à  une heure précise le soir, pour exemple, j'ai mis 22h.

j'ai intégré le code que super Shad  ;) (que je remercie encore) m'a fait pour activer mon alarme avec ma télécommande.

donc, l'idée, c'est de vérifier toute les ouvertures avant mises sous alarme et de renvoyer un message qui nome l'ouverture qui est resté ouverte, si c'est le cas  ;)

--[[
%% autostart
%% properties
%% globals
--]]

local sourceTrigger = fibaro:getSourceTrigger();
local windowSensor = {47, 32, 124, 97, 111, 114, 115, 116, 157}; --ID des capteur
--messages associer au ID
local placeSensor = {"La fenêtre le la chambre bleu est ouverte","La porte d entrée est ouverte","La fenêtre le la chambre de xxxx est ouverte","La fenêtre le la chambre des parents est ouverte","La fenêtre du bureau est ouverte","La fenêtre du salon est ouverte","La porte","La porte du garage est ouverte","La fenêtre de la cuisine est ouverte"};
local startSource = fibaro:getSourceTrigger();
 
function statutWindows ()
  local statut = "close";
    for i=1, #windowSensor do
      if (tonumber(fibaro:getValue(windowSensor[i], "value")) > 0) then
        statut = "open";
      end
    end
  return statut;
end
     
function alertWindows ()
  local place = nil;
  for i=1, #windowSensor do
    if (tonumber(fibaro:getValue(windowSensor[i], "value")) > 0) then
      if (place == nil) then
        place = placeSensor[i];
      elseif (place ~= nil) then
        place = place .. ", " .. placeSensor[i];
      end
    end
  end
  fibaro:debug("élément ouvert ou en alerte: " .. place);
  fibaro:call(53, "sendPush", "Attention: " .. place);
  fibaro:call(58, "sendPush", "Attention: " .. place);
end
     
function armedSensor (value)
  for i=1, #windowSensor do
    fibaro:call(windowSensor[i], "setArmed", value);
  end
end  
 
if (sourceTrigger["type"] == "autostart") then
while true do
local currentDate = os.date("*t");
local startSource = fibaro:getSourceTrigger();
if (
 ( ((currentDate.wday == 1 or currentDate.wday == 2 or currentDate.wday == 3 or currentDate.wday == 4 or currentDate.wday == 5 or currentDate.wday == 6 or currentDate.wday == 7) and string.format("%02d", currentDate.hour) .. ":" .. string.format("%02d", currentDate.min) == "22:00") )-- heure d'activation
)
then 
 statut = statutWindows();
  if (statut == "close") then
    armedSensor(1);
    fibaro:call(53, "sendDefinedPushNotification", "11");
	fibaro:call(58, "sendDefinedPushNotification", "11");
	fibaro:call(62, "sendDefinedPushNotification", "11");
	fibaro:call(127, "pressButton", "1");
        fibaro:debug("Alarme Nuit Activée");
  elseif (statut == "open") then
    alertWindows();
  end
 end
  fibaro:sleep(60*1000);
  end 
    end
Lien vers le commentaire
Partager sur d’autres sites

Oh, j'ai l'impression d'être au travail.

"On peut faire mieux mais on va pas le faire car ce qu'on a fonctionne déjà".

Résultat un code vieux, incompréhensible et non optimiser.

Shad... Tu n'es pas comme cela

Lien vers le commentaire
Partager sur d’autres sites

oui, mais vu qu'il y a plusieurs capteurs dans la même pièce, cela aurai peut être posé problème et tu as raison, il marche tés bien, exactement ce que je souhaiter alors pourquoi changer...

En plus, je peux personnaliser le message des capteurs.  :60:

Lien vers le commentaire
Partager sur d’autres sites

×
×
  • Créer...