Eventually I came up with this script, I wrote myself.
I use a relay to a smart implant to detect a brownout, the input trigger i use to trigger the scene.
local currentDate = os.date("%H:%M - %d %B %Y")
local seconds = 0;
local UPStime = json.decode(fibaro:getGlobalValue("UPSbattery"))
local mytable = {0, 0}
if (tonumber(fibaro:countScenes()) > 1) then --1
fibaro:abort();
end
if UPStime[1] < 60 then
fibaro:debug("At " ..UPStime[2].. " the UPS was " ..UPStime[1].. " seconds on battery")
else
local minutes = math.floor(UPStime[1] / 60)
local remainingSeconds = UPStime[1] % 60
fibaro:debug("At " ..UPStime[2].. " the UPS was " ..(minutes).. ":" ..(remainingSeconds).. " minutes on battery")
end
if tonumber(fibaro:getValue(455, "value")) > 0 then -- >
fibaro:debug("The UPS is running on battery")
mytable[2] = currentDate
jTable = json.encode(mytable)
fibaro:setGlobal("UPSbattery", jTable);
repeat
fibaro:sleep(10000)
seconds = seconds + 10
mytable[1] = seconds
--fibaro:debug(mytable[1])
-- set global variable
jTable = json.encode(mytable)
fibaro:setGlobal("UPSbattery", jTable);
until (tonumber(fibaro:getValue(455, "value")) == 0 ) -- ==
if seconds < 60 then
fibaro:debug("At " ..(mytable[2]).. " the UPS was " ..(seconds).. " seconds on battery")
else
local minutes = math.floor(seconds / 60)
local remainingSeconds = seconds % 60
fibaro:debug("At " ..(mytable[2]).. " the UPS was " ..(minutes).. ":" ..(remainingSeconds).. " minutes on battery")
end
fibaro:debug("THe Power is been Restored - UPS is running on Mains!")
seconds = 0
mytable = {}
end