Hi, sorry I have not logged in for a while.
here is my code, though sadly im only here because my integration stopped working.
/*
- Wattson Energy Monitor
-
- Copyright 2017 Jon Hope
-
- 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 {
input “token”, “text”, title: “Access Token”, required: true
}
metadata {
definition (name: “Wattson Energy Monitor v2”, namespace: “Jon Hope”, author: “Jon_Hope”) {
capability "Power Meter"
capability "Polling"
capability "Health Check"
capability "Refresh"
capability "Sensor"
capability “Actuator”
attribute "curMonthName", "string"
}
// simulator metadata
simulator {
for (int i = 0; i <= 100; i += 10) {
status “power ${i} Wh”: new physicalgraph.zwave.Zwave().meterV1.meterReport(
scaledMeterValue: i, precision: 3, meterType: 0, scale: 0, size: 4).incomingMessage()
}
}
tiles (scale: 2) {
valueTile(“power”, “device.power”, width:6, height:4)
{
state “device.power”,
label: ‘${currentValue}W’,
icon: “https://cdn4.iconfinder.com/data/icons/environmental-and-ecology/48/environmentalsvg-02-512.png”,
backgroundColors:[
[value: 1, color: “#fff000”],
[value: 200, color: “#fff000”],
[value: 300, color: “#42db13”],
[value: 400, color: “#C3C300”],
[value: 600, color: “#ffce00”],
[value: 800, color: “#FFFB14”],
[value: 1000, color: “#FFA500”],
[value: 1500, color: “#ff7400”],
[value: 2000, color: “#ff5a00”],
[value: 3000, color: “#ff0000”]
]
}
//graph tile goes here
//last reading tile
valueTile("readingUpdated", "device.readingUpdated", width: 4, height: 2, decoration: "flat") {
state "default", label:'Last Reading:\n${currentValue}'
}
//refresh tile
standardTile(
"refresh",
"device.refresh",
inactiveLabel: false,
decoration: "flat",
width: 2,
height: 2) {
state("default",
action:"polling.poll",
icon:"st.secondary.refresh")
}
// end of tiles
}
//end of metadata
}
// handle commands
def poll() {
log.debug "Executing ‘poll’"
getReading()
}
// Get the sensor reading
private getReading() {
def today = new java.util.Date()
def strDateFormat = “MMMM”;
def sdf = new java.text.SimpleDateFormat(strDateFormat);
def curMonthName = sdf.format(today)
def curMonth = device.currentValue(‘monthName’)
def readingClosure = {
response ->
log.debug "result: $response.data"
log.debug "last reading time: $response.data.last_reading_time"
log.debug "reading: $response.data.reading"
log.debug "Current Month: $curMonthName"
sendEvent(name: “power”, value: response.data.reading)
def tf = new java.text.SimpleDateFormat(“MMM d, yyyy - h:mm:ss a”)
tf.setTimeZone(TimeZone.getTimeZone(“Europe/London”))
def readingUpdated = "${tf.format(response.data.last_reading_time)}"
log.debug "Last Updated: $readingUpdated"
sendEvent(name: “readingUpdated”, value: readingUpdated)
sendEvent(name: “curMonthName”, value: curMonth)
}
def params = [
uri: “http://www.energyhive.com”,
path: “/mobile_proxy/getInstant”,
query: [“token”: token],
contentType: ‘application/json’
]
httpGet(params, readingClosure)
}