Advertisement
boomx

Bewegung - Licht - Sonos

Dec 11th, 2015
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.00 KB | None | 0 0
  1. --[[
  2. %% properties
  3. 69 value
  4. %% globals
  5. --]]
  6.  
  7. local motionID = 69
  8. local lightID = 30
  9. local sonosCommander = 73
  10.  
  11. timeWithOutMotion = 120
  12.  
  13. if (tonumber(fibaro:countScenes())>1) then
  14.   fibaro:debug('Kill second scene!')
  15.   fibaro:abort()
  16. end
  17.  
  18. local motion = fibaro:getValue(motionID, 'value')
  19. local armedMotion, lastArmedMotion = fibaro:get(motionID, 'armed')
  20. local trigger = fibaro:getSourceTrigger()
  21.  
  22. if (tonumber(trigger['deviceID'])==tonumber(motionID)) then
  23.     if (tonumber(motion)==1) then
  24.       fibaro:call(sonosCommander, 'pressButton', '1')
  25.       fibaro:call(lightID, 'turnOn');
  26.       fibaro:debug('Motion detected. Light on!');
  27.       fibaro:call(motionID, 'setArmed', '1');
  28.       fibaro:call(motionID, 'setArmed', '0');
  29.     -- no motion anymore
  30.     elseif (tonumber(motion)==0 and (os.time()-lastArmedMotion)>=timeWithOutMotion) then
  31.       fibaro:debug('No motion. Light off!')
  32.       fibaro:call(sonosCommander, 'pressButton', '4')
  33.       fibaro:call(lightID, 'turnOff');
  34.     end
  35.   end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement