Aeon Home Energy Monitor v2

Where’s the code for scottinpollock’s power failure app? I did a search of the forum, but I didn’t find it. I’d be interested in looking at this as well.

search “power is out” in safety and security

Since Xively accounts are hard to come by these days, I figured I’d post what I’ve come up with for logging to Thingspeak. I found some code in the forums and modified it to work. One gotcha is that Thingspeak only allows one update every 15 seconds PER channel, so if you’re posting more than one variable (i.e. power, energy, etc), you may want to re-work it to combine all the variables into a single update. Also, if you have multiple HEM’s, logging to the same channel at 30 second intervals will cause some not to come in, so I actually have two different version of this, one per each HEM posting to a different channel.

To make this work right, create a Thingspeak account, create a channel and name your field the display name of your device then add .power to it. If you look at the code you can see how to log additional capabilities by creating additional handlers (i.e. .energy). I have a HEMv1, so all I care about is Watts.

/**
 *  Thingspeak Wattage Logger for HEM
 *
 *  Copyright 2015 Brian Wilson
 *
 *  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.
 *
 */
definition(
    name: "Thingspeak Logger v2 - Channel 23835",
    namespace: "bw",
    author: "Brian Wilson",
    description: "Thingspeak Logger",
    category: "My Apps",
    iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
    iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png",
    iconX3Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png")


preferences {
    section("Log devices...") {
        input "power", "capability.powerMeter", title: "Power", required: false, multiple: true
        // input "energy", "capability.energyMeter", title: "Energy", required: false, multiple: true
    }

    section ("ThinkSpeak channel id...") {
        input "channelId", "number", title: "Channel id"
    }

    section ("ThinkSpeak write key...") {
        input "channelKey", "text", title: "Channel key"
    }
}

def installed() {
    initialize()
}

def updated() {
    unsubscribe()
    initialize()
}

def initialize() {
    subscribe(power, "power", handlePowerEvent)
    //subscribe(energy, "energy", handleEnergyEvent)


    updateChannelInfo()
    log.debug state.fieldMap
}

def handleEnergyEvent(evt) {
	logField(evt,"energy") { it.toString() }
}

def handlePowerEvent(evt) {
    logField(evt,"power") { it.toString() }

}

private getFieldMap(channelInfo) {
    def fieldMap = [:]
    channelInfo?.findAll { it.key?.startsWith("field") }.each { fieldMap[it.value?.trim()] = it.key }
    log.debug "Retrieving channel info for ${fieldMap}"
    return fieldMap
}

private updateChannelInfo() {
    log.debug "Retrieving channel info for ${channelId}"

    def url = "http://api.thingspeak.com/channels/${channelId}/feed.json?key=${channelKey}&results=0"
    httpGet(url) {
        response ->
        if (response.status != 200 ) {
            log.debug "ThingSpeak data retrieval failed, status = ${response.status}"
        } else {
            state.channelInfo = response.data?.channel
        }
    }

    state.fieldMap = getFieldMap(state.channelInfo)
}

private logField(evt, field, Closure c) {
    def deviceName = evt.displayName.trim() + '.' + field
    def fieldNum = state.fieldMap[deviceName]
  
    if (!fieldNum) {
        log.debug "Device '${deviceName}' has no field"
        return
    }
    def value = c(evt.value)
    log.debug "Logging to channel ${channelId}, ${fieldNum}, value ${value}"

    def url = "http://api.thingspeak.com/update?key=${channelKey}&${fieldNum}=${value}"
    httpGet(url) { 
        response -> 
        if (response.status != 200 ) {
            log.debug "ThingSpeak logging failed, status = ${response.status}"
        }
    }
}
1 Like

Hi @brianwilson

Do you happen to have more in-depth instructions on setting up your SmartApp with Thingspeak?

These are the steps that I’ve done so far

Thingspeak

  1. Created Thingspeak account
  2. Created a new channel and named it “House.power”…
  3. Wrote down the “Channel ID”
  4. Wrote down the “Write API Key”

Smartthings

  1. Added your SmartApp to “My SmartApps” in the web IDE of smartthings
  2. Created a SmartApp (via smartphone) that had the following items in it.
    a. Device that will send out the power consumption data
    b. “Channel ID” of the channel that I created in Thingspeak
    c. “Write API Key” of the channel that I created in Thingspeak

Currently no data is being displayed. Am I missing a step somewhere? Was I supposed to add something more than “house.power” when I created the channel?

Thanks in advance for the help.

What is your device name in SmartThings? If it’s not “House” then it won’t work.

I wrote some additional docs here; see if this helps: https://github.com/bdwilson/ThingSpeak-Energy-Logger

1 Like

@storageanarchy - I have been enjoying your code for a few months even though it doesn’t work properly on Android. To get the data I want I either look at the activity view where I see all the values or I use Alex’s ActiON-Dashboard where the values are properly displayed. I have very limited programming experience however I’d like to try to fix the Android issue if within my reach… Could you kindly point me in the right direction to do so? You mentioned the issue had something to do with colors - can you elaborate?

Thanks!

You just motivated me to look at this. The first thing I tried fixed the problem. Well, the tiles give you values but not colors. Good enough for me.

In the device code, add “decoration: “flat”” to each valueTile declaration. I also added to the standardTile rows. So the first one looks like this:

// Watts row
		valueTile("powerDisp", "device.powerDisp", decoration: "flat") {
			state (

And so on. You can also comment out the rows of colors definition if you want to remove extra code.

@Dlee - Thank you so much for fixing this issue so quickly!! I made the changes you suggested and I can now see all the values, albeit without colors, on my Android devices.

@storageanarchy - if you integrate @Dlee’s fix in your standard code will it break it on iOS? If not, would you mind adding it?

Thank you both! I look forward to learning more so I can actively contribute but for now I just have to soak up other’s input/contributions!

@aruffell -

Sorry, but @Dlee’s “fix” disables the color display on IOS - a fix that is actually necessary only because ST’s Android implementation screws up the color displays. So, no, I won’t be adding this back into my version.

Instead, we should all be asking ST to fix the Android implementation…

1 Like

@storageanarchy - ST released version 1.7.0 for Android today calling it a major upgrade.

I have noticed a number of good improvements, mainly much faster loading, however I can no longer open the Group that includes your device. All I get is “Sorry, but there was an unexpected error.”. To be sure it was not cause by @Dlee 's fix I reverted back to your stock code but I keep getting the same error whenever I try to access the group that has the device. If I move the device using the online interface to no group the error follows it.

Any suggestions on what I should look at?

It works if you comment out or remove all the tile color to value values code. Same with Nest device type. A better Android app, yes. But still no dynamic value based tile colors on Android.

Please report this to ST support - they obviously broke something!

@Tyler This value tiles value based colors on tiles is broken in a different way now with the release of Android app 1.7x. Has something to do with how the values are passed, formatted, or length, string vs integer, from what I can tell.

This code in SmartWeather Station Tile works fine with Android app 1.7x.

tiles {
		valueTile("temperature", "device.temperature") {
			state "default", label:'${currentValue}°',
				backgroundColors:[
                	[value: 19, color: "#9F8ACD"],
					[value: 31, color: "#153591"],
					[value: 44, color: "#1e9cbb"],
					[value: 59, color: "#90d2a7"],
					[value: 74, color: "#44b621"],
					[value: 84, color: "#f1d801"],
					[value: 95, color: "#d04e00"],
					[value: 96, color: "#bc2323"]
				]
		}
//later in code
    ...send(name: "temperature", value: Math.round(obs.temp_f), unit: "F")

This code in HEMv2 will block your whole Things group from loading in new Android app 1.7x (if you have a color tile as display tile) unless you comment out from backgroundColors:

tiles {
	valueTile("powerDisp", "device.powerDisp") {
		state ("default", label:'${currentValue}', 
           /* backgroundColors:[
				[value: "0 Watts", color: "#153591"],
				[value: "3000 Watts", 	color: "#1e9cbb"],
				[value: "6000 Watts", 	color: "#90d2a7"],
				[value: "9000 Watts", 	color: "#44b621"],
				[value: "12000 Watts", color: "#f1d801"],
				[value: "15000 Watts", color: "#d04e00"], 
				[value: "18000 Watts", color: "#bc2323"]
			]*/
		)
	}
//later in code
    ... sendEvent(name: "powerDisp", value: dispValue as String, unit: "", descriptionText: "Display Power: ${newValue} Watts")

Did anyone ever develop code for L1/L2 Watts, Amps, kWh?

Edit: added screen grab, the ide has L1/L2 but the SmartThings app only shows totals (L1+L2) with min and max for energy, power and volts.
Also reset doesn’t reset kWh

Like this…

I’m back to using SANDOOD’s device handler. It is now working again, I think SmartThings blocked it from running on my account. Now that I’ve not used it in years it is working.

Only problem is energydisp does not reset to zero! Any ideas?

I use one called Aeon HEMv2+ by Barry A. Burke. I have modified it slightly but only to make it a bit more basic. I very seldom look at it in the app. I send a reset command on the 28th to the HEM through a smartapp I wrote as that is when my meter is read. In fact it was just reset last night at midnight. It also has a manual reset button that does work.

got it fixed…
need to move the meterReset cmd to before the delayBetween:
credit to terminal NEW: Aeon Home Energy Monitor v2 Device

return zwave.meterV2.meterReset().format()
def cmd = delayBetween([
	zwave.meterV2.meterGet(scale: 0).format(),
	zwave.meterV2.meterGet(scale: 2).format(),
	zwave.meterV2.meterGet(scale: 4).format(),
	zwave.meterV2.meterGet(scale: 5).format()
], 1000)

Oh yeah I had forgotten about that change.