safepay / sensor.fronius

A Fronius Sensor for Home Assistant
MIT License
80 stars 31 forks source link

Support for older Fronius dataloggers #36

Open trdischat opened 3 years ago

trdischat commented 3 years ago

The current sensor.fronius add-on is based on v1 of the Fronius Solar API. I have an older Fronius Datalogger Web that uses v0 of the Fronius Solar API. I was able to make the add-on work with my equipment by changing the URL on line 21 of sensor.py to read:

_INVERTERRT = 'http://{}/solar_api/GetInverterRealtimeData.cgi?Scope={}&DeviceIndex={}&DataCollection=CommonInverterData'

... and line 338 to read:

json_response = await response.json(content_type=None)

That's it. No changes are needed for the PowerFlow or Meter URLs, since neither were supported in v0 of the Solar API, as far as I can tell. I think that the changes to line 338 should work with either API. The reason for the change that I made to line 338 is that v0 of the Solar API returns a valid json response, but incorrectly tags it with a mime type of javascript. Disabling content checking in the json() call fixes the issue.

If we could have a config option to let the end user pick a version of the Solar API (with v1 as a default), then line 21 could select the correct URL format for that version of the API. Alternatively, a call to http://{}/solar_api/GetAPIVersion.cgi will return "1" for v1 of the API and HTTP error 404 for v0 of the API, allowing you to test which version of the API is used by your Fronius device, then use that information to automatically pick the correct URL format.

Copies of the Fronius Solar API documentation are available here: v0 -- https://www.fronius.com/~/downloads/Solar%20Energy/Operating%20Instructions/42%2C0410%2C2011.pdf v1 -- https://www.fronius.com/~/downloads/Solar%20Energy/Operating%20Instructions/42%2C0410%2C2012.pdf