Solaredge Inverter plugin

Here is my first attempt to monitoring my solar panels with THR.

This plugin does NOT use SolarEdge API, because of its daily limitation of 300 calls. Instead it needs the site ID and a cookie from their monitoring website portal, which you can get with the developer tools of any browser. It starts with “cookieyes-consent=…”.

The plugin generates an html string that uses simple symbols to mimic the energy flow layout chart SE shows on their monitoring website and app. It can be inserted into a WebBrowser component. (see here).

The variables are ready, in case someone wants to make a fancy table with them, instead of a text string.

plugin.Name = "SE";
plugin.OnChangeRequest = onChangeRequest;
plugin.OnConnect = onConnect;
plugin.OnDisconnect = onDisconnect;
plugin.OnPoll = onPoll;
plugin.OnSynchronizeDevices = onSynchronizeDevices;
plugin.PollingInterval = 15000;
plugin.DefaultSettings = { "siteId": "12345678", "cookie": "cookiecontent" };

var http = new HTTPClient();

function onChangeRequest(device, attribute, value) { }

function onConnect() {     console.log(" SE connected"); }

function onDisconnect() {     console.log("SE disconnected"); }

function onPoll() {
    var out = "TEST";
    console.log("SE polling");
    var url = "https://monitoring.solaredge.com/services/powerflow/site/"+plugin.settings["siteId"]+"/latest";	
    var options = { headers: { "Cookie": plugin.settings["cookie"] } };
    var response = http.get(url,options);
    var json = response.data; 	
	var pvpower = json['pv']['currentPower'];
	var pvstatus = json['pv']['status'];
	var loadpower = json['load']['currentPower'];
	var gridpower = json['grid']['currentPower'];
	var storagepower = json['storage']['currentPower'];
	var storagelevel = json['storage']['chargeLevel'];
	var storagestatus = json['storage']['status'];
	var connections = json['connections'];
	var arrowgridload = "";
	var arrowstorageload = "";
	var arrowpvload = "";
	var arrowpvstorage = "";

     connections.forEach(function(key) {
     	var from = key.from;
     	var to = key.to;
     	//console.log('from '+from+' to '+to);
		if ((from == 'Grid') && (to == 'Load')) arrowgridload = '<span style="color: orange;"><b>&Leftarrow;</b></span>'; // orange_left
		else if ((from == 'Load') && (to == 'Grid')) arrowgridload = '<span style="color: green;"><b>&Rightarrow;</b></span>'; // green_right
		else if ((from == 'PV') && (to == 'Load')) arrowpvload = '<span style="color: green;"><b>&Rightarrow;</b></span>'; //green_right
		else if ((from == 'Storage') && (to == 'Load')) arrowstorageload = '<span style="color: green;"><b>&Uparrow;</b></span>'; //green_up
		else if ((from == 'PV') && (to == 'Storage')) arrowpvstorage = '<span style="color: green;"><b>&Downarrow;</b></span>'; // green_down
	});

     out = "&#9728;&#65039; <b>"+pvpower+"</b> <small>kW</small> "+pvstatus+arrowpvstorage+arrowpvload+" &#127968; <b>"+loadpower+"</b> <small>kW</small> "+arrowgridload+" &#128508; <b>"+gridpower+"</b> <small>kW</small> "+"<br>";
     out += "&#128267; "+storagelevel+"% <b>"+storagepower+"</b> <small>kW</small> "+arrowstorageload+storagestatus


    var mainDevice = plugin.Devices["se"];
    mainDevice.status = out;
    //console.log(mainDevice.status);
}

function onSynchronizeDevices() {
    var inverterDevice = new Device();
    inverterDevice.Id = "se";
    inverterDevice.DisplayName = "SE Inverter";
    inverterDevice.Capabilities = [];
    inverterDevice.Attributes = ["status"];
    plugin.Devices[inverterDevice.Id] = inverterDevice;
}