Page 1 of 2

Fetching and processing SolarEdge JSON data with 2.4

Posted: Thursday 25 January 2018 16:38
by dannybloe
Hi folks,

While developing and testing dzVents 2.4 I used this script to read my SolarEdge solar panels. So instead of using the hardware plugin (which is kind of inefficient if you have multiple converters) I use the new asynchronous http call functionality to fetch some json data from SolarEdge's API and stream the results into two virtual devices:
  • SolarEdge (Electric (Instant/Counter, set to type 'Return', energy read from 'device'))
  • SolarEdge: revenue (Custom, axis label 'Euros').
Assuming you have activated and retrieved your API key and Site ID, this is the code:

Code: Select all

local KEY = 'your api key'
local SITE_ID = 'your site id'

return {
	on = {
		timer = { 'every 5 minutes at daytime' },
		httpResponses = { 'SolarEdge' } -- matches callback string below
	},
	execute = function(domoticz, triggerItem)

		if (triggerItem.isTimer) then
		
			-- get data from SolarEdge
			domoticz.openURL({
				url = 'https://monitoringapi.solaredge.com/site/' .. SITE_ID .. '/overview?api_key=' .. KEY,
				method = 'GET',
				callback = 'SolarEdge'
			})
			
		elseif (triggerItem.isHTTPResponse) then
			
			-- we got data, let's update our devices
			local response = triggerItem

			if (response.ok and response.isJSON) then			
				local lifeTime = response.json.overview.lifeTimeData.energy
				local current = response.json.overview.currentPower.power
				local revenue = response.json.overview.lifeTimeData.revenue
				
				domoticz.devices('SolarEdge').updateElectricity(current, lifeTime)
				domoticz.devices('SolarEdge: revenue').updateCustomSensor(revenue)
			else
				-- oops
				domoticz.log('Error fetching SolarEdge data', domoticz.LOG_ERROR)
				domoticz.log(response.data, domoticz.LOG_ERROR)
			end
		end
	end
}
API docs can be found here (look for Overview p.19 as of this date)

Re: Fetching and processing SolarEdge JSON data with 2.4

Posted: Thursday 25 January 2018 17:26
by elmortero
Thanks!
This will help me convert my current scripts to 2.4(1)

Re: Fetching and processing SolarEdge JSON data with 2.4

Posted: Thursday 25 January 2018 17:43
by McMelloW
Thanks Danny,

Will check this out to see how this works for me.

Actually, I am trying to read my SolarEdge via the local ip and Modbus TCP/LAN according to this document

Re: Fetching and processing SolarEdge JSON data with 2.4

Posted: Friday 26 January 2018 10:49
by McMelloW
@dannybloe

To my surprise the result of the HTTP call is finally put in respone.json .. and not in a temporary file. Very nice. See the picture for the comparison of the hardware (Actueel Vermogen) and your script (SolarEgde)

Image

The hardware don't shows the total produced power, but the total of todays produced power on the second line. Nice example of the new asynchronous http call functionality.

Re: Fetching and processing SolarEdge JSON data with 2.4

Posted: Friday 26 January 2018 10:52
by dannybloe
You generate quite some power!

Re: Fetching and processing SolarEdge JSON data with 2.4

Posted: Friday 26 January 2018 12:20
by McMelloW
dannybloe wrote: Friday 26 January 2018 10:52 You generate quite some power!
Yeah it is a top day with this cloudy weather :)

Re: Fetching and processing SolarEdge JSON data with 2.4

Posted: Saturday 27 January 2018 23:16
by McMelloW
Finally, I have a working solution to get data direct from my SolarEdge The Sunspec-Monitor Although it is a Perl script it works OK. Next step is to get it running every 5 minutes within Domoticz.

It reads the complete registers and this is the output

Code: Select all

INVERTER:
             Model: SolarEdge  SE3500 
  Firmware version: 3.2173
     Serial Number: 73xxxxxx

            Status: SLEEPING

 Power Output (AC):            0 W
  Power Input (DC):            0 W
        Efficiency:         0.00 %
  Total Production:      165.755 kWh
      Voltage (AC):       234.30 V (50.01 Hz)
      Current (AC):         0.00 A
      Voltage (DC):         0.50 V
      Current (DC):         0.00 A
       Temperature:        30.95 C (heatsink)
I think this is more like it, instead of being depended on the SolarEdge website

Re: Fetching and processing SolarEdge JSON data with 2.4

Posted: Saturday 17 February 2018 10:28
by florisi
McMelloW wrote: Friday 26 January 2018 10:49 @dannybloe

To my surprise the result of the HTTP call is finally put in respone.json .. and not in a temporary file. Very nice. See the picture for the comparison of the hardware (Actueel Vermogen) and your script (SolarEgde)

Image

The hardware don't shows the total produced power, but the total of todays produced power on the second line. Nice example of the new asynchronous http call functionality.
Is it possible to get the revenue rounded at two decimals?

Re: Fetching and processing SolarEdge JSON data with 2.4

Posted: Saturday 17 February 2018 12:03
by elmortero
[/quote]
Is it possible to get the revenue rounded at two decimals?
[/quote]

You can use the dzVents round function

Re: Fetching and processing SolarEdge JSON data with 2.4

Posted: Saturday 17 February 2018 12:07
by florisi
I've tried, but can't get it to work

Re: Fetching and processing SolarEdge JSON data with 2.4

Posted: Saturday 17 February 2018 13:04
by freijn
thanks for sharing. will give it a go later this weekend!

Re: Fetching and processing SolarEdge JSON data with 2.4

Posted: Saturday 17 February 2018 14:27
by McMelloW
florisi wrote: Saturday 17 February 2018 10:28 Is it possible to get the revenue rounded at two decimals?
Try this:

Code: Select all

domoticz.devices('SolarEdge: revenue').updateCustomSensor(domoticz.utils.round(revenue,2))
Also look at the dzVents wiki page, that's where I found it.

Re: Fetching and processing SolarEdge JSON data with 2.4

Posted: Saturday 17 February 2018 14:46
by florisi
it works.
I did forget the Domoticz.utils part in the code.
thanks

Re: Fetching and processing SolarEdge JSON data with 2.4

Posted: Saturday 17 February 2018 15:06
by McMelloW
florisi wrote: Saturday 17 February 2018 14:46 it works.
I did forget the Domoticz.utils part in the code.
thanks
Yes, I found it too not easy and clear how to use these attributes and methods. But if you do, then it is simple and it works great.

Re: Fetching and processing SolarEdge JSON data with 2.4

Posted: Saturday 10 March 2018 8:21
by florisi
I've reinstalled Domoticz.
Now I have an error:

Error: dzVents: Error: An error occured when calling event handler SolarEdge
2018-03-10 08:20:01.265 Error: dzVents: Error: ...domoticz/scripts/dzVents/generated_scripts/SolarEdge.lua:11: attempt to index local 'triggerItem' (a nil value)

Any idea how to solve?

Re: Fetching and processing SolarEdge JSON data with 2.4

Posted: Saturday 10 March 2018 8:32
by dannybloe
You need dzVents 2.4. Use the latest beta.

Re: Fetching and processing SolarEdge JSON data with 2.4

Posted: Saturday 10 March 2018 8:38
by florisi
How to update to latest beta?
I'm running Domoticz v3.8153 on a raspberry pi 3

Re: Fetching and processing SolarEdge JSON data with 2.4

Posted: Saturday 10 March 2018 8:48
by dannybloe
You can download it from the website.

Re: Fetching and processing SolarEdge JSON data with 2.4

Posted: Saturday 10 March 2018 9:11
by florisi
works like a charm

Re: Fetching and processing SolarEdge JSON data with 2.4

Posted: Sunday 11 March 2018 7:36
by florisi
It stopped yesterday at 14:20, no clue why.