Skip to content

Instantly share code, notes, and snippets.

@greenygh0st
Created March 20, 2025 03:23
Show Gist options
  • Save greenygh0st/a14b64b58c864952927e01bcea2a74ec to your computer and use it in GitHub Desktop.
Save greenygh0st/a14b64b58c864952927e01bcea2a74ec to your computer and use it in GitHub Desktop.
For Hubitat mirror a power meter without exposing a switch
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