backgroundColors changing on variable defined in preferences?

I’m very much a beginner with coding in smartthings, so I apologize now if this is incredibly simple. I’m building a device type for appliances that are only monitored, not switched on and off based on the Aeon Home Energy Monitor type. The goal is to have a tile that changes color based on whether or not the appliance is running or not based on the wattage pull. I’m trying to define a variable for the wattage in the preferences section, and then pass it up to the tile state to change colors based on a value. I can define the variable in preferences with no issue, but when I go up to the state section it throws back an error. This is the premise of what I’m trying to do:

		state "default", backgroundColors: [
			[value: ${wattStatus}-1, color: "#ffffff"],
			[value: ${wattStatus}, color: "#1e9cbb"]

		]

I’ve found some of my devices have a very small vampire draw even when turned off, and it varies by device, otherwise I’d just use 0 and 1 to determine the color states. Any help would be greatly appreciated!

On second thought, I don’t think I’m creating the variable right, because I tried to alter the code to include the variable as a label and it’s displaying “Null”, here’s my preferences code:

    preferences {
    input "wattStatus", "number", title: "How much power should be drawn to show in use status", defaultValue: 10, required: true, displayDuringSetup: false

}

Are you looking to change the color of the device tile or the input section to configure a SmartApp?

Take a look at the “smartsense multi” code. That should point you in the right direction.

1 Like

I already know how to change the color of the tile, that’s not the issue. The problem I’m having is I want to make one device type that has a variable wattage that defines whether the tile is showing on or off. For instance, my dryer meter is showing about 5 watts when off, and around 4000 watts when running. My washing machine pulls 0 watts when off, and about 250 watts when running. If I set off as being less than 1 watt, and on being greater than 1 watt, than my dryer will always indicate that it’s on. I’d like to define that variable in the device type for each individual device.

Currently I have it set at less than 9 for off and greater than 10 for on status, and this does work for these two devices, however in order to make it more functional for a wide range of devices, I want to be able to configure that variable.

Here’s the complete code as it exists. Like I said, right now I’ve got it set to 9 and 10 for the values, but I’d like to replace that with wattStatus -1 and wattStatus that I’m trying to define in the preferences. @keithcroshaw am I doing this in the wrong place?

/**

  • Appliance Energy Monitor

  • Author: PKLehmer

  • Based off of Aeon Home Energy Meter from Smartthings

  • Date: 2015-05-01
    */
    metadata {
    // Automatically generated. Make future change here.
    definition (name: “Appliance Energy Monitor”, namespace: “pklehmer”, author: “PKlehmer”) {
    capability "Energy Meter"
    capability "Power Meter"
    capability "Configuration"
    capability “Sensor”

    command "reset"
    
    fingerprint deviceId: "0x2101", inClusters: " 0x70,0x31,0x72,0x86,0x32,0x80,0x85,0x60"
    

    }

    // simulator metadata
    simulator {
    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()
    }
    }

    // tile definitions
    tiles {
    valueTile(“status”, “device.power”, canChangeIcon: true) {
    state “default”, icon: “st.Appliances.appliances17”, label: ‘${wattStatus}’, backgroundColors: [
    [value: 9, color: “#ffffff”],
    [value: 10, color: “#1e9cbb”]

    	]
    }
    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("refresh", "device.power", inactiveLabel: false, decoration: "flat") {
    	state "default", label:'', action:"refresh.refresh", icon:"st.secondary.refresh"
    }
    standardTile("configure", "device.power", inactiveLabel: false, decoration: "flat") {
    	state "configure", label:'', action:"configuration.configure", icon:"st.secondary.configure"
    }
    
    main (["status", "power","energy"])
    details(["status", "power","energy", "reset","refresh", "configure"])
    

    }
    preferences {
    input “wattStatus”, “number”, title: “How much power should be drawn to show in use status”, defaultValue: 10, required: true, displayDuringSetup: false

    }
    }

def parse(String description) {
def result = null
def cmd = zwave.parse(description, [0x31: 1, 0x32: 1, 0x60: 3])
if (cmd) {
result = createEvent(zwaveEvent(cmd))
}
log.debug "Parse returned ${result?.descriptionText}"
return result
}

def zwaveEvent(physicalgraph.zwave.commands.meterv1.MeterReport cmd) {
if (cmd.scale == 0) {
[name: “energy”, value: cmd.scaledMeterValue, 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.Command cmd) {
// Handles all Z-Wave commands we aren’t interested in
[:]
}

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

def reset() {
// No V1 available
return [
zwave.meterV2.meterReset().format(),
zwave.meterV2.meterGet(scale: 0).format()
]
}

def configure() {
def cmd = 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
])
log.debug cmd
cmd
}

I would make those dynamic settings in the preferences. Check the Belkin Wemo Insight device type, I think ST is doing something similar without the preferences there.

I’m not seeing a Smartthings Device Type for the Wemo Insight, only the Wemo outlet, and I looked at someones customer device type, I’m not seeing anything too helpful, but like I said I might be missing it.

It’s tough because it’s one of the secret devices that gets spawned from a SmartApp, I just thought it was in there sorry. I do better with SmartApps than Device Types. What device are you using this with? I have an Aeon Smart power plug that I could try this on. I’m assuming simulator isn’t much help? It doesn’t seem to be a fan of power values.

Suggestion:Simplify.

Set the tile to simply show “off” and “on”, like any other switch tile with different colors of your choosing.

In your event handler for wattage change, used the preference values to calculate whether you want to show the device as “off” or “on”, then simply

sendEvent( theSwitch, “off”)

Same end result, only without the complexity…

(This is only a humble suggestion…you will need to decide if it works for your implementation)

1 Like

@storageanarchy, will this actually turn the device on and off? I was pretty comfortable just doing simple modifications to the base device type and this sounds like it could get a little more complicated.

I’m using the Aeon Outlet for the washing machine, and the Aeon Home Energy Monitor v1 for the dryer, using this same device type for both works right now.

Create a new/additional valueTile(“displayStatus”, “device.displayStatus” — and use [value:“on”, color:

Then sendEvent(“displayStatus”, “on”) in your logic, right after where it sends the “power” event - this will update BOTH tiles…

You’ll need to add the new "displayStatus"tile to the list of tiles to display in both the main and details lists. Then you can select the tile to be the one that displays instead of the current default tile. You may also need to add

        attribute "displayStatus", "string"

in the metatdata section.

I use this technique to dynamically update several different tiles at once in my HEMv2 device (search here on the forum or on gitHub).

3 Likes

I was hoping someone would post this answer…

Device Tiles are limited to displaying information about one Attribute / Event Name. That is the limited extent of dynamic display currently.

Links to a couple recent Topic with same conclusion:

And

Awesome solution man!

1 Like

Any chance you could show me an example of Paul’s code with the Status tile included?
I cant seem to make it work with the basic on/off status tile, which is my goal. Currently the device is showing a NULL value over the current status tile - while it works fine (as Im basically just after the color showing me if my appliance is running), its not pretty…