Advertisement
Guest User

Untitled

a guest
Jun 10th, 2017
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.24 KB | None | 0 0
  1. --[[
  2. %% properties
  3. 71 value
  4. %% globals
  5. --]]
  6.  
  7. ---------------------------------------------------
  8. --------- Verwendung ------------------------------
  9. --[[
  10. Push-Benachrichtigung wenn die Waschmaschine, der Trockner oder die Spülmaschine fertig ist.
  11. Inklusive Report zur Laufzeit und dem Verbrauch.
  12.  
  13. Es wird benötigt: Fibaro Wallplug
  14.  
  15. --]]
  16.  
  17. ---------------------------------------------------
  18. --------- Schleifenschutz -------------------------
  19.  
  20. if (fibaro:countScenes()>1) then
  21. fibaro:debug('Kill the second scene!');
  22. fibaro:abort();
  23. end
  24.  
  25. ---------------------------------------------------
  26. ------------- Config ------------------------------
  27.  
  28. device = 'Die Waschmaschine'
  29. deviceID = 71
  30. minPower = 3
  31. minIntervals = 5
  32. energyRate = 0.26
  33. currency = 'EUR'
  34. pushDevices = {74,12}
  35. advDebug = true
  36. version = 'v1.0'
  37.  
  38. ---------------------------------------------------
  39. --------- Farbiges Debug --------------------------
  40. function debug( color, message )
  41. fibaro:debug(string.format('<%s style="color:%s;">%s<!--%s-->', "span", color, message, "span"));
  42. end
  43.  
  44. ---------------------------------------------------
  45. ------------- stime -------------------------------
  46. -- Funktion zum Umrechnen von Uhrzeiten in Sekunden seit 0 Uhr
  47. ---------------------------------------------------
  48. function stime(s)
  49. local pattern = "(%d+):(%d+):(%d+)"
  50. local hours, minutes, seconds = string.match(s, pattern)
  51. return (hours*3600)+(minutes*60)+seconds
  52. end
  53.  
  54. ---------------------------------------------------
  55. ------------- secToTime ---------------------------
  56. -- Sekunden in eine Uhrzeit wandeln
  57. ---------------------------------------------------
  58. function secToTime(s)
  59. return string.format("%.2d:%.2d:%.2d", s/(60*60), s/60%60, s%60)
  60. end
  61.  
  62. ---------------------------------------------------
  63. --------- Send Push -------------------------------
  64. function sendPopUp(title)
  65. energyMeasure = fibaro:getValue(deviceID, "energy") - (startMeasure)
  66. energyPrice = energyMeasure * energyRate
  67. duration = ((stime(os.date('%H')..':'..os.date('%M')..':'..os.date('%S'))) - startTime )
  68. duration = secToTime(duration)
  69.  
  70. debug('red','Fertig, sende Push. Verbrauch: '..energyMeasure..' Duration: '..duration)
  71. message = 'Es wurden '..energyMeasure..' KWh ('..energyPrice..' '..currency..') verbraucht und das Programm lief '..duration
  72.  
  73. HomeCenter.PopupService.publish({
  74. title = title,
  75. subtitle = os.date("%I:%M:%S %p | %B %d, %Y"),
  76. contentTitle = device .. ' ist fertig!',
  77. contentBody = message,
  78. type = 'Info'
  79. })
  80.  
  81. if pushDevices then
  82. for j = 1, #pushDevices do
  83. fibaro:call(pushDevices[j], "sendPush", device.." ist fertig. Für Details bitte klicken");
  84. end
  85. end
  86. end
  87.  
  88. ---------------------------------------------------
  89. --------- Timer -----------------------------------
  90. function timer()
  91. power = tonumber(fibaro:getValue(deviceID, "power"))
  92. duration = ((stime(os.date('%H')..':'..os.date('%M')..':'..os.date('%S'))) - startTime )
  93. duration = secToTime(duration)
  94.  
  95. if power < minPower then
  96. counter = counter + 1
  97. debug('green','Verbrauch von '..device..' unter '..minPower..' Watt. Counter: '..counter..'/'..minIntervals..' Laufzeit bisher: '..duration )
  98. else
  99. debug('green',device..' läuft noch. '..power..' Watt Verbrauch. Laufzeit bisher: '..duration)
  100. counter = 0
  101. end
  102. end
  103.  
  104. power = tonumber(fibaro:getValue(deviceID, "power"))
  105. startMeasure = fibaro:getValue(deviceID, "energy")
  106. startTime = stime(os.date('%H')..':'..os.date('%M')..':'..os.date('%S'))
  107.  
  108. counter = 0
  109.  
  110. if tonumber(fibaro:getValue(deviceID, "power")) >4 then
  111. debug("yellow","--- Start Geräteüberwachung, powered by mkshb.de ---")
  112. debug('green',device..' eingeschaltet.')
  113. fibaro:setGlobal("SONOS_MUSIC", "DiskStation/music/Rocki/waschmaschienean.mp3");
  114. fibaro:call(224, "pressButton", "2");
  115. while counter < minIntervals do
  116. fibaro:sleep(60000)
  117. timer()
  118. end
  119. -- Wenn Counter abgelaufen, dann Benachrichtigung
  120. sendPopUp(device)
  121. fibaro:setGlobal("SONOS_MUSIC", "DiskStation/music/Rocki/wfertig.mp3");
  122. fibaro:call(224, "pressButton", "2");
  123. debug("yellow","--- Ende Geräteüberwachung, powered by mkshb.de ---")
  124. fibaro:abort()
  125. else
  126. debug('red',device..' ist momentan ausgeschaltet')
  127. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement