-
Notifications
You must be signed in to change notification settings - Fork 5
/
SMA2.plugin.txt
77 lines (73 loc) · 3.07 KB
/
SMA2.plugin.txt
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
///////// <version>1.0.3</version>
///////// SMA2 /////////////
///////// Plugin to extract SMA2 Solar data for Toon ///////////////
///////// By Oepi-Loepi ///////////////
function getSolarData(passWord,userName,apiKey,siteid,urlString,totalValue){
if (debugOutput) console.log("*********SolarPanel Start Step1")
var http = new XMLHttpRequest()
var url = "https://www.sunnyportal.com/Templates/PublicPage.aspx?page=" + apiKey
http.open("GET", url, true);
http.onreadystatechange = function() {
if (http.readyState === 4) {
if (http.status === 200) {
var today2
try{
var resp = http.responseText
var n1 = resp.indexOf("<div class=\"widgetBox\" data-name=\"pvPower\">") + "<div class=\"widgetBox\" data-name=\"pvPower\">".length
var n3 = resp.indexOf("class=\"mainValueAmount\"",n1) + "class=\"mainValueAmount\"".length
var n5 = resp.indexOf("data-value=\"",n3) + "data-value=\"".length
var n7 = resp.indexOf("\"",n5)
currentPower = parseInt(resp.substring(n5,n7))
}
catch (a){}
try{
resp = http.responseText
var n11 = resp.indexOf("energyYieldWidget_energyYieldValue") + "energyYieldWidget_energyYieldValue".length
var n13 = resp.indexOf("mainValueAmount simpleTextFit\">",n11) + "mainValueAmount simpleTextFit\">".length
var n17 = resp.indexOf("</span>",n13)
today2 = parseInt(resp.substring(n13,n17))
}
catch (b){}
try{
resp = http.responseText
var n21 = resp.indexOf("<div class=\"widgetBox\" data-name=\"pvEnergy\">") + "<div class=\"widgetBox\" data-name=\"pvEnergy\">".length
var n23 = resp.indexOf("energyYieldTotalValue\">",n23) + "energyYieldTotalValue\">".length
var n25 = resp.indexOf("</span>",n23)
var total = resp.substring(n23,n25)
}
catch (c){}
try{
//check on comma
if (total.indexOf(",")){
var totalArray = total.split(",")
totalValue = totalArray[0] + "" + totalArray[1]
}
//check on point
if (total.indexOf(".")){
var totalArray = total.split(".")
totalValue = totalArray[0] + "" + totalArray[1]
}
//check on comma
if (!total.indexOf(",") && !total.indexOf(".")){
totalValue = total
}
}
catch (d){}
try{
resp = http.responseText
var n31 = resp.indexOf("<div class=\"widgetBox\" data-name=\"pvEnergy\">") + "<div class=\"widgetBox\" data-name=\"pvEnergy\">".length
var n33 = resp.indexOf("energyYieldTotalUnit\">",n33) + "energyYieldTotalUnit\">".length
var n35 = resp.indexOf("</span>",n33)
var totalUnit = resp.substring(n33,n35)
if (totalUnit === "MWh") {totalValue = totalValue * 1000}
}
catch (e){}
parseReturnData(currentPower,totalValue,today2,0,0,0,0,http.status,"succes")
} else {
if (debugOutput) console.log("*********SolarPanel error: " + http.status)
parseReturnData(0,totalValue,0,0,0,0,0, http.status,"error")
}
}
}
http.send();
}