-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathDOM-DOUBLE2.plugin.txt
More file actions
86 lines (80 loc) · 3.14 KB
/
DOM-DOUBLE2.plugin.txt
File metadata and controls
86 lines (80 loc) · 3.14 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
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
78
79
80
81
82
83
84
85
86
///////// <version>1.0.0</version>
///////// DOM-DOUBLE2 /////////////
///////// Plugin to extract Domoticz (Double) Solar data for Toon ///////////////
///////// By Oepi-Loepi ///////////////
function getSolarData(passWord,userName,apiKey,siteid,urlString,totalValue){
var arraynew = apiKey.split("+")
var firstIDX
var secondIDX
var number
if (arraynew.length == 1){
firstIDX = arraynew[0].trim()
number = 1
}
if (arraynew.length == 2){
firstIDX = arraynew[0].trim()
secondIDX = arraynew[1].trim()
number = 2
}
getStep2(number,firstIDX,secondIDX,urlString,totalValue)
}
function getStep2(number,firstIDX,secondIDX,urlString,totalValue){
if (debugOutput) console.log("*********SolarPanel Start getDomoticzData")
var http = new XMLHttpRequest();
http.open("GET", "http://" + urlString + "/json.htm?type=command¶m=getdevices&rid=" + firstIDX, 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.result[0].Usage)
today2=(parseFloat(JsonObject.result[0].CounterToday))*1000
totalValue= (parseFloat(JsonObject.result[0].Data))*1000
if (number == 1){
parseReturnData(currentPower,totalValue,today2,0,0,0,0,http.status,"succes")
}else{
getStep3(secondIDX,urlString,currentPower,today2,totalValue)
}
}
catch (e){
currentPower = 0
parseReturnData(0,totalValue,todayValue,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();
}
function getStep3(secondIDX,urlString,currentPower,today,totalValue){
if (debugOutput) console.log("*********SolarPanel Start getDomoticzData")
var http = new XMLHttpRequest();
http.open("GET", "http://" + urlString + "/json.htm?type=command¶m=getdevices&rid=" + secondIDX, 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 = currentPower + parseInt(JsonObject.result[0].Usage)
today2= today + ((parseFloat(JsonObject.result[0].CounterToday))*1000)
totalValue= totalValue + ((parseFloat(JsonObject.result[0].Data))*1000)
parseReturnData(currentPower,totalValue,today2,0,0,0,0,http.status,"succes")
}
catch (e){
currentPower = 0
parseReturnData(0,totalValue,todayValue,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();
}