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

Jeśli 423 to jest ID włącznika światła na suficie a nie chcesz, żeby pstryknięcie włącznika uruchamiało scenę, to po prostu usuń 3 linijkę sceny:

 

Please login or register to see this code.

Przy takim rozwiązaniu jednak każda aktywacja czujnika ruchu scenę wywoła, więc światło po 60 sekundach zgaśnie. Jeśli chcesz, żeby światło zapalone ręcznie świeciło zawsze i niezależnie od czujki ruchu, to niestety należałoby użyć zmiennej globalnej.

 

W Twojej scenie jest trochę bałaganu wg mnie, np. nie działa (o ile mnie wzrok nie myli) przedział czasowy między 20:00 a 6:00 i światło zapala się zawsze niezależnie od wartości "lumen".

 

Jeśli chcesz, ręcznie zapalać światło niezależnie od ruchu to dodaj taką scenę:

Please login or register to see this code.

a swoją, którą masz zmień na taką:

Please login or register to see this code.

po czym idź do panelu zmiennych i dodaj zmienną predefiniowaną o nazwie "manualOn" z wartościami "true" i "false".

pstryknij przyciskiem światła, poczekaj parę minut żeby się system przyzwyczaił do nowej zmiennej i sprawdź czy działa jak chcesz.

Edited by hoomee
Link to comment
Share on other sites

  • 0

hoomee

 

Zrobiłem dokładnie jak napisałeś, ale w scenie ręcznie zapalającej światło niezależnie od ruchu mam błąd:

[DEBUG] 22:13:44: line 24: 'then' expected near 'fibaro'

Pomożesz?

 

Link to comment
Share on other sites

  • 0

Rzeczywiście brakuje "then" po "elseif". Błąd się wkradł przy kopiowaniu/adaptowaniu do Twoich warunków, bo u mnie w scenie testowej wszystko ok.

Edytowałem mój post, więc teraz najlepiej skopiuj całą scenę jeszcze raz.

---jeszcze jedna zmiana---

Skopiuj jeszcze raz również drugą scenę z mojego postu, bo dodałem sprawdzanie za pomocą naszej zmiennej globalnej czy światło zostało włączone ręcznie podczas odliczania.

Edited by hoomee
Link to comment
Share on other sites

  • 0

Tym razem nie mam żadnych błędów, jednak światło po wykryciu ruchu nie gaśnie. Wygląda na to, że gdy światło jest włączone (bez różnicy czy manualnie czy po wykryciu ruchu) to zmienna "manualOn" zawsze jest "true". Masz pomysł jak to rozwiązać?

Edited by barto
Link to comment
Share on other sites

  • 0

No tak, racja. Zapalenie światła pod wpływem ruchu wywołuje scenę ustawienia zmiennej globalnej... :oops:  ale warto było spróbować ;)

 

Przepisałem całość od nowa używając tylko Twojego mechanizmu sprawdzania i odliczania i teraz powinno działać. Wracamy do tylko jednej sceny (tę drugą, którą dodałeś, możesz całkowicie wyrzucić, albo wyłączyć):

Please login or register to see this code.

 

teraz powinno działać tak:

1. zapalenie światła ręczne = światło zostaje zapalone dopóki ktoś go nie wyłączy

2. wykrycie ruchu (niezależnie od pory dnia czy nocy) = zapalenie światła

3. jeśli w tym czasie ktoś zgasi i ponownie zapali światło, to pozostanie ono zapalone jak w punkcie 1.

4. ustanie ruchu = odliczanie 60 sekund do zgaszenia światła

5. jeśli w ciągu tych 60 sekund ktoś zgasi i ponownie zapali światło, to pozostanie ono zapalone jak w punkcie 1.

6. zgaszenie światła w dowolnym czasie (podczas ruchu lub podczas odliczania oraz zgaszenie automatyczne po zakończonym odliczaniu) kasuje zmienną globalną, więc światło powinno reagować na ruch.

Edited by hoomee
bugfix - czasem zmienna zostawała ustawiona ON po wykryciu ruchu
  • Like 3
Link to comment
Share on other sites

  • 0

Jesteś genialny! :-D Bardzo bardzo dziękuję za zainteresowanie i dokładną solucję. Potestowałem i wszystko działa jak powinno. 

Może znajdziesz czas i chęci ;-) podpowiedzieć co powinienem zmienić, aby uzależnić tę sceną od czasu np:

wykrycie ruchu w godzinach 23.00-06.00 zapali światło na 40%, w pozostałych godzinach np. na 99%. Ręczne uruchomienie zapali zawsze na 100%

 

Link to comment
Share on other sites

  • 0

Jeśli to jest dimmer to dodaj na początku odpowiednie linie, żeby wyglądało tak (oczywiście możesz edytować początek wg potrzeb):

 

Please login or register to see this code.

a w środku w scenie zamień to (czyli między liniami zapalanie i gaszenie światła):

Please login or register to see this code.

na to:

Please login or register to see this code.

 

Jeśli chodzi o ręczne zapalenie, to nie jest ono wykonywane przez scenę, więc nie da się ustawić mocy światła - będzie zawsze taka jaka była przy ostatnim wyłączaniu.

Ale jeśli zapalasz pstryczkiem w ścianie to wystarczy dwukliknąć, żeby było 100%. Z aplikacji lub strony web można też wywołać dowolną moc.

 

Edited by hoomee
bugfix - czasem zmienna zostawała ustawiona ON po wykryciu ruchu
  • Like 1
Link to comment
Share on other sites

  • 0

Wszystko działa tak jak powinno. Jeszcze raz dziękuję. Bardzo mi pomogłeś. Do tej pory większość scen wykonywałem na bloczkach i zmiennych, ale pora zaprzyjaźnić się z lua. Z Twoją pomocą jestem krok do przodu. Pozdrawiam 

Link to comment
Share on other sites

  • 0

Witam.

Mam scene automatycznego zapalania światła pomysłu Rafała wrsja 1.2,I, 2014 która po załączeniu światła przez czujnik ruchu załączała światło na 30 min i każde naruszenie czujnika ruchu przedłużało świecenie do następnych 30 min. Po aktualizacji z 4.100 do 4.110 scena przestała poprawnie działać ponieważ przestała odliczać czas od 30 min do 0. tz. wygląda jakby się zacinało odliczanie np. pokazuje do wyłączenia 30,00 zmieni się na 29,59 i znowu pokazuje 30,00 przez co nie wyłącza światła. Pytanie do bardziej doświadczonych użytkowników co może być przyczyną tego.

 

-- Script for automation lights in home 

-- by Fibaro Bialy Kosciol 

-- version 1.2, I, 2014

 

-- TODO:

-- dodać możliwość osobnego poziomu sciemniania dla manualnego wlaczania

 

-- show status on debug window 

fibaro:debug("Getting list of virtual devices..."); 

-- connect to HC2 

HC2 = Net.FHttp("localhost", 80); 

-- with authentication 

HC2:setBasicAuthentication(„login”, „haslo”); 

-- grab virtual devices list from api 

response, status, errorCode = HC2:GET("/api/virtualDevices"); 

-- show status on debug window 

fibaro:debug("Status of reqest: " .. status .. '.'); 

 

-- if answer is wrong 

if (tonumber(status)~=200) then 

  fibaro:debug("Error " .. errorCode .. "."); 

end 

 

-- prepare places for previous values 

oldValues = {};

oldTimers = {};

lastWakeTime = {};

 

-- icons 

iconOn = 0; 

iconOff = 0; 

iconVId = 0; 

 

-- variables for summary 

globalValue = 0; 

globalSliderId = 0; 

globalSliderVId = 0; 

globalLabelId = 0; 

globalLabelVId = 0;

 

-- function to prepare value for sliders

function clockValue(val)

  clock = "";

  if (not tonumber(val)) then val = 0 end

  if (val<0) then val = 0 end

  m = math.floor( val/60 );

  s = math.floor( val - (m*60) );

  if (m<10) then clock = clock .. "0" end

  if (m) then clock = clock .. m .. "." end

  if (s<10) then clock = clock .. "0" end

  if (s) then clock = clock .. s end

  return clock;

end

 

-- main loop if answer is ok 

while (tonumber(status)==200) do 

  -- reset data of fastest device to switch off 

  fastestDevice = ""; 

  fastestTimer = 0; 

  fastestDeviceId = 0; 

  fastestSlider = 0;

  iconOn = 0;

  iconOff = 0;

  iconVId = 0; 

  -- decode text to json object 

  jsonTable = json.decode(response); 

  -- roll over all virtual devices 

  for virtualIndex, virtualData in pairs(jsonTable) do 

    -- fibaro:debug('Virtual Device Id [' .. virtualData.id .. ']'); 

    -- roll over all rows in virtual device 

    for rowIndex, rowData in pairs(virtualData.properties.rows) do 

      -- fibaro:debug('  Row [' .. rowIndex .. '][' .. rowData.type .. ']'); 

      -- if row type is label 

      if (rowData.type=='label') then 

        -- rool over all buttons in row 

        for labelIndex, labelData in pairs(rowData.elements) do 

          -- check if that is main label 

          if (globalLabelId==0 and labelData.name=='globalLabel') then 

            globalLabelVId = tonumber(virtualData.id); 

            globalLabelId = tonumber(labelData.id); 

            fibaro:debug('Label ' .. globalLabelId .. ' / ' .. globalLabelVId .. '.'); 

          end 

        end 

      end 

      -- if row type is slider 

      if (rowData.type=='slider') then 

        -- rool over all buttons in row 

        for sliderIndex, sliderData in pairs(rowData.elements) do 

          -- check if that is main slider 

          if (sliderData.name=='globalSlider') then 

            -- if not defined yet? 

            if (globalSliderId==0) then 

              globalSliderVId = virtualData.id; 

              globalSliderId = sliderData.id; 

              fibaro:debug('Global slider ' .. globalSliderId .. ' / ' .. globalSliderVId .. '.'); 

            end 

          end 

          -- check if button (slider) has right defined code? 

          if (string.find(sliderData.msg, "{")==1) then 

            -- decode defined code for button (slider) 

            sliderParams = json.decode(sliderData.msg); 

            -- if autoOff parameter is present? 

            if (sliderParams.action=="autoOff") then 

              

              -- grab device information from definition 

              deviceId = sliderParams.deviceId; 

              deviceType = fibaro:getType(deviceId); 

              deviceName = fibaro:getName(deviceId); 

              deviceValue, deviceTS = fibaro:get(deviceId, 'value'); 

              deviceSeconds = os.time() - deviceTS; 

              deviceValue = tonumber(deviceValue); 

              deviceDead =  tonumber(fibaro:getValue(deviceId, "dead")); 

              

              -- grab slider information 

              sliderId = sliderData.id;

              sliderName = "ui." .. sliderData.name .. ".value";

              sliderValue, sliderTS = fibaro:get(virtualData.id, sliderName);

              sliderSeconds = os.time() - sliderTS;

              sliderValue = tonumber(sliderValue);

              

              -- make old values if necessary 

              if (not oldValues[deviceId]) then 

                --fibaro:log('New device [' .. deviceName .. '][' .. deviceId .. ']!'); 

                fibaro:debug('New device [' .. deviceName .. '][' .. deviceId .. '] Type [' .. deviceType .. '] Value [' .. deviceValue .. '].'); 

                oldValues[deviceId] = 0; 

                oldTimers[deviceId] = 0; 

              end

 

              -- value from slider is not number?

              if (not sliderValue or (sliderValue % 1)>0 ) then

                --fibaro:debug("Restoring... [" .. sliderValue .. "]");

                sliderValue = oldTimers[deviceId];

              end

              -- slider value is smaller than prev value

              if ( (oldTimers[deviceId]-sliderValue) > 2 ) then

                sliderValue = oldTimers[deviceId];

              end

              sliderValue = tonumber(sliderValue);

              

              -- checking if its dead?

              if (deviceDead>0) then

                wakePeriod = sliderParams.wakeTime;

                if (wakePeriod) then wakePeriod = tonumber(wakePeriod) end

                if (not wakePeriod) then wakePeriod = 3600 end

                if (not lastWakeTime[deviceId] or lastWakeTime[deviceId]>wakePeriod) then

                  lastWakeTime[deviceId] = 0;

                  fibaro:wakeUpDeadDevice(deviceId);

                  fibaro:debug('WAKE UP [' .. deviceId .. ']...');

                else

                  --fibaro:debug('Device [' .. deviceId .. '] dead  [' .. lastWakeTime[deviceId] .. ']!');

                  lastWakeTime[deviceId] = lastWakeTime[deviceId] + 1;

                end

                sliderValue = 0;

              --end 

 

              -- turn on by slider 

              -- detecting if device has to be switched on 

              -- if slider changes eg. from scenes 

              elseif (sliderValue>0 and ((deviceValue==0 and deviceSeconds>2) or sliderValue>oldTimers[deviceId])) then 

                -- if device type is dimmer 

                if (deviceType=="dimmable_light") then 

                  -- if default value for dimmer is defined 

                  if (sliderParams.defaultValue) then 

                    -- set dimmer value to that 

                    fibaro:call(deviceId, 'setValue', tonumber(sliderParams.defaultValue)); 

                    -- remember new value as actual 

                    deviceValue = tonumber(sliderParams.defaultValue); 

                  -- if dimmer has not defined starting value 

                  else 

                    -- set maximum 

                    fibaro:call(deviceId, 'setValue', 100);

                    -- and remember as actual

                    deviceValue = 100;

                  end

                  -- log to home screen 

                  fibaro:log(sliderData.caption .. ' ON [' .. deviceValue .. '] by Slider [' .. sliderValue .. ']!'); 

                -- if device is binary switch or another 

                else 

                  -- remember as actual 

                  deviceValue = 1; 

                  -- basic switch on 

                  fibaro:call(deviceId, 'turnOn'); 

                  -- log to home screen 

                  fibaro:log(sliderData.caption .. ' ON by Slider [' .. sliderValue .. ']!'); 

                end 

              -- end 

 

              -- manualy on          

              -- if default value for timer is defined 

              -- and device was manualy switched on 

              -- and new status (value) is biggest than previously 

              -- and sliderValue==0? 

              elseif (sliderParams.defaultTime and deviceValue>oldValues[deviceId]) then 

                -- set slider value to defined time 

                sliderValue = sliderParams.defaultTime;

                -- if default starting value for dimmer device is defined? 

                if (sliderParams.defaultValue) then 

                  -- use maximum of defined dimmer value

                  deviceValue = tonumber(sliderParams.defaultValue);

                  fibaro:call(deviceId, 'setValue', deviceValue);

                end 

                -- log to home screen 

                fibaro:log(sliderData.caption .. ' Manual ON [' .. deviceValue .. ']!');

              -- end 

              

              -- manual off 

              elseif (sliderValue>0 and deviceValue==0 and deviceSeconds<2) then 

                sliderValue = 0; 

                -- show log on home screen 

                fibaro:log(sliderData.caption .. ' Aborting!'); 

                -- update slider value to show left time - zero 

                -- fibaro:call(virtualData.id, "setSlider", sliderData.id, sliderValue);

                fibaro:call(virtualData.id, "setProperty", sliderName,  sliderValue); 

              --end 

              

              -- switch off by slider 

              elseif (sliderValue==0 and oldTimers[deviceId]>0) then 

                -- log on home screen 

                fibaro:log(sliderData.caption .. ' OFF by slider!'); 

                -- switch off device 

                fibaro:call(deviceId, 'turnOff'); 

              --end 

                  

              -- counting to down 

              elseif (sliderValue>0) then 

 

                -- decresing slider value 

                sliderValue = sliderValue - 1; 

 

                -- debug on window

                fibaro:debug('Device [' .. deviceId .. ']: Value [' .. deviceValue .. '][' .. deviceSeconds .. ' s.]; Slider [' .. sliderValue .. '][' .. sliderSeconds .. ' s.];'); 

 

                -- time to switch off 

                if (sliderValue==0) then 

                  -- log on home screen 

                  fibaro:log(sliderData.caption .. ' Auto OFF!'); 

                  -- switch off device 

                  fibaro:call(deviceId, 'turnOff'); 

                --end 

              

                -- update dimmer level 

                -- if defined "dimming time" parameter? 

                elseif (sliderParams.dimmTime and deviceType=="dimmable_light") then 

                  dimmTime = tonumber(sliderParams.dimmTime); 

                  -- if default starting value for dimmer device is defined? 

                  if (sliderParams.defaultValue) then 

                    -- calculate dimmer step for one second 

                    -- use starting default value for dimmer device 

                    dimmStep = tonumber(sliderParams.defaultValue) / dimmTime; 

                    --dimmStep = deviceValue / dimmTime; 

                  else 

                    -- calculate dimmer step for one second 

                    -- use 100% value for dimmer device 

                    dimmStep = 100 / dimmTime; 

                  end 

                  -- if time to start dimming 

                  if (sliderValue<dimmTime) then 

                    -- calculate dimmer value 

                    newVal = sliderValue * dimmStep; 

                    -- in other case use maximum value 

                  else 

                    -- if default starting value for dimmer device is defined? 

                    if (sliderParams.defaultValue) then 

                      -- use maximum of defined dimmer value 

                      newVal = tonumber(sliderParams.defaultValue); 

                    else 

                      -- use 100% 

                      newVal = 100; 

                    end 

                  end 

                  -- if calculated value is lower then 1 

                  if (newVal<1) then 

                    newVal = 1; 

                  end 

                  -- if calculated value is grater then 100 

                  if (newVal>100) then 

                    newVal = 100; 

                  end 

                  -- set the new dimmer value if calculated value is lower then actual 

                  -- or new value is bigger but depending of slider (time) changes 

                  if (newVal<deviceValue or sliderValue>oldTimers[deviceId]) then 

                    fibaro:call(deviceId, 'setValue', newVal+1); 

                  end 

                end 

              

              end 

 

              -- update fastest timer and device name and icons 

              if ((sliderValue>0 or oldValues[deviceId]>1)

              and (sliderValue<fastestTimer or fastestTimer==0))

              then

                fastestTimer = sliderValue;

                fastestDevice = sliderData.caption;

                fastestDeviceId = deviceId; 

                fastestSlider = sliderData.id; 

                iconVId = virtualData.id; 

                iconOff = virtualData.properties.deviceIcon; 

                iconOn = sliderData.buttonIcon; 

              end 

 

              -- remeber old values and timers (sliders) 

              oldValues[deviceId] = deviceValue; 

              oldTimers[deviceId] = sliderValue; 

              

              -- select new value on the slider

              new = clockValue(sliderValue);

              old = fibaro:getValue(virtualData.id, sliderName);

              if (new ~= old) then

                fibaro:call(virtualData.id, "setProperty", sliderName, new);

              end

              

            end 

          end 

        end 

      end 

    end 

  end 

 

  --fibaro:debug(fastestDevice .. '... [' .. fastestTimer .. ']...');

  

  -- update main slider

  if (globalSliderId and globalSliderVId) then

    old = fibaro:getValue(globalSliderVId, "ui.globalSlider.value");

    new = clockValue(fastestTimer);

    if (new ~= old) then

      fibaro:call(globalSliderVId, "setProperty", "ui.globalSlider.value", new);

    end

  end

  

  -- update main label 

  if (globalLabelId and globalLabelVId) then 

    new = "---";

    if (fastestTimer>0) then

      new = "";

      h = math.floor( fastestTimer/3600 );

      m = math.floor( ( fastestTimer - (h*3600) )/60 );

      s = math.floor( fastestTimer - (h*3600) - (m*60) );

      if (h>0) then new = new .. h .. ":" end

      if (m<10) then new = new .. "0" end

      new = new .. m .. ":";

      if (s<10) then new = new .. "0" end

      new = new .. s;

      new = new .. " " .. fastestDevice;

    end

    old = fibaro:getValue(globalSliderVId, "ui.globalLabel.value");

    if (new ~= old) then

      fibaro:call(globalLabelVId, "setProperty", "ui.globalLabel.value", new);

    end

  end 

    

  -- update icon to ON

  if (iconVId and iconOn) then 

    fibaro:call(iconVId, "setProperty", "currentIcon", iconOn); 

  end 

 

  -- WAIT

  fibaro:sleep(500); 

 

  -- update icon to OFF 

  if (iconVId and iconOff) then 

    fibaro:call(iconVId, "setProperty", "currentIcon", iconOff); 

  end 

  

  -- WAIT

  fibaro:sleep(500);

  

end 

-- if everything is ok, the main loop will never end 

 

-- wait after API error 

fibaro:sleep(10000); 

Link to comment
Share on other sites

  • 0

Witaj  

Please login or register to see this link.

 wybacz ze pytam ale mnie nie dziala ta scena zmienilem tylko numery na poczatku urzadzen wszystko pozostale tak jak ty masz ale wyskakuje mi blad

[[DEBUG] 22:40:41: --------- debugging ----------
[DEBUG] 22:40:41: line 111: attempt to concatenate field 'deviceID' (a nil value)

 
czy jest cos co moge poprawic albo czy cos pominalem - jesli trzeba to wkleje twoja scene dla potrzeby, ale nie rozumiem bledu
pozdrawiam i dziekuje za super scene nauczyla mnie juz podstaw ale najwyrazniej jeszcze nie wystarczajaco//////
 
Edited by confesor
Link to comment
Share on other sites

  • 0

@confesor

Błąd, który dostajesz, wynika z braku ID "wywoływacza" sceny.

Kod się praktycznie nie wykonuje i wpada w ostatnią bramkę "nieoczekiwanego błędu", która też się wywala, bo wartość  

Please login or register to see this code.

jest pusta. Nie zawiera żadnych danych.

Numery urządzeń na początku musisz zmienić w dwóch miejscach. Tutaj:

Please login or register to see this code.

i tutaj:

Please login or register to see this code.

Gdzie XX należy zastąpić ID sensora ruchu a XXX - ID dimmera światła do zapalania.

Link to comment
Share on other sites

  • 0

@wiesiekr

To mi wygląda raczej na urządzenie wirtualne niż scenę.

Na wstępie zaznaczę, że nie chce mi się wczytywać głęboko w logikę tego urządzenia (zresztą brak informacji a nie chce mi się szukać) i autor, albo ktoś kto tego używa najlepiej z możliwością sprawdzenia na 4.110 prawdopodobnie pomoże najszybciej.

Nie podałeś nawet komunikatów debuggowania a przyczyn może być wiele... może przyciski (z fotki, którą załączyłeś) powinny mieć zaznaczony kod Lua zamiast ciągu znaków (te ciągi są dekodowane przez jsona? jeśli w 4.100 tak działało, to może coś się zmieniło teraz.) A może zmieniły się warunki korzystania z /api/? może trzeba użyć portu 11111 zamiast 80? hasło i login są poprawne?

Niestety nie pomogę.

Link to comment
Share on other sites

  • 0

Witam serdecznie hoomee - nadal pokazuje mi sie ten sam numer bledu w lini 111, to co napisales sprawdzalem juz na samym poczatku bo tez tak myslalem ale blad nadal zostal i nic sie nie dzieje. Wysylam program w jakim stanie go wkleilem moze zobaczysz czy cos zle zrobilem . Zaznacze ze zrobilem tez zmienna globalna manualOn ze stanami true i false tak jak ty. Ale zastanawiam sie moze to przez to ze jeszcze jakas inna zmienna globalna musi byc stworzona??Jak bedziesz mial czas to zerknij, ja jeszcze z tym powalcze sam tak czy siak zreszta to najlepsza forma nauki. dziekuje serdecznie i pozdrawiam

P.s dzieki za wczorajsza szybka odpowiedz 

 

 

P.S 1 scena zaczela dzialac ale jest przekroczenie instancji teraz/ Ponizej kod ktory uzywam

--[[
%% properties 
104 value
111 value
%% globals 
--]] 

local sensorID = 104                 -- sensor ruchu
local lightID = 111                 -- światło sufit
local delay = 60                    -- opóźnienie gaszenia w sekundach 
local nightStartsat = 23            -- początek ciszy nocnej
local dayStartsat = 6               -- koniec ciszy nocnej
local lightDay = 100                -- moc światła w dzień
local lightNight = 40               -- moc światła w nocy
---- 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 
    if ( (tonumber(os.date("%H")) >= nightStartsat) or (tonumber(os.date("%H")) < dayStartsat) )
      then
        fibaro:call(lightID, "setValue", lightNight)
        fibaro:debug("Jest noc, natężenie światła: "..lightNight)
        fibaro:sleep(1000)
    elseif ( (tonumber(os.date("%H")) >= dayStartsat) and (tonumber(os.date("%H")) < nightStartsat) )
      then
        fibaro:call(lightID, "setValue", lightDay)
        fibaro:debug("Jest dzień, natężenie światła: "..lightDay)
        fibaro:sleep(1000)
    else
      fibaro:debug(os.date("%H"))
      fibaro:debug("dziwny błąd, aborting")
      fibaro:abort() 
    end
  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

Edited by confesor
Link to comment
Share on other sites

  • 0
8 godzin temu, hoomee napisał:

@wiesiekr

To mi wygląda raczej na urządzenie wirtualne niż scenę.

Na wstępie zaznaczę, że nie chce mi się wczytywać głęboko w logikę tego urządzenia (zresztą brak informacji a nie chce mi się szukać) i autor, albo ktoś kto tego używa najlepiej z możliwością sprawdzenia na 4.110 prawdopodobnie pomoże najszybciej.

Nie podałeś nawet komunikatów debuggowania a przyczyn może być wiele... może przyciski (z fotki, którą załączyłeś) powinny mieć zaznaczony kod Lua zamiast ciągu znaków (te ciągi są dekodowane przez jsona? jeśli w 4.100 tak działało, to może coś się zmieniło teraz.) A może zmieniły się warunki korzystania z /api/? może trzeba użyć portu 11111 zamiast 80? hasło i login są poprawne?

Niestety nie pomogę.

Dzięki hoomee za zwrócenie uwagi oraz pomoc.. Masz rację przejęzyczyłem się jest to UV a nie scena a błąd który powodował nie odliczanie czasu to polegał na tym że w starszych wersjach w przycisku miał zaznaczone-ciąg znaków a w  tej wersji trzeba zaznaczyć kod lua. To urządzenie wirtualne do automatycznego sterowania oświetleniem jest stare z przed trzech lat ale do tej pory działało mi super. A potrafi naprawdę wiele np. jeżeli zostanie naruszone z przycisku to wyłącza światło np. po 15 min i światło załączając się może się pomału rozjaśniać, załączone z kolei przez czujnik ruch zapala światło (może również płynnie rozjaśniać) na np. 30 min i każde naruszenie czujnika ponownie przedłuża świecenie do 30min i wyłącza światło (potrafi też wygaszać płynnie).  Jeszcze raz wielkie dzięki dla kolegi hoomee za pomoc.

Edited by wiesiekr
Link to comment
Share on other sites

  • 0
1 hour ago, confesor said:

(...)

P.S 1 scena zaczela dzialac ale jest przekroczenie instancji teraz/ Ponizej kod ktory uzywam

(...)

 

Czyli działa :) to dobrze.

Klikałeś "Uruchom scenę" zamiast wywołać ją ruchem ;) przyznam, że nie pomyślałem o tym wcześniej.

 

Przekroczenie instancji jest częstym problemem w nowych wersjach firmware'u (bo nareszcie Fibaro zaczęło zwracać na to uwagę ;) ).

Ale w tym wypadku scena sama się reguluje i teoretycznie nie pozwala na więcej niż 2 instancje równocześnie. Tyle, że procesor jest szybszy niż światło ;) a w każdym razie szybszy niż wykonywany kod, więc może się zdarzyć, że przy szybkich zmianach (ruch natychmiast po uzbrojeniu czujnika, po kliknięciu włącznika światła lub tp.) może wystartować kolejna instancja. Dlatego w ustawieniach sceny nie w "zaawansowanych, ale na pierwszej stronie "Ogólnej" określ maksymalną ilość instancji na 5.

Teoretycznie musiałbyś być szybszy niż światło, żeby przekroczyć pięć instancji, ale to tylko komputery, więc nie daję żadnej gwarancji ;)

Link to comment
Share on other sites

  • 0

Dzieki wielkie pozdrawiam serdecznie / zastanawiam sie jeszcze nad jednym problemem ale najpierw ogarne ten temat i poucze sie go troche pozd

Link to comment
Share on other sites

  • 0

Witaj hoomee i confesor.

 

Zaznaczę że to moje początki z tymi scenami. Wcześniej pracował na bloczkach i poz mianie centralki te działają, ale próbuję opanować te z Lua.

 

Przekleiłem scenę jak jest w opisie zmieniając jedynie wartości sensorID i lightID i niestety mam podobny błąd jak confesor

Please login or register to see this code.

Po wykryciu ruchu na debugerze pojawia się:

[DEBUG] 20:55:13: line 110: attempt to concatenate field 'deviceID' (a nil value)

 

Czytałem że powinienem utworzyć jakąś zmienną globalną, ale szczerze nie mam pojęcia jak. Wiem że to n00bowskie pytanie, ale każdy kiedyś zaczynał..

Z góry dziękuję za wskazówki

 

Edit:

Linia z debugera to:

Please login or register to see this code.

Edit 2

Znalazłem zmienną predefiniowaną i dodałem manualON. Niestety dalej błąd i światło się nie zapala..

Edited by eustachy
Edit1:Wskazanie linii z debugera. Edit2: Ustawienie zmiennej globalnej.
Link to comment
Share on other sites

  • 0

Zwracaj również uwagę na wielkość liter. Powinno być "manualOn" a nie "manualON".

Poza tym sprawdź czy na pewno czy ID się zgadzają - sensorID musi być od czujnika ruchu a nie master, albo temperatura. Czasami łatwo to przeoczyć.

 

Ponieważ sam w tej chwili wciąż używam tej sceny i (wydaje mi się, że) działa cały czas dobrze, to wklejam tutaj moją wersję (spersonalizowaną dla eustachego).

Dodałem tam tylko więcej opcji debugowania np. jeszcze bramkę na uruchamianie ręczne (które tutaj akurat nie ma za bardzo sensu).

Please login or register to see this code.

 

Edited by hoomee
więcej szczegółów
Link to comment
Share on other sites

  • 0

Masz rację, zmieniłem na poprawną nazwę zmiennej. teraz po zastosowaniu Twojego kodu mam następujący debug:

[DEBUG] 18:42:59: źródło: 91
[DEBUG] 18:42:59: scena numer: 1
[DEBUG] 18:42:59: unexpected error! aborting
[DEBUG] 18:42:59: --------- aborting ----------

 

 

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...