Hey everyone,
I haven't coded for 20+ years but I figured I would give this strange LUA language a go on my new HC2 and see if I can get my fronius inverter working.
With the help of the mountain of code on this forum I was surprised to get basics working in an hour or so. Im a bit stuck so hopefully someone can help with questions.
My plan is to make this a fully functional Fronius VD. Just going to be a bit slow going learning LUA.
Here is the code as it stands.
It basically works and is displaying usage on the icon.
function round(x, n)
n = math.pow(10, n or 0)
x = x * n
if x >= 0 then x = math.floor(x + 0.5) else x = math.ceil(x - 0.5) end
return x / n
end
--SMARTMETER 538d72d9
local smartmeter= Net.FHttp('192.168.0.37');
response,status,errorCode = smartmeter:POST("/solar_api/v1/GetPowerFlowRealtimeData.fcgi", '{"seq":1,"method":"object_list_props_values","arguments":{"oid":"538d72d9"}}')
fibaro:debug(response)
if tonumber(status)==200 then
local fronius = json.decode(response)
usage = fronius.Body.Data.Site.P_Load
grid = fronius.Body.Data.Site.P_Grid
solar = fronius.Body.Data.Site.P_PV
if fronius.Body.Data.Site.P_Load == json.null then
usage = 0
end
if fronius.Body.Data.Site.P_Grid == json.null then
grid = 0
end
if fronius.Body.Data.Site.P_PV == json.null then
solar = 0
end
usage = math.abs(usage)
usage = round(usage,1)
grid = round(grid,1)
solar = round(solar,1)
fibaro:debug(usage)
fibaro:debug(grid)
fibaro:debug(solar)
fibaro:call(24, "setProperty", "ui.usage.value", usage.." kWh")
fibaro:call(24, "setProperty", "ui.grid.value", grid.." kWh")
fibaro:call(24, "setProperty", "ui.solar.value", solar.." kWh")
else
fibaro:debug("error Smart Meter:"..errorCode)
end
fibaro:sleep(60000)
1) If anyone has recommendations on bettering the code.. feel free to post
2) In the post line. I'm not sure what the OID does. Anyone have a link to some good ULA resources that can help with how this function works. I don't actually need to pass any additional values to the fronius. Not sure if im passing rubbish to it for no reason.
3) How do I put a newline after a debug message?
4) So i figured how to make the usage numbers appear in the icon for VD. The main number I get is the houses energy consumption. So how do I push this number into the main Fibaro consumption page so it gets graphed etc.
5) Is it possible to use the values in the VD in scenes in any way? eg When I'm generating a heap of extra power then turn a hue light red.
6) How do I pull the IP address from the Vdevice instead of manually adding it to the script?
7) Is there a way to graph all of this data easily?
Thanks for the help!!
Brom