This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Fronius inverter JSON integration
#42
Code:
-- Load libs
require('socket.http')
require('json')

-- Set timeout
socket.http.TIMEOUT = 15

-- Get data from API
--data = socket.http.request('http://192.168.1.182/solar_api/v1/GetInverterRealtimeData.cgi?scope=System&collection=CommonInverterData')
--data = socket.http.request('http://192.168.1.182/solar_api/v1/GetInverterRealtimeData.cgi?scope=System&collection=CumulationInverterData')
--data = socket.http.request('http://192.168.1.182/solar_api/v1/GetInverterRealtimeData.cgi?scope=System&collection=3PInverterData')
data = socket.http.request('http://192.168.1.182/solar_api/v1/GetInverterRealtimeData.cgi?scope=System')

if data then
  function sum(t)
    local sum = 0
    for k,v in pairs(t) do
        sum = sum + v
    end
    sum = math.round(sum*0.001,2)
    return sum
    end
  decdata = json.pdecode(data)
  totaldata = decdata.Body.Data.TOTAL_ENERGY.Values
  yeardata = decdata.Body.Data.YEAR_ENERGY.Values
  daydata = decdata.Body.Data.DAY_ENERGY.Values
  currentdata = decdata.Body.Data.PAC.Values
  total = sum(totaldata)
  year = sum(yeardata)
  day = sum(daydata)
  current = sum(currentdata)
  previoustotal = storage.get('froniustotal')
  if previoustotal then
    if total > previoustotal then
      grp.checkupdate('32/1/5',total)
        previoustotal = storage.set('froniustotal', total)
    end
  else
    storage.set('froniustotal', total)
  end
  grp.checkupdate('32/1/6',year)
  grp.checkupdate('32/1/7',day)
  grp.checkupdate('32/1/8',current)
end

I use the storage to check the previous total, as the inverter can go in sleep mode when there is no sun, the API is not sending a valid value at that moment and i dont want to write a invalid value to my trend. So this part is needed if you might see strange values when removing it (:
Reply


Messages In This Thread
RE: Fronius inverter JSON integration - by Erwin van der Zwart - 07.02.2022, 16:29

Forum Jump: