Lägg till följande LUA kod i knappen:
Code: Select all
function getIcon(watt)
if(watt > 8000) then return 1049
elseif(watt >= 7500) then return 1047
elseif(watt >= 6500) then return 1046
elseif(watt >= 5500) then return 1045
elseif(watt >= 4850) then return 1044
elseif(watt >= 4250) then return 1043
elseif(watt >= 3750) then return 1042
elseif(watt >= 3450) then return 1041
elseif(watt >= 3350) then return 1040
elseif(watt >= 3250) then return 1039
elseif(watt >= 3150) then return 1038
elseif(watt >= 3050) then return 1037
elseif(watt >= 2950) then return 1036
elseif(watt >= 2850) then return 1035
elseif(watt >= 2750) then return 1034
elseif(watt >= 2650) then return 1033
elseif(watt >= 2550) then return 1032
elseif(watt >= 2450) then return 1031
elseif(watt >= 2350) then return 1030
elseif(watt >= 2250) then return 1029
elseif(watt >= 2150) then return 1028
elseif(watt >= 2050) then return 1027
elseif(watt >= 1950) then return 1026
elseif(watt >= 1850) then return 1025
elseif(watt >= 1750) then return 1024
elseif(watt >= 1650) then return 1023
elseif(watt >= 1550) then return 1022
elseif(watt >= 1450) then return 1021
elseif(watt >= 1350) then return 1020
elseif(watt >= 1250) then return 1019
elseif(watt >= 1150) then return 1018
elseif(watt >= 1050) then return 1017
elseif(watt >= 950) then return 1016
elseif(watt >= 850) then return 1015
elseif(watt >= 750) then return 1014
elseif(watt >= 650) then return 1013
elseif(watt >= 550) then return 1012
elseif(watt >= 450) then return 1011
else return 1011 end
end
local time = os.time()
local date = os.date("*t", time)
local year = date.year
local month = date.month
local unixtime = os.time{year=year, month=month, day=01, hour=00, min=00, sec=00}
--fibaro:log(month)
--fibaro:log(unixtime)
thisId = 173
started = os.date("%Y-%m-%d %H:%M:%S")
fibaro:debug("-- ["..started .."] Function Start --")
HC2 = Net.FHttp("192.168.0.61")
rwatt, status, errorCode = HC2:GET("/api/energy/now/now/single/devices/power/17")
rkwhour, status, errorCode = HC2:GET("/api/energy/now-3600/now/single/devices/power/17")
rkwhmonth, status, errorCode = HC2:GET("/api/energy/"..unixtime.."/now/single/devices/power/17")
jsonTable = json.decode(rwatt)
jsonTable = json.decode(rkwhour)
jsonTable2 = json.decode(rkwhmonth)
watt = (jsonTable.W)
kwh = (jsonTable.kWh)
month = (jsonTable2.kWh)
time = os.date("%H:%M:%S");
fibaro:log("Now: "..watt.."W | Last hour: "..kwh.."kWh")
fibaro:call(thisId, "setProperty", "ui.LabelNow.value", watt.." Watt");
fibaro:call(thisId, "setProperty", "ui.LabelHour.value",kwh.." kWh");
fibaro:call(thisId, "setProperty", "ui.LabelMonth.value", month.." kWh");
fibaro:call(thisId, "setProperty", "ui.LabelWhen.value", time);
fibaro:call(thisId, "setProperty", "currentIcon", getIcon(watt));
ended = os.date("%Y-%m-%d %H:%M:%S");
fibaro:debug("-- [".. ended .."] Function Ended --");
fibaro:debug("Error: "..errorCode);
Dessa rader ska ändras:
Code: Select all
HC2 = Net.FHttp("192.168.0.61")
rwatt, status, errorCode = HC2:GET("/api/energy/now/now/single/devices/power/17")
rkwhour, status, errorCode = HC2:GET("/api/energy/now-3600/now/single/devices/power/17")
rkwhmonth, status, errorCode = HC2:GET("/api/energy/"..unixtime.."/now/single/devices/power/17")
Skapa en scen som trycker på knappen Update var xx:min (jag uppdaterar min var 5:e min)
Code: Select all
Du måste byta numret på ikonerna under funktionen getIcon Du hittar id på ikonerna efter uppladdning genom att gå till http://hc2_ip/api/icons