Aller au contenu

Syncro Rgbw Avec Différentes Actions


d@m!Ch94

Recommended Posts

Bonjour à  tous,

 

Pour faire suite aux sujet sur les associations de modules RGBW je but sur un script me permettant de changer la couleur d'un ruban LED branché sur un module RGBW suivant différente action (ouverture de porte, détection présence, etc..) ET qui puisse revenir à  sa couleur avant action quelle qu'elle soit.

J'avais abandoné!

Alors ne rier pas mais à  force de retouche il s'est chargé en ligne de code et est devenu un gros bordel mais voici le script:

--[[ 
%% autostart
%% properties 
33 value
5 value
5 color
%% globals 
--]] 

fibaro:debug('______start_____') 

local colorSetA = fibaro:getValue(5, "lastColorSet");
fibaro:debug('Set en début programme :'..colorSetA);

if ( tonumber(fibaro:getValue(33, "value")) == 0 )
 then fibaro:debug('Porte fermé');
if ( tonumber(fibaro:getValue(33, "value")) == 1 )
 then fibaro:debug('Porte ouverte');
 end
end


if ( tonumber(fibaro:getValue(5, "value")) == 220 )
 then fibaro:debug('LED Vert');
      goto A
end


if ( tonumber(fibaro:getValue(5, "value")) > 0 )
 then fibaro:debug('LED On');
  
 local colorSet = fibaro:getValue(5, "lastColorSet");        
 fibaro:debug('Set en ON :'..colorSet);
 goto B
  
end


if ( tonumber(fibaro:getValue(5, "value")) == 0 )
 then fibaro:debug('LED eteintes');       
end

::A::

  fibaro:debug('A');

  
 if (tonumber(fibaro:getValue(33, "value")) == 1 )
  then fibaro:debug('Porte ouverte en OFF ou vert');
  -- lance le vert
  fibaro:call(5, "setColor","0","220","0","0");
  fibaro:debug('lance le vert');
  fibaro:sleep(3000)
  -- apres 3 secondes, relance la couleur fixe
  fibaro:call(5, "turnOff")
  fibaro:debug('Estinction led');
  fibaro:sleep(2500)

 end  
   



::B::
 
 fibaro:debug('B');

 if (tonumber(fibaro:getValue(33, "value")) == 1 )
  then fibaro:debug('Porte ouverte en ON');
  -- lance le vert
  fibaro:call(5, "setColor","0","220","0","0");
  fibaro:debug('lance le vert');
  fibaro:sleep(3000)
  -- apres 3 secondes, relance la couleur fixe
  fibaro:call(5, "setColor", colorSet);
  fibaro:debug('reprise couleur led');
  fibaro:sleep(2500)
 end
    
 fibaro:debug('______end_____')                
 

Un extrait du débug parle de lui même:

 

 
[DEBUG] 12:18:30: ______start_____
[DEBUG] 12:18:30: Set en début programme :120,18,0,0
[DEBUG] 12:18:30: LED On
[DEBUG] 12:18:30: Set en ON :120,18,0,0
[DEBUG] 12:18:30: B
[DEBUG] 12:18:30: Porte ouverte en ON
[DEBUG] 12:18:30: lance le vert
[DEBUG] 12:18:30: ______start_____
[DEBUG] 12:18:30: Set en début programme :0,220,0,0
[DEBUG] 12:18:30: LED Vert
[DEBUG] 12:18:30: A
[DEBUG] 12:18:30: Porte ouverte en OFF ou vert
 
en gros il veut pas revenir à  la couleur iniciale, il recommance trop vite et prend en compte la couleur verte à  la place!
Lien vers le commentaire
Partager sur d’autres sites

mdrrr.

 

Attend, regard, ça c'est celui qui m'avais servi de base:

---[[ 
%% autostart
%% properties 
33 value
5 value
5 color
%% globals 
--]] 



local ETATporte = tonumber(fibaro:getValue(33, "value"))
--get last color
  local colorSet = fibaro:getValue(5, "lastColorSet");        
  --set old color
  local RGBWTable= {};
  local i = 1;
   
  for value in string.gmatch(colorSet,"(%d+)") do
  RGBWTable[i] = value;
  i = i + 1;
  end

if ( tonumber(fibaro:getValue(33, "value")) == 0 )
 then fibaro:debug('Porte fermé');
if ( tonumber(fibaro:getValue(33, "value")) > 0 )
 then fibaro:debug('Porte ouverte');
 end
end

fibaro:debug('R:'..RGBWTable[1]);
fibaro:debug('G:'..RGBWTable[2]);
fibaro:debug('B:'..RGBWTable[3]);
fibaro:debug('W:'..RGBWTable[4]);


if (tonumber(fibaro:getValue(33, "value")) > 0)
 then -- lance le vert
  fibaro:call(5, "setColor","0","220","0","0");
  fibaro:debug('lance le vert');
  fibaro:sleep(3000)
  fibaro:debug('Porte:'..ETATporte)
  -- apres 3 secondes, relance la couleur fixe
  fibaro:call(5, "setColor", RGBWTable[1], RGBWTable[2], RGBWTable[3], RGBWTable[4]);
  fibaro:debug('reprise couleur led');
  
end

Donc en reprenant ma situation, ce que je voudrais c'est que mon module RGBW id5, se mette en vert pendant 3 sec quant la porte id33 s'ouvre et se reteigne s'il etait éteint (ca je sais faire simplement) mais aussi que s'il est dans une couleur X ou Y choisie avant l'ouverture de la porte, il revienne à  cette couleur et là  je bug!!!

Lien vers le commentaire
Partager sur d’autres sites

essaye sa

--[[
%% properties
33 value
%% globals
--]]
local startSource = fibaro:getSourceTrigger();   
local porte = 33;
local RGBW = 5;
     
function split(s, pattern, maxsplit)
  local pattern = pattern or ' '
  local maxsplit = maxsplit or -1
  local s = s
  local t = {}
  local patsz = #pattern
  while maxsplit ~= 0 do
    local curpos = 1
    local found = string.find(s, pattern)
    if found ~= nil then
      table.insert(t, string.sub(s, curpos, found - 1))
      curpos = found + patsz
      s = string.sub(s, curpos)
    else
      table.insert(t, string.sub(s, curpos))
      break
    end
    maxsplit = maxsplit - 1
    if maxsplit == 0 then
      table.insert(t, string.sub(s, curpos - patsz - 1))
    end
  end
  return t
end
 
     
local result = split(fibaro:getValue(RGBW, "color"), ',')
local ProgramID = fibaro:getValue(RGBW, "currentProgramID")

function callLastState ()
  if (result[1] == "0" and result[2] == "0" and result[3] == "0" and result[4] == "0" and (ProgramID > "0")) then
    fibaro:call(RGBW, "startProgram", ProgramID);
  else
    fibaro:call(RGBW, "setColor", result[1], result[2], result[3], result[4]);
  end
end

if (startSource['type']=='property') then
  -- door trigger
  if (startSource['deviceID']==tostring(porte)) then
    if (tonumber(fibaro:getValue(porte, "value")) > 0) then
      fibaro:debug('Porte ouverte');
      fibaro:call(5, "setColor","0","220","0","0");
      fibaro:sleep(3000);
      callLastState();
    end
  end
end
Lien vers le commentaire
Partager sur d’autres sites

Yessss, merci de te pencher sur ce script Shad!

 

Je viens de rentrer, je vais test... faut que je refasse le paramètre d'association du module avant (sans HC2 coché je vais vers un résultat faussé comme sur la box de ce matin!).

Lien vers le commentaire
Partager sur d’autres sites

Pas de soucis, j'ai déjàchanger tes id, perso pour moi sa marche.

Mais je te conseille tous de même de faire une scène globale d'association pour au moins tous des modules RGB.

Sa évitera d'avoir plusieurs fois le même script.

Lien vers le commentaire
Partager sur d’autres sites

Ouai j'ai vu les id...c'est cool...Thank's!

Bon, j'ai remis la HC2 sur le paramétre d'association du module...

+ petit redémarage pour la forme.

Làle module ne réagis pas àl'ouverture

Lien vers le commentaire
Partager sur d’autres sites

--[[
%% properties
33 value
%% globals
--]]

fibaro:debug("________start________");

local startSource = fibaro:getSourceTrigger();   
local porte = 33;
local RGBW = 5;

fibaro:debug("étape 1");
     
function split(s, pattern, maxsplit)
  local pattern = pattern or ' '
  local maxsplit = maxsplit or -1
  local s = s
  local t = {}
  local patsz = #pattern
  
  while maxsplit ~= 0 do
    local curpos = 1
    local found = string.find(s, pattern)
    if found ~= nil then
fibaro:debug("étape 1.1");
      table.insert(t, string.sub(s, curpos, found - 1))
      curpos = found + patsz
      s = string.sub(s, curpos)
    else
fibaro:debug("étape 1.2");
      table.insert(t, string.sub(s, curpos))
      break
    end
    
fibaro:debug("étape 2");
   
    maxsplit = maxsplit - 1
    if maxsplit == 0 then
fibaro:debug("étape 2.1");
      table.insert(t, string.sub(s, curpos - patsz - 1))
    end
  end
  return t
end

fibaro:debug("étape 3"); 
     
local result = split(fibaro:getValue(RGBW, "color"), ',')
local ProgramID = fibaro:getValue(RGBW, "currentProgramID")
 
function callLastState ()
  if (result[1] == "0" and result[2] == "0" and result[3] == "0" and result[4] == "0" and (ProgramID > "0")) 
    then
    fibaro:call(RGBW, "startProgram", ProgramID);
fibaro:debug("étape 3.1");
  else
    fibaro:call(RGBW, "setColor", result[1], result[2], result[3], result[4]);
fibaro:debug("étape 3.2");
  end
end

fibaro:debug("étape 4");
 
if (startSource['type']=='property') then
  -- door trigger
fibaro:debug("étape 4.1");
  if (startSource['deviceID']==tostring(porte)) then
fibaro:debug("étape 4.2");
    if (tonumber(fibaro:getValue(porte, "value")) > 0) then
fibaro:debug("étape 4.3");
      fibaro:debug('Porte ouverte');
      fibaro:call(5, "setColor","0","220","0","0");
      fibaro:sleep(3000);
      callLastState();
    end
  end
fibaro:debug("________END________");

end

[DEBUG] 21:14:08: ________start________

[DEBUG] 21:14:08: étape 1

[DEBUG] 21:14:08: étape 3

[DEBUG] 21:14:08: étape 1.1

[DEBUG] 21:14:08: étape 2

[DEBUG] 21:14:08: étape 1.1

[DEBUG] 21:14:08: étape 2

[DEBUG] 21:14:08: étape 1.1

[DEBUG] 21:14:08: étape 2

[DEBUG] 21:14:08: étape 1.2

[DEBUG] 21:14:08: étape 4

[DEBUG] 21:14:08: étape 4.1

[DEBUG] 21:14:08: ________END________

[DEBUG] 21:14:13: ________start________

[DEBUG] 21:14:13: étape 1

[DEBUG] 21:14:13: étape 3

[DEBUG] 21:14:13: étape 1.1

[DEBUG] 21:14:13: étape 2

[DEBUG] 21:14:13: étape 1.1

[DEBUG] 21:14:13: étape 2

[DEBUG] 21:14:13: étape 1.1

[DEBUG] 21:14:13: étape 2

[DEBUG] 21:14:13: étape 1.2

[DEBUG] 21:14:13: étape 4

[DEBUG] 21:14:13: étape 4.1

[DEBUG] 21:14:13: ________END________

Lien vers le commentaire
Partager sur d’autres sites

Flute à  bec!

 

J'avais de sérieux doute sur le module du fait de mon traffic ds ses paramètre d'association, et je viens de teste avec un autre... même résultat :(

Lien vers le commentaire
Partager sur d’autres sites

Dans le script par endroit au lieu de remettre l id j ai utiliser une local porte. Peut être qu avec ta version il aime pas. Remplace donc les portes par l id de ton module

Lien vers le commentaire
Partager sur d’autres sites

harg!

 

J'ai envie de revenir en 3.xx rien que pour ça! le remplace de la local ne change rien, surtout que la box les prend bien en compte pour le jumelage RGBW vu ensemble ce matin

Lien vers le commentaire
Partager sur d’autres sites

×
×
  • Créer...