Aller au contenu

Messages recommandés

Posté(e)

Bonjour à  tous,

 

Je m'essaye au script Lua, je tente d'améliorer mes scènes qui tourne déjà .

 

Mais voilà , je ne comprends pas ce qui cloche (à  part ma tête !!) ....??

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

local sourceTrigger = fibaro:getSourceTrigger();
local currentDate = os.date("*t");
local startSource = fibaro:getSourceTrigger();
if (sourceTrigger["type"] == "autostart") then
while true do
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) == "12:00") )
and ( fibaro:getGlobalValue("TV") == "Off" ))
then
    fibaro:call(56, "pressButton", "1") -- Telco Freebox
     fibaro:sleep(10*1000);
    fibaro:call(105, "pressButton", "2") -- Zapping + petula
     fibaro:debug("TLMVP avec allumage")
      else
	fibaro:call(105, "pressButton", "2")
     fibaro:debug("TLMVP, zapping chaine")
end
    
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) == "12:47") )
)
then
    fibaro:call(101, "pressButton", "22")
     fibaro:sleep(6*1000);
	fibaro:call(105, "pressButton", "4")
     fibaro:debug("12/45 M6")
end
    
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) == "12:58") )
)
then
    fibaro:call(101, "pressButton", "5")
     fibaro:sleep(6*1000);
	fibaro:call(105, "pressButton", "1")
     fibaro:debug("Journal du 13H")
end
    
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) == "19:57") )
and ( fibaro:getGlobalValue("TV") == "Off" ))
then
    fibaro:call(56, "pressButton", "1") -- Telco Freebox
     fibaro:sleep(10*1000);
    fibaro:call(101, "pressButton", "6") -- Sample Pétula
     fibaro:sleep(6*1000);
	fibaro:call(105, "pressButton", "1") -- Zapping
      else
    fibaro:call(101, "pressButton", "6")
     fibaro:sleep(6*1000);
	fibaro:call(105, "pressButton", "1")
     fibaro:debug("Journal du 20H")
end

local startSource = fibaro:getSourceTrigger();  
if (
 ( ((currentDate.wday == 2 or currentDate.wday == 3 or currentDate.wday == 4 or currentDate.wday == 5 or currentDate.wday == 6) and string.format("%02d", currentDate.hour) .. ":" .. string.format("%02d", currentDate.min) == "20:34") )
)
then
    fibaro:call(105, "pressButton", "8")
     fibaro:debug("Le petit journal")
end
fibaro:sleep(60*1000);
  end
  else

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) == "12:00") )
and ( fibaro:getGlobalValue("TV") == "Off" ))
then
    fibaro:call(56, "pressButton", "1") -- Telco Freebox
     fibaro:sleep(10*1000);
    fibaro:call(105, "pressButton", "2") -- Zapping + petula
     fibaro:debug("TLMVP avec allumage")
      else
	fibaro:call(105, "pressButton", "2")
     fibaro:debug("TLMVP, zapping chaine")
end
    
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) == "12:47") )
)
then
    fibaro:call(101, "pressButton", "22")
     fibaro:sleep(6*1000);
	fibaro:call(105, "pressButton", "4")
     fibaro:debug("12/45 M6")
end
    
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) == "12:58") )
)
then
    fibaro:call(101, "pressButton", "5")
     fibaro:sleep(6*1000);
	fibaro:call(105, "pressButton", "1")
     fibaro:debug("Journal du 13H")
end
    
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) == "19:57") )
and ( fibaro:getGlobalValue("TV") == "Off" ))
then
    fibaro:call(56, "pressButton", "1") -- Telco Freebox
     fibaro:sleep(10*1000);
    fibaro:call(101, "pressButton", "6") -- Sample Pétula
     fibaro:sleep(6*1000);
	fibaro:call(105, "pressButton", "1") -- Zapping
      else
    fibaro:call(101, "pressButton", "6")
     fibaro:sleep(6*1000);
	fibaro:call(105, "pressButton", "1")
     fibaro:debug("Journal du 20H")
end

local startSource = fibaro:getSourceTrigger();  
if (
 ( ((currentDate.wday == 2 or currentDate.wday == 3 or currentDate.wday == 4 or currentDate.wday == 5 or currentDate.wday == 6) and string.format("%02d", currentDate.hour) .. ":" .. string.format("%02d", currentDate.min) == "20:34") )
)
then
    fibaro:call(105, "pressButton", "8")
     fibaro:debug("Le petit journal")
end
fibaro:sleep(60*1000);
  end

Si un professeur de Lua passait par la, et pouvait me filer un coup de main .......

d'avance merci pour votre aide.

Posté(e)

J'ai l'impression que tu as fais des copier/coller d'un tas de trucs.

 

Commence par faire le ménage dans choses inutiles.

Les "local startSource" et "currentDate", une fois au début de la scène c'est suffisant.

 

Les tests de "currentDate" de 1 à  7 sont inutiles.

Revois aussi un peu l'indentation pour rendre ton code plus lisible.

J'ai commencé et je tombe sur un truc qui ne va pas.

Tu commence un "while true do" en 12 qui se termine en 59. Le reste du code est donc inaccessible.

 

A toi de jouer, car je ne sais pas qu'elle était ton idée.

--[[
%% autostart
%% properties
%% globals
--]]
 
local sourceTrigger = fibaro:getSourceTrigger();
local currentDate = os.date("*t");
local startSource = fibaro:getSourceTrigger();
if (sourceTrigger["type"] == "autostart") then
while true do
  if ((string.format("%02d", currentDate.hour) .. ":" .. string.format("%02d", currentDate.min))     == "12:00") and ( fibaro:getGlobalValue("TV") == "Off" )) then
     fibaro:call(56, "pressButton", "1") -- Telco Freebox
     fibaro:sleep(10*1000);
     fibaro:call(105, "pressButton", "2") -- Zapping + petula
     fibaro:debug("TLMVP avec allumage")
    else
	   fibaro:call(105, "pressButton", "2")
     fibaro:debug("TLMVP, zapping chaine")
   end
 

  if (string.format("%02d", currentDate.hour) .. ":" .. string.format("%02d", currentDate.min) == "12:47")then
     fibaro:call(101, "pressButton", "22")
     fibaro:sleep(6*1000);
	   fibaro:call(105, "pressButton", "4")
     fibaro:debug("12/45 M6")
   end
 

  if (string.format("%02d", currentDate.hour) .. ":" .. string.format("%02d", currentDate.min) == "12:58")then
     fibaro:call(101, "pressButton", "5")
     fibaro:sleep(6*1000);
	   fibaro:call(105, "pressButton", "1")
     fibaro:debug("Journal du 13H")
  end
 

  if ((string.format("%02d", currentDate.hour) .. ":" .. string.format("%02d", currentDate.min) == "19:57") and ( fibaro:getGlobalValue("TV") == "Off" ))then
     fibaro:call(56, "pressButton", "1") -- Telco Freebox
     fibaro:sleep(10*1000);
     fibaro:call(101, "pressButton", "6") -- Sample Pétula
     fibaro:sleep(6*1000);
	   fibaro:call(105, "pressButton", "1") -- Zapping
   else
     fibaro:call(101, "pressButton", "6")
     fibaro:sleep(6*1000);
	   fibaro:call(105, "pressButton", "1")
     fibaro:debug("Journal du 20H")
   end
 

  if ((currentDate.wday == 2 or currentDate.wday == 3 or currentDate.wday == 4 or currentDate.wday == 5 or currentDate.wday == 6) and (string.format("%02d", currentDate.hour) .. ":" .. string.format("%02d", currentDate.min) == "20:34") ) then
     fibaro:call(105, "pressButton", "8")
     fibaro:debug("Le petit journal")
  end
fibaro:sleep(60*1000);
end

  else
 
if ( (string.format("%02d", currentDate.hour) .. ":" .. string.format("%02d", currentDate.min) == "12:00") and ( fibaro:getGlobalValue("TV") == "Off" )) then
    fibaro:call(56, "pressButton", "1") -- Telco Freebox
     fibaro:sleep(10*1000);
    fibaro:call(105, "pressButton", "2") -- Zapping + petula
     fibaro:debug("TLMVP avec allumage")
      else
	fibaro:call(105, "pressButton", "2")
     fibaro:debug("TLMVP, zapping chaine")
end
 
if (string.format("%02d", currentDate.hour) .. ":" .. string.format("%02d", currentDate.min) == "12:47")then
    fibaro:call(101, "pressButton", "22")
     fibaro:sleep(6*1000);
	fibaro:call(105, "pressButton", "4")
     fibaro:debug("12/45 M6")
end
 

if (string.format("%02d", currentDate.hour) .. ":" .. string.format("%02d", currentDate.min) == "12:58")then
    fibaro:call(101, "pressButton", "5")
     fibaro:sleep(6*1000);
	fibaro:call(105, "pressButton", "1")
     fibaro:debug("Journal du 13H")
end
  
if ((string.format("%02d", currentDate.hour) .. ":" .. string.format("%02d", currentDate.min) == "19:57") and ( fibaro:getGlobalValue("TV") == "Off" )) then
    fibaro:call(56, "pressButton", "1") -- Telco Freebox
     fibaro:sleep(10*1000);
    fibaro:call(101, "pressButton", "6") -- Sample Pétula
     fibaro:sleep(6*1000);
	fibaro:call(105, "pressButton", "1") -- Zapping
      else
    fibaro:call(101, "pressButton", "6")
     fibaro:sleep(6*1000);
	fibaro:call(105, "pressButton", "1")
     fibaro:debug("Journal du 20H")
end
 
if ((currentDate.wday == 2 or currentDate.wday == 3 or currentDate.wday == 4 or currentDate.wday == 5 or currentDate.wday == 6) and (string.format("%02d", currentDate.hour) .. ":" .. string.format("%02d", currentDate.min) == "20:34") )then
    fibaro:call(105, "pressButton", "8")
     fibaro:debug("Le petit journal")
end
fibaro:sleep(60*1000);
  end
Posté(e)

Merci beaucoup Bereale pour ce script. Je m'y essaye depuis un petit moment ….

Cette scène me sert à  zapper la TV en fonction de l'heure du programme.

Je fais des appuis sur la Telco freebox via le VD 105 et une banque de sample de TTS en VD 101.

 

J'étais parti d'une scène block convertie, d'ou les doublons car je ne savais pas les supprimer (sans mettre le script en erreur)

 

Sut ton script, voila le début que j'ai

 

J'ai fait le ménage sur le mien, cela m'apprends et le tien me permet égalent de découvrir de nouveau truc.

 

Je poursuis mes tentatives, si tu as une idée …!! 

×
×
  • Créer...