Vera - Smarter Home Control Forum

Advanced => Programming => Plugins & Plugin Development => Topic started by: tmorberg on April 19, 2017, 01:51:26 am

Title: Fronius Solar inverter integration
Post by: tmorberg on April 19, 2017, 01:51:26 am
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.
Title: Re: Fronius Solar inverter integration
Post by: tmorberg on April 19, 2017, 02:16:30 pm
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.
Title: Re: Fronius Solar inverter integration
Post by: reneboer on April 20, 2017, 05:16:55 am
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 &amp;
   < becomes &lt;

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
Title: Re: Fronius Solar inverter integration
Post by: tmorberg on April 22, 2017, 02:58:11 pm
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?

Title: Re: Fronius Solar inverter integration
Post by: reneboer on April 24, 2017, 05:05:09 am
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
Title: Re: Fronius Solar inverter integration
Post by: tmorberg on April 29, 2017, 04:34:29 pm
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?
Title: Re: Fronius Solar inverter integration
Post by: a-lurker on April 29, 2017, 05:40:44 pm
Quote
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:

Code: [Select]
"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: :D

Code: [Select]
"WattsHour Today --> "..tostring(retData.Data.DAY_ENERGY.Value).."  --> "..retData.Data.DAY_ENERGY.Unit
or perhaps:

Code: [Select]
"WattsHour Today --> "..tostring(retData.DAY_ENERGY.Value).."  --> "..retData.DAY_ENERGY.Unit



Title: Re: Fronius Solar inverter integration
Post by: tmorberg on April 30, 2017, 03:33:37 pm
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: "http://dkolf.de/src/dkjson-lua.fsl/home"

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
            }
         }
      }
   }
}
Title: Re: Fronius Solar inverter integration
Post by: a-lurker on April 30, 2017, 06:37:28 pm
Try this:
Code: [Select]
log("Current Power --> "..tostring(retData.Body.Data.PAC.Values[1]) ..retData.Body.Data.PAC.Unit)
And to avoid these problems:
Code: [Select]
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.
Title: Re: Fronius Solar inverter integration
Post by: tmorberg on May 01, 2017, 12:48:21 am
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
Quote
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.

Quote
And to avoid these problems:
Code: [Select]
Two typical ones are & and <
   & becomes &amp;
   < becomes &lt;
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: [Select]
log("Using Fronius IP address " .. ipAddress)
--EData.URL = "http://" .. ipAddress .. "/solar_api/v1/GetInverterRealtimeData.cgi?Scope=Device&amp;DeviceId=1&amp;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

The result i am getting is as below:
Code: [Select]
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.
Title: Re: Fronius Solar inverter integration
Post by: a-lurker on May 01, 2017, 02:28:11 am
Using the original URL:

Code: [Select]
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)
Title: Re: Fronius Solar inverter integration
Post by: tmorberg on May 01, 2017, 03:22:17 am
Yes!!! That was the issue!  ;D

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

Code: [Select]
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>
Title: Re: Fronius Solar inverter integration
Post by: a-lurker on May 01, 2017, 03:45:16 am
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.
Title: Re: Fronius Solar inverter integration
Post by: pln8421 on April 06, 2018, 02:58:54 pm
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.
Title: Re: Fronius Solar inverter integration
Post by: reneboer on April 07, 2018, 12:32:56 pm
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.

https://github.com/reneboer/vera-SolarMeter (https://github.com/reneboer/vera-SolarMeter)

Let me know.

Cheers Rene
Title: Re: Fronius Solar inverter integration
Post by: pln8421 on April 13, 2018, 12:47:31 am
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.

https://github.com/reneboer/vera-SolarMeter (https://github.com/reneboer/vera-SolarMeter)

Let me know.

Cheers Rene
Hi Rene. I will test it.
Thanks.

Per

Title: Re: Fronius Solar inverter integration
Post by: givapva on April 13, 2018, 12:50:57 pm
Hi Rene! Thank you ! Would you take a look please at: http://forum.micasaverde.com/index.php/topic,77969.0.html
Title: Re: Fronius Solar inverter integration
Post by: pln8421 on April 16, 2018, 02:48:39 pm
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?
Title: Re: Fronius Solar inverter integration
Post by: reneboer on April 16, 2018, 03:07:24 pm
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?
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
Title: Re: Fronius Solar inverter integration
Post by: pln8421 on April 20, 2018, 11:58:56 am
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
Title: Re: Fronius Solar inverter integration
Post by: reneboer on April 23, 2018, 06:58:48 am
Hi,

On UI5 you can add the configuration variables manually and then I think it should work.
The ServiceID to use is; urn:rboer-com:serviceId:SolarMeter1
Variable FA_IPAddress you enter the Fronius IP address
Variable FA_DeviceID the Fronius device ID, a number between 0 and 9.
Variable System the value 6.

Cheers Rene
Title: Re: Fronius Solar inverter integration
Post by: pln8421 on April 25, 2018, 01:56:42 am
Hi Rene,
Thank you for continuing to help me.
Where and how can I add the variables manually? I can see the files in "develop apps" and "luup files" but I cannot edit. Download, edit and upload again?

Best regards, Per
Title: Re: Fronius Solar inverter integration
Post by: reneboer on April 25, 2018, 05:08:18 am
Hi Per,

I honestly do not remember how you can manually add a variable to a device in UI5. It is done with the device, not in develop apps.

I also do not recall is you can type some LUA test code in UI5 (I did not run UI5 for long).
But if you can you can also use these LUA statements:
Code: [Select]
luup.variable_set("urn:rboer-com:serviceId:SolarMeter1", "System", 6, 379)
luup.variable_set("urn:rboer-com:serviceId:SolarMeter1", "FA_IPAddress", "<IP address>", 379)
luup.variable_set("urn:rboer-com:serviceId:SolarMeter1", "FA_DeviceID", <fr dev id>, 379)
Then reload luup and see what happens.

Cheers Rene
Title: Re: Fronius Solar inverter integration
Post by: jswim788 on April 25, 2018, 12:31:29 pm
In UI5 you go to the bottom of the advanced tab for the device to add a variable:

Title: Re: Fronius Solar inverter integration
Post by: reneboer on April 26, 2018, 05:35:56 am
That's it. Thanks. :)
Title: Re: Fronius Solar inverter integration
Post by: pln8421 on April 26, 2018, 11:51:37 am
Hi,
I have added the LUA statements in Startup LUA manually and SolarMeter1 stopped to ask "Configure solar system via Settings"  :)
But I cannot find the device in my device list neither open the device # 379 in the App, nothing is shown.
If I could do see the device it would be possible to open it and add variables at bottom in the device.
//Per
Title: Re: Fronius Solar inverter integration
Post by: reneboer on April 30, 2018, 07:16:00 am
Hi Per,

I fear there are more things UI5 needs to have that UI7 does different. It has been a long time since I looked at those and as said I do not have a box to test with anymore. Not sure if you can compare with other plugins and test it with trail and error. Else I am sorry it does not work for you.

Cheers Rene