Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


  • 0

Scena światło - właczenie i wyłączenie po 60s


zibko1

Question

Witam wszystkich adaptowałem z forum poniższą scenę działa dobrze jednak chciałbym jak włączę światło wyłącznikiem to mi nie zgaśnie po 60s

--[[
%% properties 
 
423 value
19 value
 
%% globals 
 
--]] 
-----------------------------------------------------------------------------
fibaro:debug("SCENE START --------------------------")
fibaro:debug("sceneInstance: "..fibaro:countScenes())
if fibaro:countScenes() > 1 
 then 
 fibaro:debug("SCENE ABORT --------------------------") 
 fibaro:abort() 
 end
-----------------------------------------------------------------------------
 
-- sensor ruchu
local sensorID = 19
 
-- światło sufit
local lightID =  423
 
local delay =  60
local lumen =  200
local timeStart = '19:59'  
local timeStop = '06:00'  
 
 
--  Functions  ---------------------------------------------------------------
 
-- funkcja zamienia czas w formacie tekstowym "HH:MM" lub os.date("*t") na liczbę minut od północy 
 
function toMinutes(czasHHMM) 
  local a 
  if type(czasHHMM) == "string" 
    then 
    a = tonumber(string.sub(czasHHMM, 1, 2)) * 60 + tonumber(string.sub(czasHHMM, 4, 5)) 
    else    
    a = tonumber(czasHHMM.hour) * 60 + tonumber(czasHHMM.min) 
    end 
  return a 
end
 
 
------------------------------------------------------------------------------
 
local minStart = toMinutes(timeStart)
local minStop = toMinutes(timeStop)
local minNow = toMinutes(os.date("*t"))
 
local sensorMoved = (tonumber(fibaro:getValue(sensorID, "value")) > 0)
local isLightOn = (tonumber(fibaro:getValue(lightID, "value")) > 0)
 
fibaro:debug("isLightOn: "..tostring(isLightOn))
fibaro:debug("sensorMoved: "..tostring(sensorMoved))
 
------------------------------------------------------------------------------
 
local isTime
 
if (minStop >= minStart) 
  then 
  if (minNow >= minStart) and (minNow <= minStop)
     then 
     isTime = true 
     else 
     isTime = false
     end
  elseif (minStop <= minStart)
     then 
     if (minNow <= minStart) and (minNow >= minStop)
       then 
       isTime = false 
       else 
       isTime = true
       end
  end
fibaro:debug("isTime: "..tostring(isTime))
 
 
-- zapalanie światła --------------------------------------------------------
 
if sensorMoved  and isTime
  then 
  fibaro:call(lightID, "turnOn")
  fibaro:debug("Action: turnOn")  
  end
 
if sensorMoved  and (not isTime)
  then 
  fibaro:call(lightID, "turnOn")
  fibaro:debug("Action: turnOn")  
  end
 
 
-- gaszenie światła ---------------------------------------------------------
 
if isLightOn 
  then
 
  local turnOffTime = os.time() + delay
 
  while turnOffTime > os.time() 
    do 
    if tonumber(fibaro:getValue(sensorID, "value")) > 0
      then 
      turnOffTime = os.time() + delay
      end  
    fibaro:debug("DELAY: "..tostring(turnOffTime - os.time()))
    fibaro:sleep(1000)
    
 -- sprawdzenie czy światło wyłączone ręcznie podczas trwania zwłoki   
    local isLightOnInLoop = (tonumber(fibaro:getValue(lightID, "value")) + tonumber(fibaro:getValue(lightID, "value")) > 0)
    if not isLightOnInLoop 
      then
      fibaro:debug("SCENE ABORT --------- LIGHT TURNED OFF MANUALLY ---------") 
      fibaro:abort() 
      end
    
  end       
fibaro:call(lightID, "turnOff") 
fibaro:debug("Action: turnOff")   
  
end

Link to comment
Share on other sites

Recommended Posts

  • 0

niestety nie działa.

 

scena miała na ruch włączać dwa dimmey, gdzie podajemy drugiego dimmera?

Link to comment
Share on other sites

  • 0
2 hours ago, Thomson said:

scena miała na ruch włączać dwa dimmey, gdzie podajemy drugiego dimmera?

 

 

Please login or register to see this code.

 

local powers =  { 547, 571 },

...

 

setPowerState(powers, 40) lub

setPowerState(powers, 0) -- wyłaczyc

 

 

Link to comment
Share on other sites

  • 0

inny przykład

 

Please login or register to see this code.

setPowerState(dev, 1)
 
setPowerState(dev, 0)

w zaleznosci od czasu.

dimmer / rgb / lamp

Edited by 10der
Link to comment
Share on other sites

  • 0

nie za bardzo rozumiem, coś nie działa, możesz zerknąć

Please login or register to see this code.

 

Link to comment
Share on other sites

  • 0

tak

3 hours ago, Thomson said:

nie za bardzo rozumiem, coś nie działa, możesz zerknąć

 

haha, funkcję deklarujesz

i kto zadzwoni funkcję ? 

:)

 

zmiany:

Please login or register to see this code.

dodaj ponizej

Please login or register to see this code.

-- gaszenie światła ---------------------------------------------------------

 

Edited by 10der
Link to comment
Share on other sites

  • 0

cały czas działa mi tylko jedno światło ://

 

chyba będę Cię prosił o pisanie prostszym językiem, bardziej zrozumiałem dla mnie

mój kod wygląda teraz tak

Please login or register to see this code.

 

Link to comment
Share on other sites

  • 0

Please login or register to see this code.

 

>>chyba będę Cię prosił o pisanie prostszym językiem, bardziej zrozumiałem dla mnie

:(

 

 

Link to comment
Share on other sites

  • 0
27 minutes ago, Thomson said:

wciąż się wyłącza tylko jedno światło...

ale czego chcesz ?!

 

Please login or register to see this code.

 

Edited by 10der
Link to comment
Share on other sites

  • 0

@hoomee

Bardzo proszę Ciebie lub kogoś kto jest w stanie mi pomóc. Na bazie Twojej sceny z pierwszej strony stworzyłem własną. Stworzyłem zmienną globalną manualOn z dwoma wartościami "true" i false" i nie działa mi przełączanie zmiennej. Scena została napisana na czujkę ruchu,  ja używam czujki drzwi/okien ale to chyba nie ma znaczenia. Jak przełączę zmienną ręcznie z "false" na "true" działa poprawnie część sceny po włączeniu światła ręcznie, po powrocie do "false" -część inicjowana otwarciem drzwi, ale zmienna nie działa automatycznie. Jestem zielony i już naprawdę nie wiem co robię źle. Usuwałem już zmienną z restartem jak zalecałeś komuś wcześniej. Nie pomogło :(

--[[
%% properties 
924 value
750 value
%% events
%% globals
manualOn 
--]] 

local sensorID = 924     -- sensor drzwiowy
local lightID  = 750     -- światło sufit
local delay    =  30     -- opóźnienie gaszenia w sekundach 

---- nie edytuj poniżej tej linii -------------------------------------------
local startSource = fibaro:getSourceTrigger()
-----------------------------------------------------------------------------
-- reakcja na ruch
-- czy nie za dużo instancji
if ( (startSource.deviceID == sensorID) and (fibaro:countScenes() > 1) )
  then
    fibaro:debug("--------- debugging ----------") 
    fibaro:debug("za dużo scen: "..fibaro:countScenes())
    fibaro:debug("źródło: "..startSource.deviceID)
    fibaro:debug(fibaro:getGlobal("manualOn"))
    fibaro:debug("scena numer: "..fibaro:countScenes())
    fibaro:debug("--------- aborting ----------") 
    fibaro:abort() 
-- czy globalna zmienna mówi, że światło włączone ręcznie 
elseif ( (startSource.deviceID == sensorID) and (tostring(fibaro:getGlobal("manualOn")) == "true") )
  then
    fibaro:debug("--------- debugging ----------") 
    fibaro:debug("światło było zapalone ręcznie")
    fibaro:debug("źródło: "..startSource.deviceID)
    fibaro:debug(fibaro:getGlobal("manualOn"))
    fibaro:debug("scena numer: "..fibaro:countScenes())
    fibaro:debug("--------- aborting ----------") 
    fibaro:abort() 
elseif( (startSource.deviceID == sensorID) and (tostring(fibaro:getGlobal("manualOn")) == "false") )
  then
  local sensorMoved = (tonumber(fibaro:getValue(sensorID, "value")) > 0)
  local isLightOn = (tonumber(fibaro:getValue(lightID, "value")) > 0)
  fibaro:debug("isLightOn: "..tostring(isLightOn))
  fibaro:debug("sensorMoved: "..tostring(sensorMoved))
-- zapalanie światła
  if sensorMoved 
    then 
      fibaro:call(lightID, "turnOn")
      fibaro:debug("Action: turnOn")
      fibaro:sleep(1000)
  end
-- gaszenie światła 
  if isLightOn 
    then 
      local turnOffTime = os.time() + delay
      while turnOffTime > os.time() 
      do 
        if (tonumber(fibaro:getValue(sensorID, "value")) > 0)
          then 
          turnOffTime = os.time() + delay
        end  
      fibaro:debug("DELAY: "..tostring(turnOffTime - os.time()))
      fibaro:sleep(1000)
      end
-- sprawdzenie czy światło wyłączone ręcznie podczas trwania zwłoki (zmienna globalna) 
    if (tostring(fibaro:getGlobal("manualOn")) == "true")
      then 
      fibaro:debug("SCENE ABORT -----------MANUAL ON ACTIVATED---------------") 
      fibaro:abort() 
    end
    fibaro:call(lightID, "turnOff")
    fibaro:debug("Action: turnOff") 
  end 
elseif ( startSource.deviceID == lightID ) 
  then
  local sensorMoved = (tonumber(fibaro:getValue(sensorID, "value")) > 0)
  if ( (fibaro:countScenes() == 1) or (not sensorMoved) )
    then
    if (tonumber(fibaro:getValue(lightID, "value")) > 0)
      then
      fibaro:debug("--------- debugging ----------") 
      fibaro:debug("zapalenie ręczne")
      fibaro:debug("źródło: "..startSource.deviceID)
      fibaro:debug("scena numer: "..fibaro:countScenes())
      fibaro:setGlobal("manualOn", "true")
      fibaro:abort()
    elseif (tonumber(fibaro:getValue(lightID, "value")) == 0)
    then
      fibaro:debug("--------- debugging ----------") 
      fibaro:debug("zgaszenie")
      fibaro:debug("źródło: "..startSource.deviceID)
      fibaro:debug("scena numer: "..fibaro:countScenes())
      fibaro:setGlobal("manualOn", "false")
      fibaro:abort()
    end
  end
else
    fibaro:debug("--------- debugging ----------") 
    fibaro:debug("źródło: "..startSource.deviceID)
    fibaro:debug("scena numer: "..fibaro:countScenes())
    fibaro:debug("unexpected error! aborting")
    fibaro:debug("--------- aborting ----------")
    fibaro:abort()
end
 

Link to comment
Share on other sites

  • 0

@10der

Cześć, dzięki za odpowiedź, choć jest dla mnie trochę enigmatyczna :)

Napisałeś witam po polsku, ale link jest do postu po angielsku... so... 

 

If I understand correctly, You suggest that the script is ok, but the device does not show true state to fibaro? Maybe, but I also tried script on the Aeotec motion detector and had the same issue :( I'll try on fibaro motion detector, but I have no hope ;) 

Link to comment
Share on other sites

  • 0

witam! 

mam 5 Aeotec + 5 fibaro - dziala! 

ten sam skrypt dziala (!) z "globalnymi".

 

PS:

1) ucze sie polskiego :)

2) jestem Ukraincem.

3) link jest do postu po angielsku, tak, to jest wspolna sekcja/topic

Edited by 10der
Link to comment
Share on other sites

  • 0

Wykazałem brak logiki i chyba byłem na tyle sugestywny, że Ty również tego nie zauważyłeś :) Przecież ta zmienna globalna "manualOn" nie dotyczy czujników, ale włączników :)   Włączniki mam chińskie coolcam. Możliwe, że nie raportują prawidłowo stanu i stąd ten problem :(  Na razie się poddałem :( 

  

Edited by Fro
Link to comment
Share on other sites

  • 0

coolcam? 5  gniazdka elektryczne, 15  przełaczniki elektryczne. dziala bardzo dobrze

¯ \ _ (ツ) _ / ¯

Please login or register to see this image.

jKWShD3Yoy.png

Link to comment
Share on other sites

  • 0

Przełączniki takie jak na Twoim drugim zdjęciu. Ja już nie wiem gdzie jest błąd, brakuje mi niestety wiedzy w programowaniu w lua... pewnie to ja coś źle robię.

 

Link to comment
Share on other sites

  • 0
W dniu 27.01.2017 o 23:39, hoomee napisał:

ok. Nie wiem co się dzieje, ale zróbmy jak w dowcipie - wysiądźmy z tego samochodu i wsiądźmy jeszcze raz ;)

 

W poniższym kodzie dodałem bramkę na zmienną globalną (gdyby nie była jak trzeba). Wklej całość u siebie, zrestartuj HC2, poruszaj się przed sensorem i sprawdź debug. Zobaczymy co z tego wyniknie ;)

 

Please login or register to see this code.

 

Witam serdecznie, również zastosowałem powyższą scene i działa super. Jednak idąc dalej tym tropem, gdybyśmy chcieli, aby scena wywoływana była przez kilka czujek na to samo źródło światła. Mam w domu długi korytarz i chciałbym, aby łapała mnie czujka na początku, na końcu korytarza, oraz jak wychodzę z łazienki, czy też wiatrołapu?

Razem 4 czujki na to samo źródło światła. Obecnie używając dwóch scen na to samo źródło światła obie sceny wariują, gdyż rozpoznają ręczne zapalenie światła i już go nie gaszą. Pomógłby ktoś coś takiego zrobić? Z góry dzięki ;)

Link to comment
Share on other sites

  • 0

Witam 

Jestem początkującym i nie potrafię sobie poradzić z tym błędem 

ID czujki i switcha ustawione prawdiłowo

Ktoś pomoże?

Unknown exception: /opt/fibaro/scenes/5.lua:96: attempt to concatenate field 'deviceID' (a nil value)

Link to comment
Share on other sites

  • 0
18 minutes ago, MarcinL said:

Witam 

Jestem początkującym i nie potrafię sobie poradzić z tym błędem 

ID czujki i switcha ustawione prawdiłowo

Ktoś pomoże?

Unknown exception: /opt/fibaro/scenes/5.lua:96: attempt to concatenate field 'deviceID' (a nil value)

 

nie jestem Baba Wanga. Nie umiem czytac LUA scripts na odległosc :D 

 

Link to comment
Share on other sites

  • 0

Cześć @10der, od około tygodnia przyszedł mi pewien pomysł. Pytanie czy jest to możliwe. Czy jesteś wstanie mi pomóc by światło w week włączało się o innych porach dnia :), wiem to wyższy level :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...