Forum użytkowników automatyki budynkowej

Z-wave => Fibaro - sceny => Wątek zaczęty przez: Garen w Kwiecień 24, 2018, 01:16:03 pm

Tytuł: Scena wykona się tylko 1 raz
Wiadomość wysłana przez: Garen w Kwiecień 24, 2018, 01:16:03 pm
Witam.
Chcę stworzyć scenę, która w założeniu ma w określonym przedziale czasu po naruszeniu czujnika drzwi ustawić lamelki na 50%.
W tym celu stworzyłem zmienną globalną licznik, który zeruję o określonej godzinie. (scena_1)
Następnie scena_2 ustawia lamelki o określonej godzinie.
Dlaczego?
1) w obu scenach mam przekroczoną liczbę instancji (czytałem o tym, ale nie udało mi się tego wyeliminować)
2) czy taki sposób nie zapycha mi procesora?
3) jest jakiś lepszy sposób, aby scena wykonała się raz na dobe? (zastanawiałem się po przekonwertowaniu na Lua(jestem początkujący) nad fibaro:sleep(24*60*60*1000) ), ale czy to ma sens?

W scenie_2 chciałem dodać jeszcze warunek, że pozycja lamelek ~= od 50, ale nie ma takiego znaku...
Tytuł: Odp: Scena wykona się tylko 1 raz
Wiadomość wysłana przez: marecki_0luk1 w Kwiecień 25, 2018, 09:45:25 am
zrob podglad LUA i wstaw tutaj kod jak możesz
Tytuł: Odp: Scena wykona się tylko 1 raz
Wiadomość wysłana przez: Garen w Kwiecień 26, 2018, 08:40:30 am
scena_1

--[[
%% autostart
%% properties
%% weather
%% events
%% globals
licznik
--]]

local sourceTrigger = fibaro:getSourceTrigger();
function tempFunc()
local currentDate = os.date("*t");
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) == "13:03")  and  tonumber(fibaro:getGlobalValue("licznik")) == tonumber("1") )
)
then
   fibaro:setGlobal("licznik", "0");
end

setTimeout(tempFunc, 60*1000)
end
if (sourceTrigger["type"] == "autostart") then
tempFunc()
else

local currentDate = os.date("*t");
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  tonumber(fibaro:getGlobalValue("licznik")) == tonumber("1") )
or
startSource["type"] == "other"
)
then
   fibaro:setGlobal("licznik", "0");
end

end

scena_2

--[[
%% autostart
%% properties
62 value
%% weather
%% events
%% globals
licznik
--]]

local sourceTrigger = fibaro:getSourceTrigger();
function tempFunc()
local currentDate = os.date("*t");
local startSource = fibaro:getSourceTrigger();
if (
 ( (tonumber(os.date("%H%M")) >= tonumber(string.format("%02d%02d", "13", "05")) and tonumber(os.date("%H%M")) <= tonumber(string.format("%02d%02d", "14", "14"))) and (math.floor(os.time()/60)-math.floor(1524654300/60))%0 == 0  and  tonumber(fibaro:getValue(62, "value")) > 0  and  tonumber(fibaro:getGlobalValue("licznik")) == tonumber("0") )
)
then
   fibaro:call(4, "setValue2", "50");
   fibaro:setGlobal("licznik", "1");
end

setTimeout(tempFunc, 60*1000)
end
if (sourceTrigger["type"] == "autostart") then
tempFunc()
else

local currentDate = os.date("*t");
local startSource = fibaro:getSourceTrigger();
if (
 ( (tonumber(os.date("%H%M")) >= tonumber(string.format("%02d%02d", "13", "05")) and tonumber(os.date("%H%M")) <= tonumber(string.format("%02d%02d", "14", "14")))  and  tonumber(fibaro:getValue(62, "value")) > 0  and  tonumber(fibaro:getGlobalValue("licznik")) == tonumber("0") )
or
startSource["type"] == "other"
)
then
   fibaro:call(4, "setValue2", "50");
   fibaro:setGlobal("licznik", "1");
end

end