Created
March 20, 2025 03:23
-
-
Save greenygh0st/a14b64b58c864952927e01bcea2a74ec to your computer and use it in GitHub Desktop.
For Hubitat mirror a power meter without exposing a switch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
definition( | |
name: "Power Meter Mirror", | |
namespace: "bubblelabs", | |
author: "Dale Myszewski", | |
description: "Mirrors only the power attribute from a selected device to a virtual device.", | |
category: "Convenience", | |
installOnOpen: true, | |
singleInstance: false, | |
iconUrl: "https://raw.githubusercontent.com/hubitat/HubitatPublic/master/hubitat.ico" | |
) | |
preferences { | |
section("Select Power Meter Device") { | |
input "sourceDevice", "capability.powerMeter", title: "Source Device", required: true, multiple: false | |
} | |
section("Select Virtual Device") { | |
input "virtualDevice", "capability.powerMeter", title: "Virtual Device", required: true, multiple: false | |
} | |
} | |
def installed() { | |
initialize() | |
} | |
def updated() { | |
unsubscribe() | |
initialize() | |
} | |
def initialize() { | |
if (sourceDevice && virtualDevice) { | |
subscribe(sourceDevice, "power", powerHandler) | |
} | |
} | |
def powerHandler(evt) { | |
log.debug "Updating virtual device power: ${evt.value} W" | |
virtualDevice.sendEvent(name: "power", value: evt.value, unit: "W") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment