ayasystems / froniusHttp

Fronius http phyton domoticz plugin
GNU General Public License v3.0
5 stars 3 forks source link

In the Domoticz log I get some errors "onMessage" #1

Closed HanSyt closed 10 months ago

HanSyt commented 4 years ago

HI,

I have a fronius TL4.0 inverter with a datalogger unit. I discoverd the messages from the datalogger unit can be retreived with: <IP>/solar_api/GetInverterRealtimeData.cgi?Scope=System So I replaced this line in plugin.py, however I get thes errors:

2020-07-26 21:51:41.949 (Fronius) Good Response received from Solax, Dropping connection. 2020-07-26 21:51:41.949 Error: (Fronius) 'onMessage' failed 'NameError'. 2020-07-26 21:51:41.949 Error: (Fronius) ----> Line 230 in '/home/pi/domoticz/plugins/froniusHttp/plugin.py', function onMessage 2020-07-26 21:51:41.949 Error: (Fronius) ----> Line 165 in '/home/pi/domoticz/plugins/froniusHttp/plugin.py', function onMessage 2020-07-26 21:51:41.949 Error: (Fronius) ----> Line 287 in '/home/pi/domoticz/plugins/froniusHttp/plugin.py', function processResponse

Maybe I need another plugin for python? Or is the data structure incompatible? This is what the datalogger sends to me.

{ "Head" : { "RequestArguments" : { "Scope" : "System" }, "Status" : { "Code" : 0, "Reason" : "", "UserMessage" : "" }, "Timestamp" : "2020-07-26T21:35:18+02:00" }, "Body" : { "Data" : { "PAC" : { "Unit" : "W", "Values" : {} }, "DAY_ENERGY" : { "Unit" : "Wh", "Values" : { "1" : 8139 } }, "YEAR_ENERGY" : { "Unit" : "Wh", "Values" : { "1" : 1687941 } }, "TOTAL_ENERGY" : { "Unit" : "Wh", "Values" : { "1" : 20687944 } } } } }

In DEBUG log I got this (I think maybe this is de Data message that is causing trouble:

2020-07-26 22:07:30.294 (Fronius) ----a>'Content-Type':'text/javascript' 2020-07-26 22:07:30.294 (Fronius) a>'Data':'b'{\n\t"Head" : {\n\t\t"RequestArguments" : {\n\t\t\t"Scope" : "System"\n\t\t},\n\t\t"Status" : {\n\t\t\t"Code" : 0,\n\t\t\t"Reason" : "",\n\t\t\t"UserMessage" : ""\n\t\t},\n\t\t"Timestamp" : "2020-07-26T22:04:31+02:00"\n\t},\n\t"Body" : {\n\t\t"Data" : {\n\t\t\t"PAC" : {\n\t\t\t\t"Unit" : "W",\n\t\t\t\t"Values" : {}\n\t\t\t},\n\t\t\t"DAY_ENERGY" : {\n\t\t\t\t"Unit" : "Wh",\n\t\t\t\t"Values" : {\n\t\t\t\t\t"1" : 8139\n\t\t\t\t}\n\t\t\t},\n\t\t\t"YEAR_ENERGY" : {\n\t\t\t\t"Unit" : "Wh",\n\t\t\t\t"Values" : {\n\t\t\t\t\t"1" : 1687941\n\t\t\t\t}\n\t\t\t},\n\t\t\t"TOTAL_ENERGY" : {\n\t\t\t\t"Unit" : "Wh",\n\t\t\t\t"Values" : {\n\t\t\t\t\t"1" : 20687944\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}'' 2020-07-26 22:07:30.294 (Fronius) Good Response received from Solax, Disconnecting.

gniazdoj commented 3 years ago

Think its because you don't have battery.

HanSyt commented 3 years ago

That could be the problem. However I solved the problem with a bash script. I'm not a python programmer and the code was to complex for me to alter it. So with this idea I wrote a bash script to read the data: So with this idea I wrote a bash script to read the data:

gniazdoj commented 3 years ago

you can try to use latest pull request that support nonhybrid system and give a try

HanSyt commented 3 years ago

The data of the original is not merged with your code, I suggest you correct the readme.MD as well:

git clone https://github.com/ayasystems/froniusHttp.git to git clone https://github.com/gniazdoj/froniusHttp.git

I will try the code tonight.

HanSyt commented 3 years ago

Did try it now, unfortunately no data, used both options:

image

HanSyt commented 3 years ago

Tried DEBUG option: image

gniazdoj commented 3 years ago

My Inverter doesn't find URL from your script (/solar_api/GetInverterRealtimeData.cgi?Scope=System)

Can you drop your output from this URL? http://IP:PORT/solar_api/v1/GetInverterRealtimeData.cgi?Scope=Device&DeviceID=1&DataCollection=CommonInverterData and debug output from Domoticz, what you sent is just errors. Debug will tell more, Select device with no AKU.

you can check different URL in documentation, maybe you have older firmware? https://www.fronius.com/en/photovoltaics/products/all-products/system-monitoring/open-interfaces/fronius-solar-api-json-#75ac040a-dc5d-4bfe-b49b-274216b1f709

HanSyt commented 3 years ago

Problem, I have a different URL: http://192.168.2.12/solar_api/GetInverterRealtimeData.cgi?Scope=System The other V1 URL does not work, this is the output:

image

gniazdoj commented 3 years ago

Look in the Fronius DOC API I've sent you link to for better URL, you should be able to get much more details from your device. to get the script to work please comment all lines that takes/update data that you don't have and change variable URL4 to your need. lines to change are like: URL4 = "/solar_api/GetInverterRealtimeData.cgi?Scope=System" line 367 change condition and remove LEDColor if((self.current==self.URL1 or self.current==self.URL4) and int(self.LEDColor) == 2 ): to if((self.current==self.URL1 or self.current==self.URL4) ):

from:

                self.E_Day    =  str(jsonData['Body']['Data']['DAY_ENERGY']['Value'])
                self.E_Total  =  str(jsonData['Body']['Data']['TOTAL_ENERGY']['Value'])
                self.E_Year   =  str(jsonData['Body']['Data']['YEAR_ENERGY']['Value'])
                try:
                    self.PAC     =  str(jsonData['Body']['Data']['PAC']['Value'])

to:

            self.DAY_ENERGY = str(jsonData['Body']['Data']['DAY_ENERGY']['Values']['1'])
            self.PAC = str(jsonData['Body']['Data']['PAC']['Values']['1'])
            self.TOTAL_ENERGY = str(jsonData['Body']['Data']['TOTAL_ENERGY']['Values']['1'])

as you can see **['Values']['1'])** this string is different in your output.

lines to comments are like: in function: def processResponse(self,httpResp):

                self.UAC      = str(jsonData['Body']['Data']['UAC']['Value'])
                self.UDC      = str(jsonData['Body']['Data']['UDC']['Value'])
                self.IAC      = str(jsonData['Body']['Data']['IAC']['Value'])
                self.IDC      = str(jsonData['Body']['Data']['IDC']['Value'])
                self.FAC      = str(jsonData['Body']['Data']['FAC']['Value']) 

                UpdateDevice("F_UAC",      0, self.UAC+";0")
                UpdateDevice("F_UDC",      0, self.UDC+";0")
                UpdateDevice("F_FAC",      0, self.FAC+";0")
                UpdateDevice("F_IAC",      0, self.IAC+";0")
                UpdateDevice("F_IDC",      0, self.IDC+";0")

You can try to look in URLs: http://IP/solar_api/GetInverterRealtimeData.cgi?Scope=Device&DeviceIndex=0&DataCollection=CommonInverterData http://IP/solar_api/GetInverterRealtimeData.cgi?Scope=Device&DeviceIndex=1&DataCollection=CommonInverterData

ayasystems commented 3 years ago

Good job @gniazdoj

I did this plugin without Fronius inverter so it is not easy fix it on my side...

Thanks for your work....

HanSyt commented 3 years ago

Did do the changes you suggested. However, no data is comming in Domoticz. I will publish the debug data on comment later

The output of the 2 urls: image image

HanSyt commented 3 years ago

The Debug data..

image

gniazdoj commented 3 years ago

Looking on line from time 13:07:20.061 is wrong URL. Variable URL4 should be setup to your second picture, it return exactly data I have on my side so all names should be correct. Back code to one in pull request and select under Hardware Tab Inverter Model: Fronius URL4 = "/solar_api/GetInverterRealtimeData.cgi?Scope=Device&DeviceIndex=1&DataCollection=CommonInverterData"

my debug output for this line looks like this: 2020-11-06 13:16:56.285 (FroniusInverter) a>'Data':'b'{\n "Body" : {\n "Data" : {\n "DAY_ENERGY" : {\n "Unit" : "Wh",\n "Value" : 892.20000000000005\n },\n "DeviceStatus" : {\n "ErrorCode" : 0,\n "LEDColor" : 2,\n "LEDState" : 0,\n "MgmtTimerRemainingTime" : -1,\n "StateToReset" : false,\n "StatusCode" : 7\n },\n "FAC" : {\n "Unit" : "Hz",\n "Value" : 50.009999999999998\n },\n "IAC" : {\n "Unit" : "A",\n "Value" : 0.59999999999999998\n },\n "IDC" : {\n "Unit" : "A",\n "Value" : 0.5\n },\n "PAC" : {\n "Unit" : "W",\n "Value" : 148\n },\n "TOTAL_ENERGY" : {\n "Unit" : "Wh",\n "Value" : 82691.009999999995\n },\n "UAC" : {\n "Unit" : "V",\n "Value" : 241.19999999999999\n },\n "UDC" : {\n "Unit" : "V",\n "Value" : 323.89999999999998\n },\n "YEAR_ENERGY" : {\n "Unit" : "Wh",\n "Value" : 82691.800000000003\n }\n }\n },\n "Head" : {\n "RequestArguments" : {\n "DataCollection" : "CommonInverterData",\n "DeviceClass" : "Inverter",\n "DeviceId" : "1",\n "Scope" : "Device"\n },\n "Status" : {\n "Code" : 0,\n "Reason" : "",\n "UserMessage" : ""\n },\n "Timestamp" : "2020-11-06T13:16:53+01:00"\n }\n}\n''

HanSyt commented 3 years ago

I deleted the plugin and did a fresh clone from the server, changed URL4 from ID to Index image image removed all created devices and restarted

Sadly no values in devices, enclosed a part of the log:

image

gniazdoj commented 3 years ago

can you confirm you have: URL4 = "/solar_api/GetInverterRealtimeData.cgi?Scope=Device&DeviceIndex=1&DataCollection=CommonInverterData" ?

I have feeling you left v1 after /solar_api/.

HanSyt commented 3 years ago

My mistake, corrected it: image

Restarted Domoticz, sadly no values, image

debug image

gniazdoj commented 3 years ago

can you drop the output from lines like: 2020-11-06 13:53:01.308 (FroniusInverter) Good Response received from Solax, Disconnecting. 2020-11-06 13:53:01.309 (FroniusInverter) ErrorCode.processResponse: 0 2020-11-06 13:53:01.309 (FroniusInverter) LEDColor.processResponse: 2 2020-11-06 13:53:01.309 (FroniusInverter) self.LEDColor.processResponse LED Status is: GREEN : 2 2020-11-06 13:53:01.309 (FroniusInverter) onConnect.#self.current: /solar_api/v1/GetInverterRealtimeData.cgi?Scope=Device&DeviceID=1&DataCollection=CommonInverterData 2020-11-06 13:53:01.310 (FroniusInverter) self.PAC.processResponse.URL4 : 124 2020-11-06 13:53:01.310 (FroniusInverter) self.E_Day.processResponse.URL4 : 962.5

maybe set URL1, URL2, URL4 to same value.

Can you validate IP address please? on one picture I can see 192.168.2.8 in Domoticz Hardware, and other picture with proper data was returned with IP: 192.168.2.12

HanSyt commented 3 years ago

Changing all URL's to non V1 urls did the trick: image

Now it is giving output data to the devices: image

So the problem seems to be solved:)

gniazdoj commented 3 years ago

Good job @gniazdoj

I did this plugin without Fronius inverter so it is not easy fix it on my side...

Thanks for your work....

Your welcome, I love that script. This opens for all different kind of json output you can handle. Think we can pass some parameters to Hardware TAB to cover more Inverters and clarify it works only with 1 phase or "1 phase + AKU" etc. Anyway now we know that API v1, API v2, different phase options are on market requires other URL, This can be easily adjusted by changing few lines of code based on Fronius Documentation. Thanks

HanSyt commented 3 years ago

Thanks for helping out, switched off my bash script and continue with this one (this one has more information like the voltage of the inverters grid connection (I had problems with the inverter switching off at 248 Volt, Fronius NL fixed that.).

HanSyt commented 3 years ago

Guess this one caused the problem? line 163 image

gniazdoj commented 3 years ago

please look in the morning, for me it doesn't start after night, need to find out why, for now you can setup timeout on device but this produce error each 1h or what time you setup or you can add Push button - dummy switch with ON action setup to: http://IP:PORT/json.htm?type=command&param=updatehardware&htype=94&idx=45&name=FroniusInverter&username=&password=&address=FRONIUS_IP&port=&serialport=&Mode1=80&Mode2=Normal&Mode3=Fronius3&Mode4=&Mode5=&Mode6=0&extra=FroniusHttp&enabled=true&datatimeout=0 and Timer setup to start 00:30 After Sunrise or similar.

gniazdoj commented 3 years ago

Guess this one caused the problem? line 163 image

There are some lines I don't understand why there was selection between URL1 and URL2, I just start using one URL and this could be change I think but its my first python script so I'm happy it works at all :)

HanSyt commented 3 years ago

I will check it tomorrow and let you know

HanSyt commented 3 years ago

I have no problem with the plugin starting after the night, yesterday and today it started without problem. However (there is always a but), I noticed that it does not shut down clean at night, last 2 nights it stopped working, stating a 7 Wh delivery all night. This evening I will try to check this command after it stops working: _http://192.168.2.12/solar_api/GetInverterRealtimeData.cgi?Scope=Device&DeviceIndex=1&DataCollection=CommonInverterData_ to find out what data it sends to the plugin, I assume it has something to do with ledcolor=2. My bash version could get data from the datalogger all night (not when you reset it at night time). Keep you informed

gniazdoj commented 3 years ago

I don't have issue when URL2 = URL4 in the morning now. line: if((self.current==self.URL1 or self.current==self.URL4) and int(self.LEDColor) == 2 ): present status of LED Light as GREEN it means for me Inverter works fine, have enough light etc. I have 3 states:

I have idea to create another menu for devices with API v0 and have different URL and maybe inverter works all day/night I will submit another version and you can check how it works for you.

HanSyt commented 3 years ago

My inverter itself does not have a web interface, it is een separate unit called datalogger. However if the unit switches off the output of the datalogger does what you wrote, led status went from 2 to 1. I can't tell you the colour of leds since I do not recognise colours to well. At the same time the web output is slightly smaller:

image

So I guess the reading of the led status is important for the plugin what data is readable.

gniazdoj commented 3 years ago

I have same output when there is no sunlight for some time before Inverter will go into sleep mode. There is much less details and this cause script to generate error message each few seconds. It's why I've added LEDColor condition to avoid that. It will only update values when there is production. I don't know if your device works at night or not. I only guess script should work well, if there is sunlight and will continue to update values, if there is no sunlight it will change LEDColor to != 2 this means frequently "not enough sunlight" and skip update part, simply doing nothing.

ajarzyn commented 3 years ago

I read this tread after all.

API detection can be done automatically: by checking API version by /solar_api/GetAPIVersion.cgi according to documentation both of them should have that API available. Simply set proper URL regarding to returned API version.

BR, Jarzyn

ajarzyn commented 10 months ago

@ayasystems I think this issue may be closed.

ayasystems commented 10 months ago

Thanks!!!!