forked from ToonSoftwareCollective/solarpanel-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathENPHASE2.plugin.txt
More file actions
34 lines (33 loc) · 1.45 KB
/
ENPHASE2.plugin.txt
File metadata and controls
34 lines (33 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
///////// <version>1.0.3</version>
///////// ENPHASE2 /////////////
///////// Plugin to extract Enphase Solar data for Toon ///////////////
///////// By Oepi-Loepi ///////////////
function getSolarData(passWord,userName,apiKey,siteid,urlString,totalValue){
if (debugOutput) console.log("*********SolarPanel Start getEnphaseData")
var http = new XMLHttpRequest();
var url = "https://api.enphaseenergy.com/api/v4/systems/" + siteid+ "/summary?key=" + apiKey + "&user_id=" + userName
http.open("GET", url, true)
http.onreadystatechange = function() {
if (http.readyState == XMLHttpRequest.DONE) {
if (http.status === 200 || http.status === 300 || http.status === 302) {
try {
var JsonString = http.responseText
var JsonObject= JSON.parse(JsonString)
var today2
currentPower = parseInt(JsonObject.current_power)
today2 = parseInt(JsonObject.energy_today)
totalValue = parseInt(JsonObject.energy_lifetime)
parseReturnData(currentPower,totalValue,today2,0,0,0,0,http.status,"succes")
}
catch (e){
currentPower = 0
parseReturnData(0,totalValue,0,0,0,0,0, http.status,"error")
}
} else {
if (debugOutput) console.log("*********SolarPanel error: " + http.status)
parseReturnData(0,totalValue,0,0,0,0,0, http.status,"error")
}
}
}
http.send();
}