Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- %% properties
- 71 value
- %% globals
- --]]
- ---------------------------------------------------
- --------- Verwendung ------------------------------
- --[[
- Push-Benachrichtigung wenn die Waschmaschine, der Trockner oder die Spülmaschine fertig ist.
- Inklusive Report zur Laufzeit und dem Verbrauch.
- Es wird benötigt: Fibaro Wallplug
- --]]
- ---------------------------------------------------
- --------- Schleifenschutz -------------------------
- if (fibaro:countScenes()>1) then
- fibaro:debug('Kill the second scene!');
- fibaro:abort();
- end
- ---------------------------------------------------
- ------------- Config ------------------------------
- device = 'Die Waschmaschine'
- deviceID = 71
- minPower = 3
- minIntervals = 5
- energyRate = 0.26
- currency = 'EUR'
- pushDevices = {74,12}
- advDebug = true
- version = 'v1.0'
- ---------------------------------------------------
- --------- Farbiges Debug --------------------------
- function debug( color, message )
- fibaro:debug(string.format('<%s style="color:%s;">%s<!--%s-->', "span", color, message, "span"));
- end
- ---------------------------------------------------
- ------------- stime -------------------------------
- -- Funktion zum Umrechnen von Uhrzeiten in Sekunden seit 0 Uhr
- ---------------------------------------------------
- function stime(s)
- local pattern = "(%d+):(%d+):(%d+)"
- local hours, minutes, seconds = string.match(s, pattern)
- return (hours*3600)+(minutes*60)+seconds
- end
- ---------------------------------------------------
- ------------- secToTime ---------------------------
- -- Sekunden in eine Uhrzeit wandeln
- ---------------------------------------------------
- function secToTime(s)
- return string.format("%.2d:%.2d:%.2d", s/(60*60), s/60%60, s%60)
- end
- ---------------------------------------------------
- --------- Send Push -------------------------------
- function sendPopUp(title)
- energyMeasure = fibaro:getValue(deviceID, "energy") - (startMeasure)
- energyPrice = energyMeasure * energyRate
- duration = ((stime(os.date('%H')..':'..os.date('%M')..':'..os.date('%S'))) - startTime )
- duration = secToTime(duration)
- debug('red','Fertig, sende Push. Verbrauch: '..energyMeasure..' Duration: '..duration)
- message = 'Es wurden '..energyMeasure..' KWh ('..energyPrice..' '..currency..') verbraucht und das Programm lief '..duration
- HomeCenter.PopupService.publish({
- title = title,
- subtitle = os.date("%I:%M:%S %p | %B %d, %Y"),
- contentTitle = device .. ' ist fertig!',
- contentBody = message,
- type = 'Info'
- })
- if pushDevices then
- for j = 1, #pushDevices do
- fibaro:call(pushDevices[j], "sendPush", device.." ist fertig. Für Details bitte klicken");
- end
- end
- end
- ---------------------------------------------------
- --------- Timer -----------------------------------
- function timer()
- power = tonumber(fibaro:getValue(deviceID, "power"))
- duration = ((stime(os.date('%H')..':'..os.date('%M')..':'..os.date('%S'))) - startTime )
- duration = secToTime(duration)
- if power < minPower then
- counter = counter + 1
- debug('green','Verbrauch von '..device..' unter '..minPower..' Watt. Counter: '..counter..'/'..minIntervals..' Laufzeit bisher: '..duration )
- else
- debug('green',device..' läuft noch. '..power..' Watt Verbrauch. Laufzeit bisher: '..duration)
- counter = 0
- end
- end
- power = tonumber(fibaro:getValue(deviceID, "power"))
- startMeasure = fibaro:getValue(deviceID, "energy")
- startTime = stime(os.date('%H')..':'..os.date('%M')..':'..os.date('%S'))
- counter = 0
- if tonumber(fibaro:getValue(deviceID, "power")) >4 then
- debug("yellow","--- Start Geräteüberwachung, powered by mkshb.de ---")
- debug('green',device..' eingeschaltet.')
- fibaro:setGlobal("SONOS_MUSIC", "DiskStation/music/Rocki/waschmaschienean.mp3");
- fibaro:call(224, "pressButton", "2");
- while counter < minIntervals do
- fibaro:sleep(60000)
- timer()
- end
- -- Wenn Counter abgelaufen, dann Benachrichtigung
- sendPopUp(device)
- fibaro:setGlobal("SONOS_MUSIC", "DiskStation/music/Rocki/wfertig.mp3");
- fibaro:call(224, "pressButton", "2");
- debug("yellow","--- Ende Geräteüberwachung, powered by mkshb.de ---")
- fibaro:abort()
- else
- debug('red',device..' ist momentan ausgeschaltet')
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement