With the new photovoltaic array on the roof, the next logical step is to teach the home automation how much energy is currently available. The SolarEdge inverter comes with a powerful API that I'm integrating into OpenHAB here.

Motivation

I honestly don't need much motivation to integrate new services into home automation. "Because it works" is an excellent rationale.

That said, there are objective reasons to integrate your PV system into your SmartHome. The best thing to do with the electricity from the roof is to consume it (sensibly, of course). If the solar system on the roof delivers enough energy and the storage is full, it makes sense to switch on electricity-intensive consumers NOW and not when you have to buy expensive electricity from the grid. For this, however, you need to know what the current status is.

Our technology

We have a SolarEdge 10K inverter installed in our house. This one provides quite a useful API and also comes with an app that allows you to see the current system status on your smartphone.

Through the API, essentially the same information is readable (I'm guessing heavily, the API exists because SolarEdge provides the app for it) and provides information about current production, home consumption, and whether power is currently being delivered to or drawn from the public grid.

I also found the storage status as an additional API endpoint; however, since our battery has not yet been installed, I will have to supply the information for that.

OpenHAB2 Binding: SolarEdge

OpenHAB has its own binding to connect data from SolarEdge. This can be easily activated via the PaperUI.

As written elsewhere, I prefer to define my Things and Items in configuration files rather than via PaperUI - it is much easier to find them again later and to address them for your own rule set.

First of all, you have to log in via the website https://monitoring.solaredge.com and activate the API. To do this, click on the Admin section, then Plant access and set the checkbox for API access. There you will see your system number and the API key, which you will need when setting up the Thing.

The SolarEdge binding also allows the unofficial use of a private API; but since I like stable APIs, I decided to use the official API.

In /etc/openhab2/things I created a new file: solaredge.things with the following content:

 

solaredge:generic:se10k [ tokenOrApiKey="*****", solarId="19*****", meterInstalled=true, usePrivateApi=false, liveDataPollingInterval=15, aggregateDataPollingInterval=60 ]

 

The polling interval timings are in minutes (not seconds as I originally assumed). The public API allows 300 polls per day; if you want to set the interval much shorter, you'll have to switch to the unofficial private API.

SolarEdge items

To be able to access the corresponding values, we also define the matching items in a new file in /etc/openhab2/items/solaredge.items

 

Number:Power SE10K_Live_Production "PV Production [%.2f %unit%]" {channel="solaredge:generic:se10k:live#production"}
Number:Power SE10K_Live_Consumption "Current consumption [%.2f %unit%]" {channel="solaredge:generic:se10k:live#consumption"}
Number:Dimensionless SE10K_Live_Batterylevel "Battery charge" {channel="solaredge:generic:se10k:live#battery_level"}
Number:Energy SE10K_Day_Production "PV Production [%.1f kWh]" {channel="solaredge:generic:se10k:aggregate_day#production"}
Number:Energy SE10K_Day_Consumption "Electricity Consumption [%.1f kWh]" {channel="solaredge:generic:se10k:aggregate_day#consumption"}
String SE10K_Status "PV Current Status" {channel="solaredge:generic:se10k:live#load_status" }

 

 

Reading out the values

After the definition of the items is finished, it can take a few minutes until the values can be read out. So don't be surprised if you try to create a web overview in the HAB panel and get only ZERO values at the beginning.

In the OpenHAB CLI the items can be read out easily:

 

willmann@raspberrypi:/etc/openhab2/items# openhab-cli console

Logging in as openhab
Password:  

                          __  _____    ____    
  ____  ____  ___  ____  / / / /   |  / __ ) 
 / __ \/ __ \/ _ \/ __ \/ /_/ / /| | / __  | 
/ /_/ / /_/ /  __/ / / / __  / ___ |/ /_/ / 
\____/ .___/\___/_/ /_/_/ /_/_/  |_/_____/     
    /_/                        2.5.5
                               Release Build   

Hit '<tab>' for a list of available commands
and '[cmd] --help' for help on a specific command.
Hit '<ctrl-d>' or type 'system:shutdown' or 'logout' to shutdown openHAB.

openhab> smarthome:status SE10K_Live_Consumption                      
1.37 kW
openhab> smarthome:status SE10K_Live_Production
0.0 kW

 

(I am writing this article in the evening, it is dark outside and therefore the modules on the roof are not producing any power at the moment, so the 0.0 kW is correct)

Of course, Rules can react to these values, e.g. a device can be switched on if the current production is higher than the consumption and the battery storage is charged to at least 75%. Or whatever suits your application best.

And of course it is also possible to create an overview in the OpenHAB panel, which can then be viewed on a tablet or a display in the house at any time.