------------Section 1------------ local output = 1 -- choose number of outlet local spotrebaLimit = 10 -- choose watthour limit [Wh] local timeLimit = 10 -- choose time limit [seconds] local recipient = "my.email@example.com" local subject = "Output takes too much power" ---------End of Section 1--------- -- Global variables: _G.timestamp local spotreba = 0 function shutDown() devices.system.SetOut{output=output, value=false} devices.system.ResetCumulativeConsumption{output=output} end function checkTime() local timeNow = os.time() log("Porovnani casu") if (_G.timestamp == 0 or _G.timestamp == nil) then _G.timestamp = timeNow end if (timeNow - _G.timestamp >= timeLimit) then return true end return false end function powerMeasurement() log("Porovnani spotreby") spotreba = devices.system["output" .. output .. "_cumulatedConsumption"] if spotreba> spotrebaLimit then if checkTime() then shutDown() log("Shutdown") end else _G.timestamp = 0 end end powerMeasurement() log("Script Spotreba Wh started")