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
#41
Hi,

i have written a full script using the API a few years ago, i will post it later today when having access to my laptop…
Reply
#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
#43
how to get the infomation from this webseite script into the logicmachine virtual groupe adresse?
thanks

http://192.168.0.187/solar_api/v1/GetPow...eData.fcgi

{
"Body" : {
"Data" : {
"Inverters" : {
"1" : {
"Battery_Mode" : "normal",
"DT" : 99,
"E_Day" : 2853.699951171875,
"E_Total" : 2032.1309814453125,
"E_Year" : 137498.703125,
"P" : 172,
"SOC" : 57.400001525878906
}
},
"Site" : {
"BatteryStandby" : false,
"E_Day" : 2853.7000000000003,
"E_Total" : 2032.1310000000001,
"E_Year" : 137498.70000000001,
"Meter_Location" : "grid",
"Mode" : "bidirectional",
"P_Akku" : -705.40000000000009,
"P_Grid" : -0.95999999999999996,
"P_Load" : -171.03999999999999,
"P_PV" : 904.40000000000009,
"rel_Autonomy" : 100,
"rel_SelfConsumption" : 99.441860465116278
},
"Version" : "12"
}
},
"Head" : {
"RequestArguments" : {},
"Status" : {
"Code" : 0,
"Reason" : "",
"UserMessage" : ""
},
"Timestamp" : "2022-02-08T14:09:59+01:00"
}
}
Reply
#44
See Erwin's example in the previous post, it has exactly what you need.
Reply
#45
is ok. maybe you know how the procedere is from ip.fcgi to script.
i do not know but i will find it out
Reply
#46
Hi.

Is it possible to write this if condition in a modbus profile for automatic scale the values dependent on how big it is, for easier reading it? 

Code:
-- Total power ever
r1, r2, r3, r4 = mb:readregisters(509, 4)
if r1 then
  value = r1 * 0x1000000000000 + r2 * 0x100000000 + r3 * 0x10000 + r4
  currentvalue = grp.getvalue('32/1/55')
  if tonumber(currentvalue) ~= value then
    if value > 999999999 then
        units = 'GWh'
          value = value / 1000000000
    elseif value > 999999 then
          units = 'MWh'
          value = value / 1000000
        else
          units = 'KWh'
          value = value / 1000
        end
        value = string.format('%.2f', value) .. units
        grp.checkupdate('32/1/55', value)
  end
end
Reply
#47
You can use profile to read raw values then use a script to convert values to formatted strings. This cannot be done directly in the profile.
Reply
#48
Hello,

I'm trying to create a modbus profile, but I'm having some trouble with scale factor: "address_scale". Without this scale factor, profile is working, but we get wrong values due to "live" multipliersd.

Testing register and his scale factor with the tool "read test", they are working properly. But I do not get response with both together in the profile.

    Holding register: 40293,  uint6--> 2260
    Holding register: 40256 ,  int16--> -2

    Tension on MPTT1: 2260 * 10^-2= 22.6 V; that is correct

I attach my profile, that it is created with map register of post #17.

Any help will be welcome.

Attached Files Thumbnail(s)
           
.json   fronius_230912_inversor.json (Size: 2.62 KB / Downloads: 2)
Reply
#49
All scale registers must be added to the profile. Add "internal": true to scale register definition. Internal scale registers won't be visible in the mapping table, but will be read before reading other data registers.
Reply
#50
Thanks, now it is working.

I attach the profiles in case anyone can use them as a basis.

Regards

Attached Files
.json   fronius_230920_inversor.json (Size: 3.81 KB / Downloads: 12)
.json   fronius_230920_meter.json (Size: 2.33 KB / Downloads: 10)
Reply


Forum Jump: