# How to register a listener for a button capability?

**URL:** <https://community.homey.app/t/how-to-register-a-listener-for-a-button-capability/91844>\
**Category:** Developers\
**Created:** [October 15, 2023, 12:33pm UTC](https://community.homey.app/t/how-to-register-a-listener-for-a-button-capability/91844 "2023-10-15T12:33:39Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![troeste](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/troeste/32/18643_2.png) [@troeste](https://community.homey.app/u/troeste)\
**Post date:** [October 15, 2023, 12:33pm UTC](https://community.homey.app/t/how-to-register-a-listener-for-a-button-capability/91844/1 "2023-10-15T12:33:39Z")

</div>

Hello, I try to write a driver for a virtual push button device (push only, not on-off) based on the button device class with a button capability. I have problems finding out how add an event handler to be fired when the user press the button in the Homey app.

I have tried to use registerCapabilityListener(‘button’) but no event is fired when I press the button in the Homey App. I also notice that the Homey app tells me that the device is not controllable.

I have also looked into adding an action listener using registerRunListener, but I do not find any way to related the action the a specific device.

Any suggestions?

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [October 15, 2023, 12:42pm UTC](https://community.homey.app/t/how-to-register-a-listener-for-a-button-capability/91844/2 "2023-10-15T12:42:22Z")

</div>

[Works fine for me](https://github.com/robertklep/name.klep.homekitty/blob/87880f54abb9f754d531d990c71952e5211c83ab/drivers/flow-starter/device.js#L45-L51).

This is what it looks like in the web app:

 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/f/e/fe34f570ea13c5f18c14363a08550bfc9d2081f5.jpeg)

---

<div class="post-metadata">

**Author:** ![troeste](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/troeste/32/18643_2.png) [@troeste](https://community.homey.app/u/troeste)\
**Post date:** [October 15, 2023, 12:50pm UTC](https://community.homey.app/t/how-to-register-a-listener-for-a-button-capability/91844/3 "2023-10-15T12:50:54Z")

</div>

Ok, I have registered this for class and capability in the driver.compose.json:

“class”: “button”,  
“capabilities”: [  
“button”  
],

Anything else needed?

Are you using registerCapabilityListener(‘button’) to handle the push event?

-Trygve

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [October 15, 2023, 12:57pm UTC](https://community.homey.app/t/how-to-register-a-listener-for-a-button-capability/91844/4 "2023-10-15T12:57:46Z")

</div>

> [@troeste](#):
>
> Are you using registerCapabilityListener(‘button’) to handle the push event?

I guess you didn’t spot the link I posted: [https://github.com/robertklep/name.klep.homekitty/blob/87880f54abb9f754d531d990c71952e5211c83ab/drivers/flow-starter/driver.compose.json](https://github.com/robertklep/name.klep.homekitty/blob/87880f54abb9f754d531d990c71952e5211c83ab/drivers/flow-starter/driver.compose.json)

The only difference seems to be that I’m using `other` as device class, not `button`.

---

<div class="post-metadata">

**Author:** ![troeste](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/troeste/32/18643_2.png) [@troeste](https://community.homey.app/u/troeste)\
**Post date:** [October 15, 2023, 1:03pm UTC](https://community.homey.app/t/how-to-register-a-listener-for-a-button-capability/91844/5 "2023-10-15T13:03:09Z")

</div>

Thanks a lot - device class “other” did the trick!

-Trygve

---

<div class="post-metadata">

**Author:** ![troeste](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/troeste/32/18643_2.png) [@troeste](https://community.homey.app/u/troeste)\
**Post date:** [October 15, 2023, 1:04pm UTC](https://community.homey.app/t/how-to-register-a-listener-for-a-button-capability/91844/6 "2023-10-15T13:04:42Z")

</div>

BTW, is it possible to listen to action cards for devices? Did not find a way to associate the action flow card with a device when getting the action.

-tr

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [October 15, 2023, 1:16pm UTC](https://community.homey.app/t/how-to-register-a-listener-for-a-button-capability/91844/7 "2023-10-15T13:16:04Z")

</div>

The device is available as `args.device` (where `args` is the first argument that gets passed to the [run listener](https://apps.developer.homey.app/the-basics/flow#listening-for-events)).

---

<div class="post-metadata">

**Author:** ![troeste](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/troeste/32/18643_2.png) [@troeste](https://community.homey.app/u/troeste)\
**Post date:** [October 15, 2023, 1:19pm UTC](https://community.homey.app/t/how-to-register-a-listener-for-a-button-capability/91844/8 "2023-10-15T13:19:52Z")

</div>

Ok, thanks a lot! That information seems to be missing in the SDK documentation for RunCallback.

-tr

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [October 15, 2023, 1:22pm UTC](https://community.homey.app/t/how-to-register-a-listener-for-a-button-capability/91844/9 "2023-10-15T13:22:17Z")

</div>

You’ll probably find that a lot of intricacies aren’t (properly) documented 🥴
