Så snart den klipper igen efter laddning så nollas den och räknar samma som aktuell klipptid.
Har skapat Globala variablar för "lawnmowerStarttime" och "lawnmowerCutttime" och ändrat "cutTime till "cutDuration" enligt tidigare inlägg (tror jag ändrade på rätt ställe).
Vad har jag missat?
Code: Select all
--Ändra Username/Password
--Ändra powerDeviceID till ID som gräsklipparen sitter på
--Skapa Global variabel lawnmowerStarttime
local username = "xxxxx"
local password = "xxxxx"
local powerDeviceID = 146
local selfId = fibaro:getSelfId()
local startTime = tonumber(fibaro:getGlobalValue("lawnmowerStarttime"))
if startTime == 0 then
fibaro:setGlobal("lawnmowerStarttime", os.time())
end
function getPowerStatus (currentpower)
if tonumber(currentpower) < 2 then
return "Vilar"
elseif tonumber(currentpower) < 5 then
return "Klipper"
elseif tonumber(currentpower) >= 5 and tonumber(currentpower) < 200 then
return "Laddar"
else
return "retry"
end
end
if fibaro:getValue(selfId,"ui.lblStatus.value") == "Klipper" then
fibaro:call(selfId, "setProperty", "currentIcon", 1005)
elseif
fibaro:getValue(selfId,"ui.lblStatus.value") == "Laddar" then
fibaro:call(selfId, "setProperty", "currentIcon", 1004)
elseif
fibaro:getValue(selfId,"ui.lblStatus.value") == "Vilar" then
fibaro:call(selfId, "setProperty", "currentIcon", 1003)
end
function checkStatus ()
VU = Net.FHttp("127.0.0.1",80);
VU:setBasicAuthentication(username,password);
response ,status, errorCode = VU:GET("/api/devices?id=" .. powerDeviceID);
if errorCode == 0 then
jsonTable = json.decode(response)
local power = jsonTable["properties"].power
fibaro:debug("Energy: " .. power)
local status = getPowerStatus(power)
local oldStatus = fibaro:getValue(selfId,"ui.lblStatus.value")
if status ~= oldStatus then
fibaro:debug("Status changed from: " .. oldStatus .. " to: " .. status)
if oldStatus == "Klipper" then
local cutDuration = os.time() - startTime
local cutTime = tonumber(fibaro:getGlobalValue("lawnmowerCuttime")) + tonumber(cutDuration)
fibaro:setGlobal("lawnmowerCuttime", cutTime)
fibaro:call(selfId,"setProperty", "ui.lblLawnmownCuttime.value","C ".. os.date("%H:%M:%S", cutDuration - 3600))
end
fibaro:call(selfId,"setProperty", "ui.lblStatus.value",status)
fibaro:setGlobal("lawnmowerStarttime", os.time())
startTime = os.time()
fibaro:call(selfId,"setProperty", "ui.lblstartTime.value", "00:00:00")
else
fibaro:call(selfId,"setProperty", "ui.lblstartTime.value",os.date("%H:%M:%S",os.time() - startTime - 3600 ))
if fibaro:getValue(selfId,"ui.lblStatus.value") == "Klipper" then
local cutDuration = os.time() - startTime
--fibaro:debug("cutduration: " .. cutDuration)
local cutTime = tonumber(fibaro:getGlobalValue("lawnmowerCuttime")) + tonumber(cutDuration)
--fibaro:debug("Totalcuttime: " .. cutTime)
--fibaro:debug("Totalcutduration: " ..os.date("%H:%M:%S",cutTime))
fibaro:setGlobal("lawnmowerCuttime", cutTime)
fibaro:call(selfId,"setProperty", "ui.lblLawnmownCuttime.value", os.date("%H:%M:%S", cutDuration - 3600))
end
fibaro:debug("Duration: " .. os.date("%H:%M:%S",os.time() - startTime - 3600 ))
end
end
end
checkStatus()