Advertisement
boomx

2 MotionSensor - LUA

Aug 25th, 2015
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.66 KB | None | 0 0
  1. --[[
  2. %% properties
  3. 43 value
  4. 175 value
  5. %% globals
  6. --]]
  7.  
  8. motionID = 93; -- MotionSensor1
  9. motionID2 = 175; -- MotionSensor2
  10. lightID = 157; -- LightID
  11.  
  12. timeWithOutMotion = 120;  -- Zeit in Sekunden; bitte anpassen
  13.  
  14. if (tonumber(fibaro:countScenes())>1) then
  15.   fibaro:debug('Kill second scene!');
  16.   fibaro:abort();
  17. end
  18.  
  19. local motion2 = fibaro:getValue(motionID2, 'value');
  20. local armedMotion2, lastArmedMotion2 = fibaro:get(motionID2, 'armed');
  21. local motion = fibaro:getValue(motionID, 'value');
  22. local armedMotion, lastArmedMotion = fibaro:get(motionID, 'armed');
  23. local trigger = fibaro:getSourceTrigger();
  24.  
  25. if (tonumber(trigger['deviceID'])==tonumber(motionID)) then
  26.     if (tonumber(motion)==1 and fibaro:getGlobalValue("Sonnenstand") == "Sonnenuntergang") then
  27.       fibaro:call(lightID, "turnOn");
  28.       fibaro:debug('Motion detected. Light on!');
  29.       fibaro:call(motionID, 'setArmed', '1');
  30.       fibaro:call(motionID, 'setArmed', '0');
  31.     -- no motion anymore
  32.     elseif (tonumber(motion)==0 and (os.time()-lastArmedMotion)>=timeWithOutMotion) then
  33.       fibaro:debug('No motion. Light off!')
  34.       fibaro:call(lightID, "turnOff");
  35.     end
  36.   end
  37.  
  38. if (tonumber(trigger['deviceID'])==tonumber(motionID2)) then
  39.     if (tonumber(motion2)==1 and fibaro:getGlobalValue("Sonnenstand") == "Sonnenuntergang") then
  40.       fibaro:call(lightID, "turnOn");
  41.       fibaro:call(motionID2, 'setArmed', '1');
  42.       fibaro:call(motionID2, 'setArmed', '0');
  43.     -- no motion anymore
  44.     elseif (tonumber(motion)==0 and (os.time()-lastArmedMotion2)>=timeWithOutMotion) then
  45.       fibaro:debug('No motion2. Light off!')
  46.       fibaro:call(lightID, "turnOff");
  47.     end
  48.   end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement