Hjälp Lua som får rörelsesensor att tända lampa i 3 min
Posted: 12 Jun 2015, 22:26
Hej!
Har inte gett upp hoppet att lyckas med ett LUA script ännu. Försöker få en rörelsesensor att tända en lampa i 3 min och sedan släcka den om sensorn blivit överträdd oavsett status. (öppnar man ytterdörren ska hallampan tändas). I ett senare steg ska den givetvis inte tändas när man går ut men jag har inte sensor för det ännu, däremot kanske jag kan använda Foscam kameran jag ska ut och montera för det, vi får se hur den funkar.
Hur som helst, jag har googlat runt och till slut kommit fram till att scriptet nedan borde funka men det gör det givetvis inte
173 är rörelsesensorn
175 är en luxsensor (jag vill inte att hallampan ska tändas när det är tillräckligt ljust)
--[[
%% autostart
%% properties
173 value -- Pir ytterdörr
175 value -- ljussensor
%% globals
--]]
local sceneId = 69 --ID of this scene, used to detect number of instances run
local timerEndTime = 300 --Seconds to keep the lamp turned on after PIR detects movement
local timer = "timer" --Name of global variabel to control the timer
local Lights = 164
local startSource = fibaro:getSourceTrigger();
if (
( tonumber(fibaro:getValue(173, "value")) > 0 )
and
( tonumber(fibaro:getValue(175, "value")) < 100 )
or
startSource["type"] == "other"
)
then
fibaro:call(Lights, "turnOn")
fibaro:setGlobal(timer, timerEndTime) --Set global variabel for timer
end
while (fibaro:getGlobalValue(timer) ~= "0") do --loop until timer is 0
timerValue = tonumber(fibaro:getGlobalValue(timer)) --Get current value of global variabel timer
fibaro:setGlobal(timer, timerValue-1) --Decrease global variabel for timer with 1 second
fibaro:debug("Loop - timer = " .. fibaro:getGlobalValue(timer)) --debug
fibaro:sleep(1000) --Wait 1 second
end
fibaro:call(Lights, "turnOff") --Turn lights off
elseif fibaro:countScenes(sceneId) > 1 then --if scene is already running , reset the timer to 3 minutes
fibaro:setGlobal(timer, timerEndTime) --set global variabel for timer to 2 minutes
fibaro:debug("New instance, totalt = " .. fibaro:countScenes(sceneId)) --debug
end
när jag testar scriptet får jag
[ERROR] 21:41:00: line 32: expected near 'elseif' (raden i röd text)
Någon som har tankar/ideer eller kanske till och med kunskap
Det finns säkert fler fel, skulle vara tacksam för kommentarer till ändringar så jag ngn gång kanske lyckas börja lära mig.
Har inte gett upp hoppet att lyckas med ett LUA script ännu. Försöker få en rörelsesensor att tända en lampa i 3 min och sedan släcka den om sensorn blivit överträdd oavsett status. (öppnar man ytterdörren ska hallampan tändas). I ett senare steg ska den givetvis inte tändas när man går ut men jag har inte sensor för det ännu, däremot kanske jag kan använda Foscam kameran jag ska ut och montera för det, vi får se hur den funkar.
Hur som helst, jag har googlat runt och till slut kommit fram till att scriptet nedan borde funka men det gör det givetvis inte
173 är rörelsesensorn
175 är en luxsensor (jag vill inte att hallampan ska tändas när det är tillräckligt ljust)
--[[
%% autostart
%% properties
173 value -- Pir ytterdörr
175 value -- ljussensor
%% globals
--]]
local sceneId = 69 --ID of this scene, used to detect number of instances run
local timerEndTime = 300 --Seconds to keep the lamp turned on after PIR detects movement
local timer = "timer" --Name of global variabel to control the timer
local Lights = 164
local startSource = fibaro:getSourceTrigger();
if (
( tonumber(fibaro:getValue(173, "value")) > 0 )
and
( tonumber(fibaro:getValue(175, "value")) < 100 )
or
startSource["type"] == "other"
)
then
fibaro:call(Lights, "turnOn")
fibaro:setGlobal(timer, timerEndTime) --Set global variabel for timer
end
while (fibaro:getGlobalValue(timer) ~= "0") do --loop until timer is 0
timerValue = tonumber(fibaro:getGlobalValue(timer)) --Get current value of global variabel timer
fibaro:setGlobal(timer, timerValue-1) --Decrease global variabel for timer with 1 second
fibaro:debug("Loop - timer = " .. fibaro:getGlobalValue(timer)) --debug
fibaro:sleep(1000) --Wait 1 second
end
fibaro:call(Lights, "turnOff") --Turn lights off
elseif fibaro:countScenes(sceneId) > 1 then --if scene is already running , reset the timer to 3 minutes
fibaro:setGlobal(timer, timerEndTime) --set global variabel for timer to 2 minutes
fibaro:debug("New instance, totalt = " .. fibaro:countScenes(sceneId)) --debug
end
när jag testar scriptet får jag
[ERROR] 21:41:00: line 32: expected near 'elseif' (raden i röd text)
Någon som har tankar/ideer eller kanske till och med kunskap
Det finns säkert fler fel, skulle vara tacksam för kommentarer till ändringar så jag ngn gång kanske lyckas börja lära mig.