Fetching and processing SolarEdge JSON data with 2.4

Moderator: leecollings

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

Fetching and processing SolarEdge JSON data with 2.4

Post 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)
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
elmortero
Posts: 247
Joined: Sunday 29 November 2015 20:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.9639
Location: Spain
Contact:

Re: Fetching and processing SolarEdge JSON data with 2.4

Post by elmortero »

Thanks!
This will help me convert my current scripts to 2.4(1)
User avatar
McMelloW
Posts: 434
Joined: Monday 20 November 2017 17:01
Target OS: Raspberry Pi / ODroid
Domoticz version: V2024.1
Location: Harderwijk, NL
Contact:

Re: Fetching and processing SolarEdge JSON data with 2.4

Post 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
Greetings McMelloW
User avatar
McMelloW
Posts: 434
Joined: Monday 20 November 2017 17:01
Target OS: Raspberry Pi / ODroid
Domoticz version: V2024.1
Location: Harderwijk, NL
Contact:

Re: Fetching and processing SolarEdge JSON data with 2.4

Post 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.
Greetings McMelloW
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Fetching and processing SolarEdge JSON data with 2.4

Post by dannybloe »

You generate quite some power!
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
User avatar
McMelloW
Posts: 434
Joined: Monday 20 November 2017 17:01
Target OS: Raspberry Pi / ODroid
Domoticz version: V2024.1
Location: Harderwijk, NL
Contact:

Re: Fetching and processing SolarEdge JSON data with 2.4

Post 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 :)
Greetings McMelloW
User avatar
McMelloW
Posts: 434
Joined: Monday 20 November 2017 17:01
Target OS: Raspberry Pi / ODroid
Domoticz version: V2024.1
Location: Harderwijk, NL
Contact:

Re: Fetching and processing SolarEdge JSON data with 2.4

Post 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
Greetings McMelloW
florisi
Posts: 78
Joined: Saturday 30 July 2016 10:14
Target OS: Linux
Domoticz version: 2020beta
Location: Arnhem
Contact:

Re: Fetching and processing SolarEdge JSON data with 2.4

Post 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?
elmortero
Posts: 247
Joined: Sunday 29 November 2015 20:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.9639
Location: Spain
Contact:

Re: Fetching and processing SolarEdge JSON data with 2.4

Post by elmortero »

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

You can use the dzVents round function
florisi
Posts: 78
Joined: Saturday 30 July 2016 10:14
Target OS: Linux
Domoticz version: 2020beta
Location: Arnhem
Contact:

Re: Fetching and processing SolarEdge JSON data with 2.4

Post by florisi »

I've tried, but can't get it to work
freijn
Posts: 536
Joined: Friday 23 December 2016 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands Purmerend
Contact:

Re: Fetching and processing SolarEdge JSON data with 2.4

Post by freijn »

thanks for sharing. will give it a go later this weekend!
User avatar
McMelloW
Posts: 434
Joined: Monday 20 November 2017 17:01
Target OS: Raspberry Pi / ODroid
Domoticz version: V2024.1
Location: Harderwijk, NL
Contact:

Re: Fetching and processing SolarEdge JSON data with 2.4

Post 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.
Greetings McMelloW
florisi
Posts: 78
Joined: Saturday 30 July 2016 10:14
Target OS: Linux
Domoticz version: 2020beta
Location: Arnhem
Contact:

Re: Fetching and processing SolarEdge JSON data with 2.4

Post by florisi »

it works.
I did forget the Domoticz.utils part in the code.
thanks
User avatar
McMelloW
Posts: 434
Joined: Monday 20 November 2017 17:01
Target OS: Raspberry Pi / ODroid
Domoticz version: V2024.1
Location: Harderwijk, NL
Contact:

Re: Fetching and processing SolarEdge JSON data with 2.4

Post 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.
Greetings McMelloW
florisi
Posts: 78
Joined: Saturday 30 July 2016 10:14
Target OS: Linux
Domoticz version: 2020beta
Location: Arnhem
Contact:

Re: Fetching and processing SolarEdge JSON data with 2.4

Post 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?
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Fetching and processing SolarEdge JSON data with 2.4

Post by dannybloe »

You need dzVents 2.4. Use the latest beta.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
florisi
Posts: 78
Joined: Saturday 30 July 2016 10:14
Target OS: Linux
Domoticz version: 2020beta
Location: Arnhem
Contact:

Re: Fetching and processing SolarEdge JSON data with 2.4

Post by florisi »

How to update to latest beta?
I'm running Domoticz v3.8153 on a raspberry pi 3
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Fetching and processing SolarEdge JSON data with 2.4

Post by dannybloe »

You can download it from the website.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
florisi
Posts: 78
Joined: Saturday 30 July 2016 10:14
Target OS: Linux
Domoticz version: 2020beta
Location: Arnhem
Contact:

Re: Fetching and processing SolarEdge JSON data with 2.4

Post by florisi »

works like a charm
florisi
Posts: 78
Joined: Saturday 30 July 2016 10:14
Target OS: Linux
Domoticz version: 2020beta
Location: Arnhem
Contact:

Re: Fetching and processing SolarEdge JSON data with 2.4

Post by florisi »

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

Who is online

Users browsing this forum: No registered users and 1 guest