Fetching and processing SolarEdge JSON data with 2.4

dannybloe
Posts: 1429
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi
Domoticz version:
Location: Ermelo
Contact:

Fetching and processing SolarEdge JSON data with 2.4

Post by dannybloe » Thursday 25 January 2018 17:38

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)
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.

elmortero
Posts: 188
Joined: Sunday 29 November 2015 21:46
Target OS: Raspberry Pi
Domoticz version: 2.3852
Location: Spain
Contact:

Re: Fetching and processing SolarEdge JSON data with 2.4

Post by elmortero » Thursday 25 January 2018 18:26

Thanks!
This will help me convert my current scripts to 2.4(1)

User avatar
McMelloW
Posts: 193
Joined: Monday 20 November 2017 18:01
Target OS: Raspberry Pi
Domoticz version: V3.beta
Location: Harderwijk, NL
Contact:

Re: Fetching and processing SolarEdge JSON data with 2.4

Post by McMelloW » Thursday 25 January 2018 18:43

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
Greetings McMelloW

User avatar
McMelloW
Posts: 193
Joined: Monday 20 November 2017 18:01
Target OS: Raspberry Pi
Domoticz version: V3.beta
Location: Harderwijk, NL
Contact:

Re: Fetching and processing SolarEdge JSON data with 2.4

Post by McMelloW » Friday 26 January 2018 11: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.
Greetings McMelloW

dannybloe
Posts: 1429
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi
Domoticz version:
Location: Ermelo
Contact:

Re: Fetching and processing SolarEdge JSON data with 2.4

Post by dannybloe » Friday 26 January 2018 11:52

You generate quite some power!
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.

User avatar
McMelloW
Posts: 193
Joined: Monday 20 November 2017 18:01
Target OS: Raspberry Pi
Domoticz version: V3.beta
Location: Harderwijk, NL
Contact:

Re: Fetching and processing SolarEdge JSON data with 2.4

Post by McMelloW » Friday 26 January 2018 13:20

dannybloe wrote:
Friday 26 January 2018 11:52
You generate quite some power!
Yeah it is a top day with this cloudy weather :)
Greetings McMelloW

User avatar
McMelloW
Posts: 193
Joined: Monday 20 November 2017 18:01
Target OS: Raspberry Pi
Domoticz version: V3.beta
Location: Harderwijk, NL
Contact:

Re: Fetching and processing SolarEdge JSON data with 2.4

Post by McMelloW » Sunday 28 January 2018 0:16

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
Greetings McMelloW

florisi
Posts: 32
Joined: Saturday 30 July 2016 10:14
Target OS: Raspberry Pi
Domoticz version: v3.8153
Location: Arnhem
Contact:

Re: Fetching and processing SolarEdge JSON data with 2.4

Post by florisi » Saturday 17 February 2018 11:28

McMelloW wrote:
Friday 26 January 2018 11: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?

elmortero
Posts: 188
Joined: Sunday 29 November 2015 21:46
Target OS: Raspberry Pi
Domoticz version: 2.3852
Location: Spain
Contact:

Re: Fetching and processing SolarEdge JSON data with 2.4

Post by elmortero » Saturday 17 February 2018 13:03

[/quote]
Is it possible to get the revenue rounded at two decimals?
[/quote]

You can use the dzVents round function

florisi
Posts: 32
Joined: Saturday 30 July 2016 10:14
Target OS: Raspberry Pi
Domoticz version: v3.8153
Location: Arnhem
Contact:

Re: Fetching and processing SolarEdge JSON data with 2.4

Post by florisi » Saturday 17 February 2018 13:07

I've tried, but can't get it to work

freijn
Posts: 298
Joined: Friday 23 December 2016 17:40
Target OS: Raspberry Pi
Domoticz version:
Location: Netherlands Purmerend
Contact:

Re: Fetching and processing SolarEdge JSON data with 2.4

Post by freijn » Saturday 17 February 2018 14:04

thanks for sharing. will give it a go later this weekend!

User avatar
McMelloW
Posts: 193
Joined: Monday 20 November 2017 18:01
Target OS: Raspberry Pi
Domoticz version: V3.beta
Location: Harderwijk, NL
Contact:

Re: Fetching and processing SolarEdge JSON data with 2.4

Post by McMelloW » Saturday 17 February 2018 15:27

florisi wrote:
Saturday 17 February 2018 11: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.
Greetings McMelloW

florisi
Posts: 32
Joined: Saturday 30 July 2016 10:14
Target OS: Raspberry Pi
Domoticz version: v3.8153
Location: Arnhem
Contact:

Re: Fetching and processing SolarEdge JSON data with 2.4

Post by florisi » Saturday 17 February 2018 15:46

it works.
I did forget the Domoticz.utils part in the code.
thanks

User avatar
McMelloW
Posts: 193
Joined: Monday 20 November 2017 18:01
Target OS: Raspberry Pi
Domoticz version: V3.beta
Location: Harderwijk, NL
Contact:

Re: Fetching and processing SolarEdge JSON data with 2.4

Post by McMelloW » Saturday 17 February 2018 16:06

florisi wrote:
Saturday 17 February 2018 15: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.
Greetings McMelloW

florisi
Posts: 32
Joined: Saturday 30 July 2016 10:14
Target OS: Raspberry Pi
Domoticz version: v3.8153
Location: Arnhem
Contact:

Re: Fetching and processing SolarEdge JSON data with 2.4

Post by florisi » Saturday 10 March 2018 9:21

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?

dannybloe
Posts: 1429
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi
Domoticz version:
Location: Ermelo
Contact:

Re: Fetching and processing SolarEdge JSON data with 2.4

Post by dannybloe » Saturday 10 March 2018 9:32

You need dzVents 2.4. Use the latest beta.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.

florisi
Posts: 32
Joined: Saturday 30 July 2016 10:14
Target OS: Raspberry Pi
Domoticz version: v3.8153
Location: Arnhem
Contact:

Re: Fetching and processing SolarEdge JSON data with 2.4

Post by florisi » Saturday 10 March 2018 9:38

How to update to latest beta?
I'm running Domoticz v3.8153 on a raspberry pi 3

dannybloe
Posts: 1429
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi
Domoticz version:
Location: Ermelo
Contact:

Re: Fetching and processing SolarEdge JSON data with 2.4

Post by dannybloe » Saturday 10 March 2018 9:48

You can download it from the website.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.

florisi
Posts: 32
Joined: Saturday 30 July 2016 10:14
Target OS: Raspberry Pi
Domoticz version: v3.8153
Location: Arnhem
Contact:

Re: Fetching and processing SolarEdge JSON data with 2.4

Post by florisi » Saturday 10 March 2018 10:11

works like a charm

florisi
Posts: 32
Joined: Saturday 30 July 2016 10:14
Target OS: Raspberry Pi
Domoticz version: v3.8153
Location: Arnhem
Contact:

Re: Fetching and processing SolarEdge JSON data with 2.4

Post by florisi » Sunday 11 March 2018 8:36

It stopped yesterday at 14:20, no clue why.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest