Advertisement
Guest User

Untitled

a guest
Jul 19th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. --[[
  2. %% properties
  3. 151 value
  4. %% globals
  5. --]]
  6. local sensors = {151}
  7. local delay = 120
  8. local debug = false
  9. local LuxSensorID = 153
  10.  
  11. function actionsMotion()
  12. fibaro:debug('Führe Aktionen bei Bewegungserkennung aus')
  13. if (
  14. ( tonumber(fibaro:getValue(LuxSensorID, "value")) <= 1 )
  15. and ( fibaro:getGlobalValue("PresentState") == "Home" )
  16. )
  17. then
  18. fibaro:call(247, "turnOn")
  19. fibaro:call(247, "changeBrightness", 30)
  20. fibaro:debug('Licht WC eingeschaltet')
  21. end
  22.  
  23. end
  24.  
  25.  
  26. function actionsNoMotion()
  27. fibaro:debug('Führe Aktionen nach Ende Bewegung aus')
  28. fibaro:call(247, "turnOff")
  29. fibaro:debug('Licht WC ausgeschaltet!')
  30. end
  31.  
  32. local instances = tonumber(fibaro:countScenes());
  33.  
  34. function getSensorStatus()
  35. for i,n in ipairs(sensors) do
  36. if (tonumber(fibaro:getValue(n, "value")) > 0) then
  37. return 1;
  38. end
  39. end
  40. return 0;
  41. end
  42.  
  43. function getLastBreach()
  44. local breach = 0;
  45. for i,n in ipairs(sensors) do
  46. local nBreach = tonumber(fibaro:getValue(n, "lastBreached"));
  47. if(nBreach > breach) then
  48. breach = nBreach;
  49. end
  50. end
  51. return breach;
  52. end
  53.  
  54. function checkMotion()
  55. lastBreached = getLastBreach();
  56. time = os.time();
  57. if (debug) then fibaro:debug("Zuletzt ausgelöst: Vor "..(time-lastBreached).." Sekunden"); end
  58. if (getSensorStatus() == 1) then
  59. return true;
  60. end
  61.  
  62. if ((time-lastBreached)>=delay) then
  63. return false;
  64. end
  65. return true;
  66. end
  67.  
  68. local lastBreached = getLastBreach()
  69.  
  70. if (fibaro:getSourceTriggerType() == 'property' and getSensorStatus() == 1) then
  71. if (instances > 1) then fibaro:abort(); end
  72. fibaro:debug('Bewegung im Raum erkannt - Starte Timer')
  73. actionsMotion()
  74. while (checkMotion()) do
  75. fibaro:sleep(5000);
  76. end
  77. if (debug) then fibaro:debug("Keine Bewegung mehr erkannt."); end
  78. actionsNoMotion()
  79. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement