-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCheckMissingPowerMeterReport.lua
More file actions
37 lines (33 loc) · 1.43 KB
/
CheckMissingPowerMeterReport.lua
File metadata and controls
37 lines (33 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
--[[
%% properties
%% weather
%% events
%% globals
--]]
local userId = 0
local warningEmailSubject = ""
local deviceId = 0 -- Set device ID
local warningFlagVariable = ""
local maxSecondsSinceReport = 120
local upperSafeLoadThreshold = 6000
local deviceName = fibaro:getName(deviceId)
local powerMeterValue, modificationTime = fibaro:get(deviceId, "power")
local secondsSinceLastModification = os.time() - modificationTime
fibaro:debug(deviceName .. " load was " .. powerMeterValue .. " W at " .. os.date("%Y-%m-%d %H:%M:%S", modificationTime))
if tonumber(powerMeterValue) > upperSafeLoadThreshold and secondsSinceLastModification > maxSecondsSinceReport then
local warningVariable = fibaro:getGlobal(warningFlagVariable)
local warningIsSent = warningVariable and tonumber(warningVariable) == 1
if not warningIsSent then
fibaro:debug("Sending warning.")
fibaro:call(
userId,
"sendEmail",
warningEmailSubject,
deviceName .. " reported consumption of " .. powerMeterValue .. " W at " .. os.date("%Y-%m-%d %H:%M:%S", modificationTime) .. " and has not reported anything since. It has now been " .. secondsSinceLastModification .. " since last modification. The time is currently " .. os.date("%Y-%m-%d %H:%M:%S", os.time()) .. "."
)
fibaro:setGlobal(warningFlagVariable, 1)
end
else
fibaro:debug("Warning not sent.")
fibaro:setGlobal(warningFlagVariable, 0)
end