Fronius Solar inverter integration

Hello

I have started to integrate my Fronius solar inverter to Vera edge (UI7).

I have changed the file from user reneboer (http://forum.micasaverde.com/index.php?topic=40611.0)
uploaded it, and created a new device as described in the post.

However, i do not get it to work properly.

  • The device says “it is not configured”
  • I can not see any log (ALTUI) for the device
  • Opening the uploaded xml file in the GUI (apps->develop app->luup files) says that there is a error on line 122 and that seems to be the “&” sign.
  • Testing the actual line of code in random lua test bench works fine.
  • Actual new code that i have changed (reading from the inverter and changed json conversion) working flawlessy.

Any suggestions on how to proceed to get it work?

The fronius API is described here:
http://www.fronius.com/cps/rde/xbcr/SID-A761BF1D-F8F8FEE6/fronius_international/42_0410_2012_318486_snapshot.pdf

The changed xml file is attached.

Well… Changed the request to the server with this line instead excluding the “&” sign that seemed to be the issue in the file. “GetInverterRealtimeData.cgi?Scope=System”

Now the module seems to start at least.

Hi,

The Vera does not like some HTML specific characters in the XML files even when they are within strings. You will have to replace them with the HTML equivalent.

Two typical ones are & and <
& becomes &
< becomes <

Give that a shot.

Note that is you would write the same code in a .lua file, you must use the original characters.

Cheers Rene

Thanks! Yes, changed the syntax and the file looks ok in the Vera viewer. ;D

The files is uploaded, device created, but i do not see anything in the logs. I am very new for the LUA files but as i have understood the file shall depending on day/night update the values automatically (no need for external calls?). The log is not showing anything also when i changed the log level to 10.

The variables for the device are created according to the definition in the file.

Maybe i have misunderstood something fundamental with the vera plugin concept?

Hi,

Try reloading luup and at the same time keep an eye on the log file to see if anything on your device shows. It should at a minimum report that it is starting and the IP address it will be using.

If it still says not configured, make sure the IP attribute in the Advances tab is populated with the IP address of your solar device.

Cheers Rene

Hello

Yes it do seems to start… And now there is something with the decoding that i trying to understand.

03 04/29/17 22:27:49.433 luup_log:308: Fronius: Starting Fronius Device <0x77163520>
50 04/29/17 22:27:49.434 luup_log:308: Fronius: Using Fronius IP address 192.168.1.60 <0x77163520>
50 04/29/17 22:27:49.434 luup_log:308: Fronius: Fronius API URL http://192.168.1.60/solar_api/v1/GetInverterRealtimeData.cgi?Scope=System <0x77163520>
50 04/29/17 22:27:49.434 luup_log:308: Fronius: Fronius: Fronius_Startup completed <0x77163520>
50 04/29/17 22:27:59.790 luup_log:308: Fronius: Retrieve HTTPget Complete… <0x74363520>
50 04/29/17 22:27:59.791 luup_log:308: Fronius: {
01 04/29/17 22:27:59.795 LuaInterface::CallFunction_Timer-5 function Fronius_Retrieve failed [string “…”]:140: attempt to concatenate field ‘?’ (a nil value) <0x74363520>

Should i expect that the raw string (containing the http call undecoded json) shall be visible as plain text in the ssh log?

attempt to concatenate field '?' (a nil value)
Happens all the time. To see more detail on the error, transform the variable into a string first. You can then see if you have a nil, number, table, boolean, etc. eg:
"WattsHour Today --> "..tostring(retData.DAY_ENERGY).."  --> Wh"

However after looking at the Fronius PDF, it looks like you need something like this, noting I haven’t read all 52 pages of the manual: :smiley:

"WattsHour Today --> "..tostring(retData.Data.DAY_ENERGY.Value).."  --> "..retData.Data.DAY_ENERGY.Unit

or perhaps:

"WattsHour Today --> "..tostring(retData.DAY_ENERGY.Value).."  --> "..retData.DAY_ENERGY.Unit

Thanks for all help!

Having trouble to access to integer part of the decoded json string. See the raw data below.

The string part work flawless. @a-lurker… Tried to convert to string but i got this output “table: 0x21c7718” so to me it seems that there is some issue to decode the string.

I read that “For example tables that contain both string keys and an array part cannot be exactly represented by JSON. You can solve this by putting your array data in an explicit subtable.”

Link: “dkjson - dkjson

The code i am trying:
local retData = json.decode(Fronius_Raw,1,nil,nil)
log("Current Power → "…tostring(retData.Body.Data.PAC.Values) …retData.Body.Data.PAC.Unit)

Undecoded response from the inverter:

{
“Head” : {
“RequestArguments” : {
“DataCollection” : “”,
“Scope” : “System”
},
“Status” : {
“Code” : 0,
“Reason” : “”,
“UserMessage” : “”
},
“Timestamp” : “2017-04-30T20:49:09+02:00”
},
“Body” : {
“Data” : {
“PAC” : {
“Unit” : “W”,
“Values” : {
“1” : 0
}
},
“DAY_ENERGY” : {
“Unit” : “Wh”,
“Values” : {
“1” : 11068
}
},
“YEAR_ENERGY” : {
“Unit” : “Wh”,
“Values” : {
“1” : 668142
}
},
“TOTAL_ENERGY” : {
“Unit” : “Wh”,
“Values” : {
“1” : 2321790
}
}
}
}
}

Try this:

 log("Current Power --> "..tostring(retData.Body.Data.PAC.Values[1]) ..retData.Body.Data.PAC.Unit)

And to avoid these problems:

Two typical ones are & and < & becomes &amp; < becomes &lt;

It helps to split the code out into a separate I_*.Lua file Results in a lot more clarity. Refer to any plugin that does this.

Hi.

Really tying to get it to work. However I am now realizing that lua debugging is very time consuming :o In fact i am stuck in with basic json deconding. …

HElloo

Try this: Code: [Select] log("Current Power --> "..tostring(retData.Body.Data.PAC.Values[1]) ..retData.Body.Data.PAC.Unit)
Yes, i fully agree. Result: Nil Value.
And to avoid these problems: Code: [Select] Two typical ones are & and < & becomes & < becomes <
Tried in the original code to implement without using the correct format and when i changed (as suggested) the filed loaded. To get more and better information from the device I changed the request string and this new one do not use these characters. This is the code i am using to request and store the data. [code] log("Using Fronius IP address " .. ipAddress) --EData.URL = "http://" .. ipAddress .. "/solar_api/v1/GetInverterRealtimeData.cgi?Scope=Device&DeviceId=1&DataCollection=CommonInverterData" EData.URL = "http://" .. ipAddress .. "/solar_api/v1/GetInverterRealtimeData.cgi?Scope=System" log("Fronius API URL " .. EData.URL) -- Schedule to start polling in 10 sec luup.call_delay("Fronius_Retrieve",10) log("Fronius: Fronius_Startup completed ") setluupfailure(0, EData.DEVICE) return true end
-- Retrieve data from Fronius
function Fronius_Retrieve()
	local HTTP_Code, Fronius_Raw = luup.inet.wget(EData.URL,5)

	if (HTTP_Code == 0) then
		log("Retrieve HTTPget Complete...")
		log(Fronius_Raw)
		local retData = json.decode(Fronius_Raw,1,nil,nil)
		log("Current Power --> "..tostring(retData.Body.Data.PAC.Values[1]) ..retData.Body.Data.PAC.Unit)

– log(“WattsHour Today → “…tostring(retData.Data.DAY_ENERGY.Values[1]) …” → Wh”)
– log(“WattsHour Year → “…tostring(retData.Data.YEAR_ENERGY.Values[1]) …” → Wh”)
– log(“WattsHour Lifetime → “…retData.Data.TOTAL_ENERGY.Values[1] …” → Wh”)
– Set values in PowerMeter
varSet(“Watts”, retData.Body.Data.PAC.Value)
– varSet(“KWH”, tostring(retData.Data.DAY_ENERGY.Values[1]/1000)/1000)
– varSet(“DayKWH”, tostring(retData.Data.DAY_ENERGY.Values[1]/1000))
– varSet(“YearKWH”, tostring(retData.Data.YEAR_ENERGY.Values[1]/1000))
– varSet(“LifeKWH”, tostring(retData.Data.TOTAL_ENERGY.Values[1]/1000))
– log("Finished Call “…retData.wattsNow…” → “…retData.DAY_ENERGY…” → “…retData.wattHoursSevenDays…” → "…retData.wattHoursLifetime)
– log("Finished Call “…retData.DAY_ENERGY.Value…” → “…retData.Body.Data.YEAR_ENERGY.Value…” → "…retData.wattHoursLifetime)
retData = nil
else
varSet(“Watts”, 0)
varSet(“Today”, 0)
log(“HTTPget failed.”,2)
end[/code]

The result i am getting is as below:

03      05/01/17 6:41:45.553    luup_log:308: Fronius: Starting Fronius Device <0x76b53520>
50      05/01/17 6:41:45.553    luup_log:308: Fronius: Using Fronius IP address 192.168.1.60 <0x76b53520>
50      05/01/17 6:41:45.554    luup_log:308: Fronius: Fronius API URL http://192.168.1.60/solar_api/v1/GetInverterRealtimeData.cgi?Scope=System <0x76b53520>
50      05/01/17 6:41:45.554    luup_log:308: Fronius: Fronius: Fronius_Startup completed  <0x76b53520>
50      05/01/17 6:41:55.850    luup_log:308: Fronius: Retrieve HTTPget Complete... <0x73d53520>
50      05/01/17 6:41:55.851    luup_log:308: Fronius: {
50      05/01/17 6:41:55.855    luup_log:308: Fronius: Current Power --> nilW <0x73d53520>
50      05/01/17 6:41:55.856    luup_log:308: Fronius: Is Day use Day delay Interval Fronius_Retrieve --> 30 <0x73d53520>

To me it looks like that the issue is when i am trying to access and convert the integer and/or decoding the json.

Using the original URL:

luup.log("Current Power --> "..tostring(retData.Body.Data.PAC.Values['1']) ..retData.Body.Data.PAC.Unit) luup.log("Current Power --> "..tostring(retData.Body.Data.YEAR_ENERGY.Values['1']) ..retData.Body.Data.YEAR_ENERGY.Unit)

Yes!!! That was the issue! ;D

The result in the logs looks like this… :slight_smile: Now I will go on and test the rest :slight_smile:

23528 root      1792 S    grep Fronius
03      05/01/17 9:16:41.252    luup_log:308: Fronius: Starting Fronius Device <0x76deb520>
50      05/01/17 9:16:41.253    luup_log:308: Fronius: Using Fronius IP address 192.168.1.60 <0x76deb520>
50      05/01/17 9:16:41.253    luup_log:308: Fronius: Fronius API URL http://192.168.1.60/solar_api/v1/GetInverterRealtimeData.cgi?Scope=System <0x76deb520>
50      05/01/17 9:16:41.254    luup_log:308: Fronius: Fronius: Fronius_Startup completed  <0x76deb520>
50      05/01/17 9:16:51.702    luup_log:308: Fronius: Retrieve HTTPget Complete... <0x73feb520>
50      05/01/17 9:16:51.703    luup_log:308: Fronius: {
50      05/01/17 9:16:51.707    luup_log:308: Fronius: Current Power --> 2157W <0x73feb520>
50      05/01/17 9:16:51.707    luup_log:308: Fronius: WattsHour Today --> 3818Wh <0x73feb520>
50      05/01/17 9:16:51.707    luup_log:308: Fronius: WattsHour Year --> 672074Wh <0x73feb520>
50      05/01/17 9:16:51.707    luup_log:308: Fronius: WattsHour Lifetime --> 2325729Wh <0x73feb520>
50      05/01/17 9:16:51.712    luup_log:308: Fronius: Is Day use Day delay Interval Fronius_Retrieve --> 30 <0x73feb520>
50      05/01/17 9:17:21.772    luup_log:308: Fronius: Retrieve HTTPget Complete... <0x73feb520>
50      05/01/17 9:17:21.772    luup_log:308: Fronius: {
50      05/01/17 9:17:21.775    luup_log:308: Fronius: Current Power --> 2158W <0x73feb520>
50      05/01/17 9:17:21.776    luup_log:308: Fronius: WattsHour Today --> 3833Wh <0x73feb520>
50      05/01/17 9:17:21.776    luup_log:308: Fronius: WattsHour Year --> 672093Wh <0x73feb520>
50      05/01/17 9:17:21.776    luup_log:308: Fronius: WattsHour Lifetime --> 2325750Wh <0x73feb520>
50      05/01/17 9:17:21.780    luup_log:308: Fronius: Is Day use Day delay Interval Fronius_Retrieve --> 30 <0x73feb520>

Good news - have go at splitting the I_FroniusPower1.xml into a I_FroniusPower1.xml and L_FroniusPower1.lua file. Makes all a lot clearer. Make sure everything that is local is declared as local.

Hello
Its 120 days since last post.
Next week I get my new Fronius inverter and are intrested to reuse the latest files into my Vera3.
Does anyone know the latest status about Fronius an Vera and where to find latest JSon and XML-files.

Hi pln,

You can also try this version. I am extending my Enphase plugin to support multiple vendors. I have not tested Fronius but it should work according to their API V1 specification.

[url=https://github.com/reneboer/vera-SolarMeter]https://github.com/reneboer/vera-SolarMeter[/url]

Let me know.

Cheers Rene

[quote=“reneboer”]Hi pln,

You can also try this version. I am extending my Enphase plugin to support multiple vendors. I have not tested Fronius but it should work according to their API V1 specification.

[url=https://github.com/reneboer/vera-SolarMeter]https://github.com/reneboer/vera-SolarMeter[/url]

Let me know.

Cheers Rene[/quote]
Hi Rene. I will test it.
Thanks.

Per

Hi Rene! Thank you ! Would you take a look please at: http://forum.micasaverde.com/index.php/topic,77969.0.html

Hello Rene
I have now installed plugin 9076 Solar Meter 1.0 from app store into my vera3, UI5. I can see it under My apps and its a device created.
But I cannot find the new device in my device list.
When I try to open device in my apps, # 379 Solar Meter, nothing happen.
Log window at top say: “Solar Meter : Configure solar system via Settings.”
So I’m stuck and don’t know how to proceed.
Any suggestions?

[quote=“pln8421, post:18, topic:196097”]Hello Rene
I have now installed plugin 9076 Solar Meter 1.0 from app store into my vera3, UI5. I can see it under My apps and its a device created.
But I cannot find the new device in my device list.
When I try to open device in my apps, # 379 Solar Meter, nothing happen.
Log window at top say: “Solar Meter : Configure solar system via Settings.”
So I’m stuck and don’t know how to proceed.
Any suggestions?[/quote]
Hi I know why it does not work. I made it only for UI7 and ALTUI. I do not have a UI5 Vera anymore. Sorry.

Cheers Rene

Has anyone used UI5 towards Fronius converter?
I’m still on Vera3, have a lot of devices, like the UI and everything works fine.
//Per