Rörelse sensor aktiverad, tänd lampa ** Ny version **

jompa68
Proffsmedlem
Posts: 735
Joined: 12 Aug 2012, 08:53
11
Location: Hofors

om du vill ha kvar trigger value till 255 så måste du ändra i scenen till detta värde. alternativ ändrar du inställningen på sensorn till enligt min bild. Kommer inte ihåg vilket utav parametrarna det var
ImageUploadedByTapatalk1372912896.573961.jpg
ImageUploadedByTapatalk1372912896.573961.jpg (52.56 KiB) Viewed 18027 times
maxxar
Medlem
Posts: 126
Joined: 06 Sep 2012, 13:30
11

Lustigt men det verkar som det löste sig efter en omstart av HC2, men har ändå synkat inställningarna med dina.
Tack!
zorro
Medlem
Posts: 365
Joined: 22 Oct 2013, 16:16
10

Hej igen
allt funkar utom en funktion
jag har ställt att lampan ska tändas med 20% men den tänds till senaste inställda värde :roll: :roll:
jag har säkert gjort något fel men ser inte vad :oops: :oops:
--[[
%% properties
71 value
%% globals
--]]

--71 = PIR for movement detection

--Scene purpose
--IF PIR detects movement then turn on dimmer and turn it off 5 minutes.
-- If new movement detected during the 5 minute period set the timer for 5 minutes

local sceneId = 31 --ID of this scene, used to detect number of instances run
local timerEndTime = 2 --Minutes to keep the lamp turned on after PIR detects movement
local timer = "timer" --Name of global variabel to control the timer
local timerValue = fibaro:getGlobalValue(timer) --Current value of global variabel for timer
local triggerValue = fibaro:getValue(71, "value") --Get PIR value that activated this scene

local lights = 79 --light to be controlled by this scene
local dimmerValue = "20" --Ljusstyrka

fibaro:debug("start, timer = " .. timerValue .. " lights = " .. fibaro:getValue(lights, "value") .. " ,triggerValue = " .. triggerValue)
if (fibaro:getValue(lights, "value") == "0" and triggerValue == "1") then
--If starts if lights off and PIR detected movement
fibaro:call(lights, "turnOn") --Turn lights on
fibaro:setGlobal(timer, timerEndTime) --Set global variabel for timer
while (fibaro:getGlobalValue(timer) ~= "0") do
--Loop used to control timer, each loop 1 minute and continues
--as long as timer variabel isn't 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 minute
fibaro:debug("Loop - timer = " .. fibaro:getGlobalValue(timer))
fibaro:sleep(60*1000) --Wait 1 minute
end
fibaro:call(lights, "turnOff") --Turn lights off
elseif fibaro:countScenes(sceneId) > 1 then
--if scene is already running the set timer to 2 minutes
fibaro:setGlobal(timer, timerEndTime) --set global variabel for timer to 2 minutes
fibaro:debug("New instance, totalt = " .. fibaro:countScenes(sceneId))
end
fibaro:debug("End, instances = " .. fibaro:countScenes(sceneId))
Fibaro fantastic
Aktuell HC2 Version: 4.520
Mackan3972
Medlem
Posts: 44
Joined: 07 Dec 2013, 22:28
10

Kan någon hjälpa mig med detta jag får det inte att fungera alls, lampan tänds inte alls. Jag har bytt ut pir värde till min Aeon 4i1 (55) och lamp id till (76) Scenid till 16 som är id på denna scenen. Är det något mer som behövs göras?? Är helt grön på detta men försöker ;)
Attachments
LuaKod.jpg
LuaKod.jpg (821.91 KiB) Viewed 17556 times
Mackan3972
Medlem
Posts: 44
Joined: 07 Dec 2013, 22:28
10

Jag behöver hjälp med att få det där med variablar förklarat på ett enkelt sätt, jag har provat med Jompas scen om hur man får en lampa tänd i badrummet med rörelse, men förstår att jag behöver på nått sätt lägga in "timer" variabel.

Någon som antar utmaningen? :P
User avatar
sonnyboy
Proffsmedlem
Posts: 669
Joined: 26 Sep 2013, 08:05
10
Location: Västerås

@Mackan3972
Har du fått detta att funka?, får exakt samma i loggen som du :cry:
Tänkte använda detta till tvättstugan, det är inte kul när gumman gnäller på att det inte funkar.
Fibaro HomeCenter 2
Fw 4.600
BeyondMeasure 1.10
EventRunner
jompa68
Proffsmedlem
Posts: 735
Joined: 12 Aug 2012, 08:53
11
Location: Hofors

Vad är det som inte fungerar?
Ge mig lite debug loggar så kan jag kika på det.
User avatar
sonnyboy
Proffsmedlem
Posts: 669
Joined: 26 Sep 2013, 08:05
10
Location: Västerås

Äntligen så funkar det, tack ändå Jompa.
Det var timern som inte ville hoppa igång, men nu lirar det.
Fibaro HomeCenter 2
Fw 4.600
BeyondMeasure 1.10
EventRunner
User avatar
Bamsefar
Z-Wave Kung
Posts: 1230
Joined: 25 Nov 2013, 15:06
10
Location: Stockholm

Tänkte jag kan dela med mig av en liknande lösning på samma utmaning. Jag har valt något annorlunda lösning, och samtidigt baserat timerdelen på en importerad virtuel enhet som rafal.m har kodat ihop:

http://forum.fibaro.com/viewtopic.php?t=2693

Jag gillar verkligen rafal.m's lösning, jag använder den till alla mina timers - dvs jag har bara EN timer tack vare denna. I vilket fall, utöver att då definiera en timer i ovanstående kod som rafal.m då skivit, så har jag i detta exempel dels en röresesensor (Everspring SP814) och en dörrsensor (Fibaro's door sensor), plus att jag använder TOD (TimeOfDay) för att styra bort tändning av lampa under natten:

Code: Select all

--[[
%% autostart
%% properties
13 value
59 value
%% globals
TOD
--]]

local startSource = fibaro:getSourceTrigger();

if (
 ( ( tonumber(fibaro:getValue(13, "value")) > 0  or  tonumber(fibaro:getValue(59, "value")) > 0 ) and  fibaro:getGlobalValue("TOD") ~= "Natt" )
or
startSource["type"] == "other"
)
then
	fibaro:call(68, "setSlider", "4", "1800");
end

if ( tonumber(fibaro:getValue(10, "value")) > 0
	and tonumber(fibaro:getValue(13, "value")) == 0
    and tonumber(fibaro:getValue(59, "value")) == 0 )
then
	fibaro:call(68, "setSlider", "4", "-120");
end
Det som skiljer är alltså att Everspring SP814 sensorn "håller" röreseflaggan "aktiv" under längre period och rör du dig framför den hela tiden - t.ex. i ett kök - så kan du hamna i läget att sensorn enbart indikerar att du rör på dig (>0) hela tiden (vilket bevisligen stämmer) och timern helt enkelt går ut hela tiden och därefter slocknar alla lampor. Kul - not. Så vad jag gör är att sätta timern på ett mycket högt tidsvärde (man skulle kunna tänka sig att tända permanent om man inte använder rafal.m's timerlösning), och sedan forcerar ned tiden till -120 = 120 sekunder efter det att rörelsesensorn indikerat "att nu rör sig ingen framför sensorn" (=0). Alltså är lampan tänd tills du slutar att röra dig + 120 sekunder (i detta exemplet).

Som alternativlösning alltså.
Testar Home Assistant på Raspberry Pi4B - nice :mrgreen:
zorro
Medlem
Posts: 365
Joined: 22 Oct 2013, 16:16
10

Försöker och få till min toalettlampscen
jag vill att lampan ska tändas till 10% men den tänds till 100% fast jag ändrat i scenen
hjälp någon :mrgreen: :mrgreen:
--[[
%% properties
167 value
%% globals
--]]

--167 = PIR for movement detection

--Scene purpose
--IF PIR detects movement then turn on dimmer and turn it off 5 minutes.
-- If new movement detected during the 5 minute period set the timer for 5 minutes

local sceneId = 62 --ID of this scene, used to detect number of instances run
local timerEndTime = 2 --Minutes to keep the lamp turned on after PIR detects movement
local timer = "timer" --Name of global variabel to control the timer
local timerValue = fibaro:getGlobalValue(timer) --Current value of global variabel for timer
local triggerValue = fibaro:getValue(167, "value") --Get PIR value that activated this scene

local lights = 170 --light to be controlled by this scene
local dimmerValue = "10" --Ljusstyrka

fibaro:debug("start, timer = " .. timerValue .. " lights = " .. fibaro:getValue(lights, "value") .. " ,triggerValue = " .. triggerValue)
if (fibaro:getValue(lights, "value") == "0" and triggerValue == "255") then
--If starts if lights off and PIR detected movement
fibaro:call(lights, "turnOn") --Turn lights on
fibaro:setGlobal(timer, timerEndTime) --Set global variabel for timer
while (fibaro:getGlobalValue(timer) ~= "0") do
--Loop used to control timer, each loop 1 minute and continues
--as long as timer variabel isn't 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 minute
fibaro:debug("Loop - timer = " .. fibaro:getGlobalValue(timer))
fibaro:sleep(60*1000) --Wait 1 minute
end
fibaro:call(lights, "turnOff") --Turn lights off
elseif fibaro:countScenes(sceneId) > 1 then
--if scene is already running the set timer to 2 minutes
fibaro:setGlobal(timer, timerEndTime) --set global variabel for timer to 2 minutes
fibaro:debug("New instance, totalt = " .. fibaro:countScenes(sceneId))
end
fibaro:debug("End, instances = " .. fibaro:countScenes(sceneId))
Fibaro fantastic
Aktuell HC2 Version: 4.520
User avatar
Bamsefar
Z-Wave Kung
Posts: 1230
Joined: 25 Nov 2013, 15:06
10
Location: Stockholm

Det räcker inte med att bara skapa en variabel som säger dimmerValue - du måste använda funktionen för att styra dimmer'ns värde, och inte turnOn som är i koden:

Code: Select all

fibaro:call(lights, "setValue", tostring(dimmerValue)) --Turn lights on
Plus att variabel är inte "10" utan 10:

Code: Select all

local dimmerValue = 10 --Ljusstyrka
Så att hela LUA koden ser ut såhär:

Code: Select all

--[[
%% properties
167 value
%% globals
--]]

--167 = PIR for movement detection

--Scene purpose
--IF PIR detects movement then turn on dimmer and turn it off 5 minutes.
-- If new movement detected during the 5 minute period set the timer for 5 minutes

local sceneId = 62 --ID of this scene, used to detect number of instances run
local timerEndTime = 2 --Minutes to keep the lamp turned on after PIR detects movement
local timer = "timer" --Name of global variabel to control the timer
local timerValue = fibaro:getGlobalValue(timer) --Current value of global variabel for timer
local triggerValue = fibaro:getValue(167, "value") --Get PIR value that activated this scene

local lights = 170 --light to be controlled by this scene
local dimmerValue = 10 --Ljusstyrka

fibaro:debug("start, timer = " .. timerValue .. " lights = " .. fibaro:getValue(lights, "value") .. " ,triggerValue = " .. triggerValue)
if (fibaro:getValue(lights, "value") == "0" and triggerValue == "255") then
--If starts if lights off and PIR detected movement
fibaro:call(lights, "setValue", tostring(dimmerValue)) --Turn lights on
fibaro:setGlobal(timer, timerEndTime) --Set global variabel for timer
while (fibaro:getGlobalValue(timer) ~= "0") do
--Loop used to control timer, each loop 1 minute and continues
--as long as timer variabel isn't 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 minute
fibaro:debug("Loop - timer = " .. fibaro:getGlobalValue(timer))
fibaro:sleep(60*1000) --Wait 1 minute
end
fibaro:call(lights, "turnOff") --Turn lights off
elseif fibaro:countScenes(sceneId) > 1 then
--if scene is already running the set timer to 2 minutes
fibaro:setGlobal(timer, timerEndTime) --set global variabel for timer to 2 minutes
fibaro:debug("New instance, totalt = " .. fibaro:countScenes(sceneId))
end
fibaro:debug("End, instances = " .. fibaro:countScenes(sceneId))
Testar Home Assistant på Raspberry Pi4B - nice :mrgreen:
zorro
Medlem
Posts: 365
Joined: 22 Oct 2013, 16:16
10

Lysande ska testa :mrgreen: :mrgreen:
Fibaro fantastic
Aktuell HC2 Version: 4.520
zorro
Medlem
Posts: 365
Joined: 22 Oct 2013, 16:16
10

Stort TACK Bamsefar funkar perfekt :mrgreen: :mrgreen:
Fibaro fantastic
Aktuell HC2 Version: 4.520
Post Reply