Subscribe to child device

I have the following 2 lines in my installed() method:

def child = addChildDevice("smartthings", "Momentary Button Tile", getDeviceID(), null, [name: getDeviceID(), label: deviceLabel, completedSetup: true])
subscribe(child, "capability.momentary", "switchHandler")

The device is created but it is not subscribed. If I include an input in preferences to select a switch, and then subscribe to that in the exact same way, it works.

//in preferences
section(“Select trigger switch …”) {
input “triggerSwitch”, “capability.momentary”, multiple: false, required: true
}

//in installed() immediately after the other subscribe line
subscribe(triggerSwitch, “capability.momentary”, “switchHandler”)

According to the docs, capability.momentary doesn’t have any attributes, just a push method. You probably need to subscribe to the “switch” attribute.

Edit: looking at the code for the button tile, try subscribing to “momentary” without the “capability” prefix…

1 Like