Efergy Engage Elite Energy Monitor

I’ve been slowly modifying this but have reached a small format issue.

I am getting the month name with this code:

    def today = new java.util.Date()
    def strDateFormat = "MMMM";
    def sdf = new java.text.SimpleDateFormat(strDateFormat);
    def curMonthName = sdf.format(today)

I have a tile for the device that displays this month’s estimated usage.

valueTile("monthEstCost", "device.monthEstCost", width: 2, height: 1, decoration: "flat") {
		state "default", label: '$curMonthName \'s\nEstimated Cost\n\$${currentValue}'
		}    


I am struggling with getting the Month variable to show in the label. Could someone tell me what i’m doing wrong?
the full device type code is here.
Efergy Engage Device Type Code

This should work but I still haven’t completely wrapped my head around single quote, double quote, slashy, dollar slashy strings…

valueTile("monthEstCost", "device.monthEstCost", width: 2, height: 1, decoration: "flat") {
		state "default", label: '${curMonthName} \'s\nEstimated Cost\n\$${currentValue}'
		}

If that doesn’t work out check the Groovy docs and see where it goes wrong.
http://docs.groovy-lang.org/latest/html/documentation/#all-strings

Thanks Andy,

This just returns ‘null’. I have reviewed the documentation you suggested and can find nothing that relates… This string handling in not very easy to pick up.

Am i just not declaring it properly and the variable is only available inside the method?

Ah, I think you are are running into this problem Changing properties of standardTiles dynamically based on other state variables

Are you willing to share your SmartApp? Looks like you’re doing exactly what I want to do with my Elite.

Thanks!

No problem… It’s just a smart device.
https://github.com/tonesto7/SmartThings/blob/master/DeviceTypes/EfergyEngage.groovy

I am having trouble with this device updating my events says it polled at 7:45 PM but the device says last updated 6:35:04 PM. I tried to add a tile to manually refresh, but my tile is not showing up either.

You will need to use pollster to update every 60 seconds

Pollster

It’s polling every minute now, but still no update. I created a new token and updated preferences and still nothing. I’ve removed the device and added it at least 3 times now to see if creating a new device would help and no luck. Each new device still says 6:35

I put in the website with my token and got this:
{“age”:41694,“last_reading_time”:1440023704000,“reading”:0}

Hello John…

I’m sorry you are having so many issues… I will take a look at this when I get to work in about an hour. I just looked at the activity under mine and it’s not updating every minute and updated last at 11:45pm EST last night.
In the meantime are you seeing any errors in the logs under the web IDE?

I am now able to show valid data by browsing to https://engage.efergy.com/mobile_proxy/getInstant?token='token'

{
age: 3,
last_reading_time: 1440073507000,
reading: 2341
}

Well it seems to be updating every 60 to 120 seconds now so it could have been a couple things:

  1. It’s possible that Efergy was experiencing issues
  2. Maybe it was being throttled from polling (see… https://community.smartthings.com/t/rate-limiting-annoucement/15155/43
  3. There could have been a temporary issue with the ST Platform…

{“age”:70899,“last_reading_time”:1440023704000,“reading”:0}

My logs say null, null I can’t get the screenshot to paste

I tweaked line 159 and haven’t reverted. I can’t remember what I changed it to.

Would you mind sending me all of the device type code in a PM so I can look it over (If you have any static personal info in there please change it to something else.
I want to test your code with my api token and see where the hang up is.

Thanks.

/*

  • Efergy Engage Energy Monitor
  • Copyright 2015 Anthony Santilli
  • 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.

  • V1.0 (June 3, 2015)
  • Initial Working Release

*/
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.

Ok so you changed the ‘getInstant’ to ‘getCurrentValuesSummary’. I suggest that you use the ‘getInstant’ because the values returned are not what the tile is looking for. It also doesn’t provide any more useful info than the ‘getInstant’.

I have made a few changes to clean up the logging and comment the tile colors for easy reference.
github
If this still doesn’t help try using the token assigned to the Android app(It’s in the list of authorized tokens)

Another thing I recommend if it still doesn’t update after loading new code. I suggest you take your token and paste it into the token field on this page. EnergyHive to see if it returns your data.
(EnergyHive is actually the backend provider for Efergy. Your efergy login will also work)

Efergy API Reference Info:
Efergy Engage API Reference - part 1
Efergy Engage API Reference - part 2

I reverted to the version from github, above. This is my log:

708ba15a-f28b-411e-a093-cc8a6dabbc3a 5:42:14 PM: debug result: [day_tariff:[estimate:0], month_budget:0, month_kwh:[previousSum:0], day_co2:[estimate:0], month_tariff:[previousSum:0, estimate:not enough data], month_co2:[previousSum:0], day_kwh:[estimate:0]]
708ba15a-f28b-411e-a093-cc8a6dabbc3a 5:42:13 PM: debug Last Updated: Aug 19, 2015 - 6:35:04 PM
708ba15a-f28b-411e-a093-cc8a6dabbc3a 5:42:13 PM: debug result: [last_reading_time:1440023704000, reading:0, age:83229]
708ba15a-f28b-411e-a093-cc8a6dabbc3a 5:42:13 PM: debug Executing ‘poll’

I am using the android token, where exactly do you want me to paste it?

This is the result from energyhive:

[{“cid”:“PWER”,“data”:[{“1440023704000”:0}],“sid”:“746010”,“units”:“kWm”,“age”:83571},{“cid”:“PWER_GAC”,“data”:[{“1440107267000”:999}],“sid”:“746010”,“units”:null,“age”:8}]

Do you use the Efergy App on your android?
Is the app updating data every 6 seconds?

App works great seems to update fine, the shortest interval I counted was 15 seconds, I cannot verify 6 seconds, it didn’t fluctuate that much