This object is in archive! 

Virtual meters, variables and API's

Theo van den Dolder shared this question 9 years ago
Need Answer

Solor panel data into virtual meter(s) with API's ?


The case:


It would be nice to have my solar panel data in the Zipabox dashboard as meter(s) and available in rules.


I want to make a rule that does a HTTP get every X minutes and store data received from the API in a virtual meter.


Anyone ideas or examples?

---------------------------


The solar panels inverter API:


(API GET:) https://monitoringapi.solaredge.com/site/<id>/overview?api_key=<my-key>;


The (body) output of the API GET:


{

"overview": {

"lastUpdateTime": "2015-01-10 16:40:55",

"lifeTimeData": {

"energy": 1276190,

"revenue": 280.76178

},

"lastYearData": {

"energy": 24999.877

},

"lastMonthData": {

"energy": 24999.877

},

"lastDayData": {

"energy": 500.37598

},

"currentPower": {

"power": 0

}

}

}

Replies (10)

photo
1

Hello Theo,


I am trying to achieve something very similar : having a rule that will get a 3rd party device value (using Json) and putting this value in a Virtual device to get the value on the zipato dashboard.


Did you get an answer or found a way to achieve what you were looking for ?

photo
2

Hello Olivier,


It is still on my wishlist.

photo
photo
1

This can be achieved in two ways, but both require a script running on a separate server/computer. To update devices by using the Zipabox API, you need to set up authentication (cookie with token). The second approach is using virtual device Url. It does not need authentication, but there is a kind of security by obscurity in it, because the url contains two or three generated GUIDs, making it "impossible" to guess. The virtual sensor/meter url will be the easiest approach.

photo
3

I use the following scenario for lots of functionality:


- create a PHP script on my NAS (running a web server)

- this PHP does the http get and parses the json returned

- use the parsed values to set a virtual meter value in zipato using the values parsed from the NAS PHP script


Then on Zipato create a rule that does a http request calling the PHP script via the webserver on my NAS


Works flawlessly all the time. Only issue is when the zipato cloud services are down as virtual meters will not be updated on the zipatile by then.


My2c

photo
2

I too use my NAS for multiple tasks like this. It really broadens the possibillities of things you can do with the Zipabox. I collect gas prices from my closes petrol station, read Netatmo values, control my Chromecast with TTS (still experimental, using PyChromcast), control my Samsung TV and some other stuff. I use Python and PHP in a similar ways as Roland does.

photo
2

An easy alternative to a NAS is running a Google App Script every few minutes to fetch the value and send it to a virtual meter. I use this to get weather data, the state of my Tado thermostat, and the state of my Roomba. Works very nicely.

photo
5

Thanks to the various posts of David, I succeeded in creating a Google App Script that fetches the data from my solar panels, parse it and push it to my virtual meter.

/1p3QNJTAAAAAElFTkSuQmCC


This is the code I am using (tips for cleaner/better coding are welcome!):


function myFunction() {
// perform API call to ZeverCloud
var ZeverCloudJSON = UrlFetchApp.fetch('https://www.zevercloud.com/api/v1/getPlantOverview?key=xXXXXXx');
var data = JSON.parse(ZeverCloudJSON);

//Write ZerverCloud output to variables  
var zpowerunit = (data.Power.unit);
var zpower = (data.Power.value);
var ztoday = (data['E-Today'].value);
var zmonth = (data['E-Month'].value);
var ztotal = (data['E-Total'].value);
var ztotalyield = (data.TotalYield.value);
var zco2 = (data.CO2Avoided.value);

//Ensure Power is always in watts, also when received in kW

  if(zpowerunit == "kW") {var zpowernew = zpower*1000}
  if(zpowerunit == "W") {var zpowernew = zpower} 
  
// log the text that you retrieved
  Logger.log("Raw output Zevercloud API: " + data)
  Logger.log("Power rawapi: " + zpower + " " + zpowerunit)
  Logger.log("Power recalc: "+ zpowernew + " W")
  
var zZeverSolarPower = UrlFetchApp.fetch('https://my.zipato.com/zipato-web/remoting/attribute/set?serial=xXXXXXx&apiKey=xXXXXXx&ep=xXXXXXx&value1=' + zpowernew); 
var zZeverSolarToday = UrlFetchApp.fetch('https://my.zipato.com/zipato-web/remoting/attribute/set?serial=xXXXXXx&apiKey=xXXXXXx&ep=xXXXXXx&value2=' + ztoday); 
var zZeverSolarTotal = UrlFetchApp.fetch('https://my.zipato.com/zipato-web/remoting/attribute/set?serial=xXXXXXx&apiKey=xXXXXXx&ep=xXXXXXx&value3=' + ztotal);
var zZeverSolarTotalYield = UrlFetchApp.fetch('https://my.zipato.com/zipato-web/remoting/attribute/set?serial=xXXXXXx&apiKey=xXXXXXx&ep=xXXXXXx&value4=' + ztotalyield);
var zZeverSolarCO2 = UrlFetchApp.fetch('https://my.zipato.com/zipato-web/remoting/attribute/set?serial=xXXXXXx&apiKey=xXXXXXx&ep=xXXXXXx&value5=' + zco2);
var zZeverSolarCO2 = UrlFetchApp.fetch('https://my.zipato.com/zipato-web/remoting/attribute/set?serial=xXXXXXx&apiKey=xXXXXXx&ep=xXXXXXx&value6=' + zmonth);

}

photo
2

I did some rework:

  • Corrected some typos
  • Introduced a time window for GET/PUT execution between 05:00 and 23:00
  • Changed the Zipato virtual meter URL into a variable for readability and management

Also, I use the Google Apps Script scheduler to run the script every 5 minutes.

FYI this is the log output of the script

[18-02-27 13:12:51:339 CET] {E-Month={unit=kWh, value=187.48}, CO2Avoided={unit=kg, value=414.29}, E-Today={unit=kWh, value=10.8}, TotalYield={unit=€, value=162.11}, E-Total={unit=kWh, value=900.62}, ludt=2018-02-27 13:08:00, Power={unit=kW, value=1.61}, sid=19848}

[18-02-27 13:12:51:340 CET] Power rawapi: 1.61 kW

[18-02-27 13:12:51:340 CET] Power recalc: 1610 W


function myFunction() {

// only execute function between 05:00 and 23:00 hrs 
var date = new Date();  
var hrs = date.getHours();

if ((hrs >= 5) && (hrs <= 23)) {

// get solar inverter data from ZeverCloud API
var ZeverCloudJSON = UrlFetchApp.fetch('https://www.zevercloud.com/api/v1/getPlantOverview?key=xXXXXXXXXx');
var data = JSON.parse(ZeverCloudJSON);

// log Raw API output  
  Logger.log(data)

// convert output of ZerverCloud into variables  
var zpowerunit = (data.Power.unit);
var zpower = (data.Power.value);
var ztoday = (data['E-Today'].value);
var zmonth = (data['E-Month'].value);
var ztotal = (data['E-Total'].value);
var ztotalyield = (data.TotalYield.value);
var zco2 = (data.CO2Avoided.value);

// make sure Power value always in watts
  if(zpowerunit == "kW") {var zpowernew = zpower*1000}
  if(zpowerunit == "W") {var zpowernew = zpower} 
  
// log the data for reviewing unit conversion
  Logger.log("Power rawapi: " + zpower + " " + zpowerunit);
  Logger.log("Power recalc: " + zpowernew + " W")

// set path to Zipato virtual meter; URL as listed in Device manager under Virtual meter > METER > No name
var virtualmeter = ('https://my.zipato.com/zipato-web/remoting/attribute/set?serial=xXXXXXXXXx&apiKey=xXXXXXXXXx&ep=xXXXXXXXXx');

// write solar inverter values from ZeverCloud to Zipabox virtual meter
var zZeverSolarPower = UrlFetchApp.fetch(virtualmeter + '&value1=' + zpowernew); 
var zZeverSolarToday = UrlFetchApp.fetch(virtualmeter + '&value2=' + ztoday); 
var zZeverSolarMonth = UrlFetchApp.fetch(virtualmeter + '&value3=' + zmonth);
var zZeverSolarTotal = UrlFetchApp.fetch(virtualmeter + '&value4=' + ztotal);
var zZeverSolarTotalYield = UrlFetchApp.fetch(virtualmeter + '&value5=' + ztotalyield);
var zZeverSolarCO2 = UrlFetchApp.fetch(virtualmeter + '&value6=' + zco2);

  }
}

photo
2

Very good!!! Thank you for this sample!

photo
photo
1

Fantastic!

photo
1

Nicely Done, thanks for sharing!

photo
1

Sorry for reviving this thread, but I was wondering What I should change in this script to make it work with the solaredge api. I found the api documentation (attached), but I'm not realy a programmer and can't get it to work.

photo
1

Which script? Can you post the script?

photo
photo
1

Gilles' script, posted by him a few posts back.

photo
1

There is a driver written here in Github that might help you convert it to working within Zipato https://github.com/DiedB/SolarPanels/tree/0eb807f55575e40856c89e77e4dcf611a2f0a130

photo
Leave a Comment
 
Attach a file