Reducing power reporting noise in a device type

I made a version of the DTH that has preferences so you can turn logging on/off and pick how many watts of change in power you care about when it’s on. This isn’t super polished, but it seems to work for now.

Add these lines in the preferences block:

preferences {
    // ...
    // original code
    // ...
    input name: "prefLogPower", type: "bool", title: "Show power usage?", description: "", required: true
    input name: "prefLogPowerDelta", type: "decimal", title: "Only show changes over…", description: "Enter watts", required: true
}

Add these in parse()

// ...
// bunch of stuff
// ...
else if (finalResult.type == "power") {
    def powerValue = (finalResult.value as Integer)/10
    def changeValue = powerValue - state.lastPowerValue

    if (prefLogPower == true) {
        if (changeValue > prefLogPowerDelta || changeValue < -prefLogPowerDelta || powerValue == 0 || state.lastPowerValue == 0) {
            sendEvent(name: "power", value: powerValue, descriptionText: '{{ device.displayName }} power is {{ value }} Watts', translatable: true )
            state.lastPowerValue = powerValue
        }
    }
    // ...
    // only other thing here in the original code was a big comment.
    // ...
}
1 Like