/*
*/
preferences {
input “token”, “text”, title: “Access Token”, required: true
}
metadata {
definition (name: "Efergy Engage Elite Energy Monitor", namespace: "tonesto7", author: "tonesto7") {
capability "Energy Meter"
capability "Power Meter"
capability "Polling"
attribute "curMonthName", "string"
}
// simulator metadata
simulator {
for (int i = 0; i <= 100; i += 10) {
status "energy ${i} kWh": new physicalgraph.zwave.Zwave().meterV1.meterReport(
scaledMeterValue: i, precision: 3, meterType: 0, scale: 0, size: 4).incomingMessage()
}
}
tiles {
valueTile("energy", "device.energy") {
state "default", label: 'Right\nNow\n${currentValue} kWh',
foregroundColors:[
[value: 1, color: "#000000"],
[value: 1000, color: "#ffffff"]
],
foregroundColor: "#000000",
backgroundColors:[
[value: 1, color: "#00cc00"],
[value: 1000, color: "#79b821"],
[value: 1800, color: "#ffa81e"],
[value: 4000, color: "#fb1b42"]
]
}
valueTile("todayUsage", "device.todayUsage") {
state "default", label: 'Today\'s\nUsage\n${currentValue} kW',
foregroundColors:[
[value: 1, color: "#000000"],
[value: 20, color: "#ffffff"]
],
foregroundColor: "#000000",
backgroundColors:[
[value: 0, color: "#153591"],
[value: 10, color: "#ffd500"],
[value: 20, color: "#ffa500"],
[value: 30, color: "#bc2323"]
]
}
valueTile("todayCost", "device.todayCost") {
state "default", label: 'Today\'s\nUsage Cost\n \$${currentValue}',
foregroundColors:[
[value: 1, color: "#000000"],
[value: 3, color: "#ffffff"]
],
foregroundColor: "#000000",
backgroundColors:[
[value: 0, color: "#153591"],
[value: 3, color: "#ffd500"],
[value: 5, color: "#ffa500"],
[value: 7, color: "#bc2323"]
]
}
valueTile("monthUsage", "device.monthUsage") {
state "default", label: 'This\nMonth\'s Use\n${currentValue} kW',
foregroundColors:[
[value: 1, color: "#000000"],
[value: 200, color: "#ffffff"]
],
foregroundColor: "#000000",
backgroundColors:[
[value: 0, color: "#153591"],
[value: 200, color: "#ffd500"],
[value: 400, color: "#ffa500"],
[value: 600, color: "#bc2323"]
]
}
valueTile("monthCost", "device.monthCost") {
state "default", label: 'This\nMonth\'s Cost\n \$${currentValue}',
foregroundColors:[
[value: 1, color: "#000000"],
[value: 100, color: "#ffffff"]
],
foregroundColor: "#000000",
backgroundColors:[
[value: 0, color: "#153591"],
[value: 100, color: "#ffd500"],
[value: 150, color: "#ffa500"],
[value: 200, color: "#bc2323"]
]
}
valueTile("monthEstCost", "device.monthEstCost", width: 2, height: 1, decoration: "flat") {
state "default", label: 'This Month\'s\nEstimated Cost\n\$${currentValue}'
}
valueTile("readingUpdated", "device.readingUpdated", width: 2, height: 1, decoration: "flat") {
state "default", label:'Last Updated:\n${currentValue}'
}
main (["energy"])
details(["energy","todayUsage","todayCost","monthUsage","monthCost","monthEstCost","readingUpdated"])
}
}
// parse events into attributes
def parse(String description) {
log.debug "Parsing '${description}'"
}
// handle commands
def poll() {
log.debug "Executing 'poll'"
getReading()
getEstUsage()
}
// 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: "energy", value: response.data.reading)
def tf = new java.text.SimpleDateFormat("MMM d, yyyy - h:mm:ss a")
tf.setTimeZone(TimeZone.getTimeZone("America/New_York"))
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: "https://engage.efergy.com",
path: "/mobile_proxy/getCurrentValuesSummary",
query: ["token": token],
contentType: 'application/json'
]
httpGet(params, readingClosure)
}
// Get extended energy metrics
private getEstUsage() {
def estUsageClosure = {
response ->
log.debug "result: $response.data"
log.debug "Today's Estimated Usage: $response.data.day_kwh.estimate"
log.debug "Today's Estimated Cost: $response.data.day_tariff.estimate"
log.debug "This Month's Estimated Usage: $response.data.month_kwh.previousSum"
log.debug "This Month's Current Cost: $response.data.month_tariff.previousSum"
log.debug "This Month's Estimated Cost: $response.data.month_tariff.estimate"
sendEvent(name: "todayUsage", value: response.data.day_kwh.estimate)
sendEvent(name: "todayCost", value: response.data.day_tariff.estimate)
sendEvent(name: "monthUsage", value: response.data.month_kwh.previousSum)
sendEvent(name: "monthCost", value: response.data.month_tariff.previousSum)
sendEvent(name: "monthEstCost", value: response.data.month_tariff.estimate)
}
def params = [
uri: "https://engage.efergy.com",
path: "/mobile_proxy/getCurrentValuesSummary",
query: ["token": token],
contentType: 'application/json'
]
httpGet(params, estUsageClosure)
}
It is 166 and 192 that I modified that started giving me the java error. Before that I think the debug just returned [], without the “null” values.