Subscribe to dashboard button press in app does not pick up event

Hi Guys,

I am moving the control of an air-to-air heatpump from an RM rule to an app. The purpose of the rule/app is to automatically control the heat pump. In adittion to the automatic rules I also have created a dashboard with some buttons to control the heat pump. The purpose of the dashboard is to be able to override the automatic rules and change the settings on the heat pump manually. The tiles in the dashbaord are pointing to one virtual devices each, which represents a command, for instance 'TurnHeatPumpON'.

To make the script aware of what the dashboard does I want to subscribe to the events created by the virtual devices behind the dashboard buttons/tiles.

So I tried the following coding for that to happen, but the app is not picking up the events.

What am I missing?

Cheers,

def initialize() {
    log.info "Initializing"
    // - Subscribe to dashboard remote control buttons
    subscribe(location.TurnHeatPumpON, "pushed", dashboardHeatPumpON_Handler)
    subscribe(location.TurnHeatPumpOFF, "pushed", dashboardHeatPumpOFF_Handler)
}
// ------------------ Handler for incomming dashboard heat pump ON events --------------------------------------------------------------
//
def dashboardHeatPumpON_Handler(evt) { 
        log.info "Dashboard event handler: New event received: ${evt.value} from ${evt.device}"
        currentPowerStatusV = evt.value
        state.currentPowerStatusV = currentPowerStatusV
        log.debug "Dashboard event handler: Button pressed, new Power status value: ${state.currentPowerStatusV}"
}
// ------------------ Handler for incomming dashboard heat pump OFF events --------------------------------------------------------------
//
def dashboardHeatPumpOFF_Handler(evt) { 
        log.info "Dashboard event handler: New event received: ${evt.value} from ${evt.device}"
        currentPowerStatusV = evt.value
        state.currentPowerStatusV = currentPowerStatusV
        log.debug "Dashboard event handler: Button pressed, new Power status value: ${state.currentPowerStatusV}"     
}

Log file example from the virtual device representing the turn on the heat pump command:

You need a reference to the actual device here (i.e., the same name as the name parameter for a single-device input). These are device events, not hub/location events. The docs have many examples if you still aren't sure.

Also, make sure initialize() is actually called somewhere in your code. Unlike (some) drivers, there is nothing special about this method in an app, so it only runs when you run it somehow yourself (perhaps as part of updated()).

Thanks @bertabcd1234 ! I do read the documentation but for some reason I imagined, due to the property of being virtual, that they should be owned by the hub and therefor referenced using local. I now set them up like any other device and it worked like a charm. And thanks for the heads upp regarding initialize.