-
Notifications
You must be signed in to change notification settings - Fork 5
/
SolarEdge-SmartThings.groovy
176 lines (136 loc) · 5.36 KB
/
SolarEdge-SmartThings.groovy
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/**
* Solaredge Solar Energy Monitoring System
*
* Copyright 2017 Andy Zilch based on original code from by Carlos Santiago, Ronald Gouldner, David Tucker
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
* for the specific language governing permissions and limitations under the License.
*
*/
preferences {
section("Enter Configuration data for your Solaredge Inverter") {
input("uri", "text", title: "Solaredge Monitor API URL", description: "https://monitoringapi.solaredge.com", required: false)
input("siteId", "text", title: "Site Id", required: true)
input("apiKey", "text", title: "API Key (get this from your Solar PV installer)", required: true)
}
}
metadata {
definition (name: "Solaredge System", namespace: "zprius", author: "David Tucker") {
capability "Power Meter"
capability "Energy Meter"
capability "Refresh"
attribute "energy_today", "string"
attribute "energy_month", "number"
attribute "energy_year", "number"
attribute "energy_lifetime", "number"
attribute "production_level", "number"
fingerprint deviceId: "Solaredge"
}
simulator {
// TODO: define status and reply messages here
}
tiles {
valueTile("solar", "device.power") {
state("solarPower", label: '${currentValue}\nSolar', unit:"W", backgroundColors: [
[value: 2, color: "#32CD32"],
[value: 1, color: "#000000"],
]
)
}
valueTile("energy_today", "device.energy_today") {
state("energy_today", label: '${currentValue}\nToday', unit:"KWh", backgroundColors: [
[value: 1, color: "#bc2323"],
[value: 2, color: "#d04e00"],
[value: 5, color: "#f1d801"],
[value: 10, color: "#90d2a7"],
[value: 15, color: "#44b621"],
[value: 20, color: "#1e9cbb"],
[value: 25, color: "#153591"]
]
)
}
valueTile("energy_month", "device.energy_month") {
state("energy_month", label: '${currentValue}\nMonth', unit:"KWh", backgroundColors: [
[value: 30, color: "#bc2323"],
[value: 60, color: "#d04e00"],
[value: 150, color: "#f1d801"],
[value: 300, color: "#90d2a7"],
[value: 450, color: "#44b621"],
[value: 600, color: "#1e9cbb"],
[value: 750, color: "#153591"]
]
)
}
valueTile("energy_year", "device.energy_year") {
state("energy_year", label: '${currentValue}\nYear', unit:"MWh")
}
valueTile("energy_lifetime", "device.energy_lifetime") {
state("energy_lifetime", label: '${currentValue}\nLifetime', unit:"MWh")
}
valueTile("productionLevel", "device.production_level") {
state("productionLevel", label: '${currentValue}%\nProduction', unit:"%", backgroundColor: "#0000FF")
}
standardTile("refresh", "device.energy_today", inactiveLabel: false, decoration: "flat") {
state "default", action:"polling.poll", icon:"st.secondary.refresh"
}
main (["solar"])
details(["solar",
// "productionLevel", // TODO coding for production level %
"energy_today", "energy_month", "energy_year", "energy_lifetime","refresh"])
}
}
def installed() {
log.debug "Installing Solaredge Monitoring..."
refresh()
}
def updated() {
log.debug "Updating Solaredge Monitoring..."
refresh()
}
// parse events into attributes
def parse(String description) {
log.debug "Parsing '${description}'"
}
def poll() {
//refresh()
}
def refresh() {
log.debug "Executing 'refresh'"
energyRefresh()
}
def energyRefresh() {
log.debug "Executing 'energyToday'"
def cmd = "${settings.uri}/site/${settings.siteId}/overview?api_key=${settings.apiKey}";
log.debug "Sending request cmd[${cmd}]"
httpGet(cmd) {resp ->
if (resp.data) {
log.debug "${resp.data}"
def currentsolarPower = 0
currentsolarPower = resp.data.overview.currentPower.power
log.debug "currentsolarPower :${currentsolarPower}"
def energyToday = resp.data.overview.lastDayData.energy/1000
log.debug "energyToday :${energyToday}"
log.debug "${resp.data.overview.lastMonthData.energy}"
def energyMonth = resp.data.overview.lastMonthData.energy/1000
log.debug "energyMonth :${energyMonth}"
def energyYear = resp.data.overview.lastYearData.energy/1e6
log.debug "energyYear :${energyYear}"
def energyLifetime = resp.data.overview.lifeTimeData.energy/1e6
log.debug "energyLifetime :${energyLifetime}"
delayBetween(
[sendEvent(name: 'power', value: (currentsolarPower))
,sendEvent(name: 'energy_today', value: (String.format("%5.2f", energyToday)))
,sendEvent(name: 'energy_month', value: (String.format("%5.2f", energyMonth)))
,sendEvent(name: 'energy_year', value: (String.format("%5.2f", energyYear)))
,sendEvent(name: 'energy_lifetime', value: (String.format("%5.2f", energyLifetime)))
]
)
}
}
}