Adding kwh cost to Aeon Labs Smart Switch

I would like to add a tile to my Aeon Labs Smart Switch to show how much the power is costing me (kwh x price). Similar to the setup on the Aeon Home Energy Monitor v2 Device discussion. I have created new devices and apps for my ST Arduino Shield, but I don’t know where to begin with editing an existing one (basically not knowing where to view the existing code)

Where would I edit an existing app?

Any guidance will be greatly appreciated.

My current look


Device state info

Go into the developer’s IDE -> My Device Types -> New SmartDevice. Name the new device whatever you want because it’s just a dummy place holder for now. Then in the editor, click on Device Type Examples in the upper right corner and find Aeon Home Energy Meter. You can then Overwrite your existing code with the Aeon Home Energy Meter. I would add the cost per kWh as a new input and then have a new tile that displays your new multiplied value (kWh * $/kWh). If you can’t figure out how do it yourself, I’m sure some other community members might be able to write it for you.

Actually, I think you want the source to the Aeon Outlet or the Z-Wave Metering Switch.

You can find out which one for sure by examining the device in the My Devices page of the IDE to find the Type of your device. After you build your custom device, you can replace the current device driver with your new one through the IDE as well (be sure to set a default Cost per kWh in the preferences so that the new one doesn’t crash before you have the chance to define the preference value.)

@NickW Thank you, that was the starting point I was missing.


@storageanarchy Thank you for your work on the Aeon Home Energy Monitor v2 Device discussion, this is what peaked my interest in adding functionality to my existing devices.

After some playing around with the “Z-Wave Metering Switch” device type to add a cost tile, I am at a loss. I was using NEW: Aeon Home Energy Monitor v2 Device from @storageanarchy as a reference to try and add the cost per kwh. I do not get any value populated in the tile. any guidance is greatly appreciated.

Many Thanks.

Here is what I am getting:


We need to see your code in order to provide any real assistance.

My suspicion is that you haven’t defined the Attribute, or you aren’t doing a sendEvent with the name/value pair…

@storageanarchy Thank you for looking it over

metadata {
    // Automatically generated. Make future change here.
    definition (name: "Test Z-Wave Metering Switch", namespace: "", author: "") {
        capability "Energy Meter"
        capability "Actuator"
        capability "Switch"
        capability "Power Meter"
        capability "Polling"
        capability "Refresh"
        capability "Sensor"
        
        attribute "energyCost", "string"  

        command "reset"

        fingerprint inClusters: "0x25,0x32"
    }

    // simulator metadata
    simulator {
        status "on":  "command: 2003, payload: FF"
        status "off": "command: 2003, payload: 00"

        for (int i = 0; i <= 10000; i += 1000) {
            status "power  ${i} W": new physicalgraph.zwave.Zwave().meterV1.meterReport(
                scaledMeterValue: i, precision: 3, meterType: 4, scale: 2, size: 4).incomingMessage()
        }
        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()
        }

        // reply messages
        reply "2001FF,delay 100,2502": "command: 2503, payload: FF"
        reply "200100,delay 100,2502": "command: 2503, payload: 00"

    }
 
    // tile definitions
    tiles {
        standardTile("switch", "device.switch", width: 2, height: 2, canChangeIcon: true) {
            state "on", label: '${name}', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#79b821"
            state "off", label: '${name}', action: "switch.on", icon: "st.switches.switch.off", backgroundColor: "#ffffff"
        }
        valueTile("energyCost", "device.energyCost") {
            state("default", label: '${currentValue}', foregroundColor: "#000000", backgroundColor:"#ffffff")
        }
        valueTile("power", "device.power", decoration: "flat") {
            state "default", label:'${currentValue} W'
        }
        valueTile("energy", "device.energy", decoration: "flat") {
            state "default", label:'${currentValue} kWh'
        }
        standardTile("reset", "device.energy", inactiveLabel: false, decoration: "flat") {
            state "default", label:'reset kWh', action:"reset"
        }
        standardTile("configure", "device.power", inactiveLabel: false, decoration: "flat") {
            state "configure", label:'', action:"configuration.configure", icon:"st.secondary.configure"
        }
        standardTile("refresh", "device.power", inactiveLabel: false, decoration: "flat") {
            state "default", label:'', action:"refresh.refresh", icon:"st.secondary.refresh"
        }

        main (["switch","energyCost"])
        details(["switch","energyCost","power","energy","reset","configure","refresh"])
        }
        preferences {
             input "kWhCost", "string", title: "\$/kWh (0.16)", defaultValue: "0.16" as String
        }
}

def parse(String description) {
    def result = null
    def cmd = zwave.parse(description, [0x20: 1, 0x32: 1])
    if (cmd) {
        result = createEvent(zwaveEvent(cmd))
    }
    return result
}

def zwaveEvent(physicalgraph.zwave.commands.meterv1.MeterReport cmd) {

    def dispValue
    def newValue
    
        if (cmd.scale == 0) {
            newValue = cmd.scaledMeterValue
            if (newValue != state.energyValue) {       //Reference from Aeon_HEMv2.groovy by Barry A. Burke 10-07-2014 "https://github.com/SANdood/Aeon-HEM-v2"
                dispValue = String.format("%5.2f",newValue)+"\nkWh"
                sendEvent(name: "energyDisp", value: dispValue as String, unit: "")
                state.energyValue = newValue
                BigDecimal costDecimal = newValue * ( kWhCost as BigDecimal)
                def costDisplay = String.format("%5.2f",costDecimal)
                sendEvent(name: "energyTwo", value: "Cost\n\$${costDisplay}", unit: "")
                [name: "energy", value: newValue, unit: "kWh"]
            }
        }
    else if (cmd.scale == 1) {
        [name: "energy", value: cmd.scaledMeterValue, unit: "kVAh"]
    }
    else {
        [name: "power", value: Math.round(cmd.scaledMeterValue), unit: "W"]
    }
}

def zwaveEvent(physicalgraph.zwave.commands.basicv1.BasicReport cmd)
{
    [
        name: "switch", value: cmd.value ? "on" : "off", type: "physical"
    ]
}

def zwaveEvent(physicalgraph.zwave.commands.switchbinaryv1.SwitchBinaryReport cmd)
{
    [
        name: "switch", value: cmd.value ? "on" : "off", type: "digital"
    ]
}

def zwaveEvent(physicalgraph.zwave.Command cmd) {
    // Handles all Z-Wave commands we aren't interested in
    [:]
}

def on() {
    delayBetween([
            zwave.basicV1.basicSet(value: 0xFF).format(),
            zwave.switchBinaryV1.switchBinaryGet().format()
    ])
}

def off() {
    delayBetween([
            zwave.basicV1.basicSet(value: 0x00).format(),
            zwave.switchBinaryV1.switchBinaryGet().format()
    ])
}

def poll() {
    delayBetween([
        zwave.switchBinaryV1.switchBinaryGet().format(),
        zwave.meterV2.meterGet(scale: 0).format(),
        zwave.meterV2.meterGet(scale: 2).format()
    ])
}

def refresh() {
    delayBetween([
        zwave.switchBinaryV1.switchBinaryGet().format(),
        zwave.meterV2.meterGet(scale: 0).format(),
        zwave.meterV2.meterGet(scale: 2).format()
    ])
}

def reset() {

    sendEvent(name: "energyCost", value: "Cost\n--", unit: "")
    return [
        zwave.meterV2.meterReset().format(),
        zwave.meterV2.meterGet(scale: 0).format()
    ]
}

def configure() {
    delayBetween([
        zwave.configurationV1.configurationSet(parameterNumber: 101, size: 4, scaledConfigurationValue: 4).format(),       // combined power in watts
        zwave.configurationV1.configurationSet(parameterNumber: 111, size: 4, scaledConfigurationValue:     300).format(), // every 5 min
        zwave.configurationV1.configurationSet(parameterNumber: 102, size: 4, scaledConfigurationValue: 8).format(),   // combined energy in kWh
        zwave.configurationV1.configurationSet(parameterNumber: 112, size: 4, scaledConfigurationValue:     300).format(), // every 5 min
        zwave.configurationV1.configurationSet(parameterNumber: 103, size: 4, scaledConfigurationValue: 0).format(),    // no third report
        zwave.configurationV1.configurationSet(parameterNumber: 113, size: 4, scaledConfigurationValue: 300).format() // every 5 min
    ])
}

Simple: change “energyTwo” to “energyCost”

@storageanarchy Thank you for the second set of eyes. I now see the energy cost being calculated in Device in the developer tool and the Event List seems to show it now but the value is not populated in the tile (still shows - -). The APP log on the phone shows cost is “Cost…”

Are you perhaps using an Android device? If so, I suggest removing the color specifications from the tile and see if it displays correctly for you then. Colors seems to make things wonky on Androids.

@storageanarchy I am using an Android (Samsung Galaxy Note2). As suggested I did comment out the color specification for the energyCost tile and still no value. The 3 SmartThings Arduino projects I have done projects I have done in the past, so far this is the only one eluding me and it is adding a value to an existing device type. :smile:

valueTile("energyCost", "device.energyCost") {  
state("default", label: '${currentValue}')
    //Removed color reference

THANK YOU for all of the advice so far.

Sorry, but I am out of ideas…

Thanks for helping. Next step I will try an Apple device to see if may be only Android related.

The device log on the Android app shows “–” for the cost value but the ST IDE displays the proper cost. It has to be an Android app thing.

Thanks again, this is fun…

Any chance of uploading source code to github.com so we can download and add to our own hubs.

Any chance I can grab this code for the Aeons lab smart switch (assuming that it is for the regular aeon labs smarts switch and not the one with clips and all)? I have three of those in my basement and desperately need the cost part.

I don’t know about you all, but most Elec Co’s that I have dealt with have tiered rate structures. So .07 for first 1000 kW and .15 for next 1500 and .31 from there. Just thought maybe someone else might want to consider this when editing the code.

I am using the Aeon Labs DSC06106 Z-wave Smart Energy Switch. I quickly created a github for the code @ https://github.com/chaospup/Z-Wave-Metering-Switch-with-Cost

It is a work in progress, any advice will be greatly appreciated. I had to take a break for a bit to rebuild my home.

This is true, I was trying to get the basics complete first (get the cost to display) before tackling the tiered payment portion.

Thanks a lot. Let me get this going.

There was a small syntax error which I fixed on line 62.

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
script1415124873496532864338.groovy: 47: expecting ‘)’, found ‘}’ @ line 47, column 9.
}
^
Will give it a shot soon.

Also, realized namespace is required else it gives validation error.