# Help with registerCapabilityListener

**URL:** <https://community.homey.app/t/help-with-registercapabilitylistener/10099>\
**Category:** Developers\
**Created:** [March 5, 2019, 12:02am UTC](https://community.homey.app/t/help-with-registercapabilitylistener/10099 "2019-03-05T00:02:28Z")\
**Posts on this page:** 5\
**Page:** 3

<div class="post-metadata">

**Author:** ![Adrian\_Rockall](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/adrian_rockall/32/13209_2.png) [@Adrian\_Rockall](https://community.homey.app/u/Adrian_Rockall)\
**Post date:** [July 21, 2021, 10:12am UTC](https://community.homey.app/t/help-with-registercapabilitylistener/10099/42 "2021-07-21T10:12:05Z")

</div>

> [@Jens\_De\_Smet](#):
>
> But I have another question, how do you actually make a device turn on or off through the app

You will obviously need something that generates an event to call your code. That could be a flow action card for example (or by polling for information from the physical device if you had one).

In the flow action you set the capability value. So, in your app onInit function you would register the flow card something like this:

```auto
 let change_my_capability_action = new Homey.FlowCardAction( 'change_my_capability_action' );
 my_action 
   .register()
   .registerRunListener( async ( args, state ) =>
   {
      return await args.device.triggerCapabilityListener( 'enum_no_on_off_capability', args.on_off ); 
   });

```

app.json

```auto
  "flow": {
    "actions": [
        {
          "title": {
          "en": "Switch On or Off"
        },
        "titleFormatted": {
          "en": "Turn [[on_off]] the lights"
        },
        "args": [
          {
            "type": "device",
            "name": "device",
            "filter": "driver_id=myDeviceID"
          },
          {
            "type": "dropdown",
            "name": "on_off ",
            "values": [
              {
                "id": "off",
                "title": {
                  "en": "Off"
                }
              },
              {
                "id": "on",
                "title": {
                  "en": "On"
                }
              }
            ]
          }
        ],
        "id": "change_my_capability_action"
      },
    ]
  }

```

---

<div class="post-metadata">

**Author:** ![Adrian\_Rockall](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/adrian_rockall/32/13209_2.png) [@Adrian\_Rockall](https://community.homey.app/u/Adrian_Rockall)\
**Post date:** [July 21, 2021, 10:16am UTC](https://community.homey.app/t/help-with-registercapabilitylistener/10099/43 "2021-07-21T10:16:53Z")

</div>

`triggerCapabilityListener` might not work there as you have define the capability as not settable, in which case you would use  
`args.device.setCapabilityValue('enum_no_on_off_capability, args.on_off);`

But that won’t trigger the capability listener.

---

<div class="post-metadata">

**Author:** ![Jens\_De\_Smet](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jens_de_smet/32/33978_2.png) [@Jens\_De\_Smet](https://community.homey.app/u/Jens_De_Smet)\
**Post date:** [July 21, 2021, 10:20am UTC](https://community.homey.app/t/help-with-registercapabilitylistener/10099/44 "2021-07-21T10:20:13Z")

</div>

That’s not really what I meant but I see something in it to use later I mean if AE\_I1 changes , instead of that line that comes in the CMD that turns on another device within the same driver eg Q1

```auto
{
         name: 'Q1 (AE)',
         dates: {
           id: 'AE_Q1',
         },
         capabilities: [
           "my-enum_no_on_off_capability"
         ],
         energy: {
           approximation: {
             usageConstant: 0, // in Watts
           },
         },
       },

```

Therefore it is enum\_no\_on\_off\_capability because it is not allowed to be turned on and off by the user.

But By the app itself when I1 eg turns on.

This is what I meant.

---

<div class="post-metadata">

**Author:** ![Adrian\_Rockall](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/adrian_rockall/32/13209_2.png) [@Adrian\_Rockall](https://community.homey.app/u/Adrian_Rockall)\
**Post date:** [July 21, 2021, 10:45am UTC](https://community.homey.app/t/help-with-registercapabilitylistener/10099/45 "2021-07-21T10:45:19Z")

</div>

OK, still the same basic code applies to set a value, but you first need to locate the devices instance.  
You could use:

```auto
let otherDevice = this.driver.getDevice({id: 'AE_Q1'});
otherDevice.setCapabilityValue('enum_no_on_off_capability', value);

```

---

<div class="post-metadata">

**Author:** ![Dijker](https://avatars.discourse-cdn.com/v4/letter/d/b9bd4f/32.png) [@Dijker](https://community.homey.app/u/Dijker)\
**Post date:** [June 9, 2025, 11:05am UTC](https://community.homey.app/t/help-with-registercapabilitylistener/10099/46 "2025-06-09T11:05:05Z")

</div>

Archived on June 9, 2025, 11:05am UTC



[Previous page](https://community.homey.app/t/help-with-registercapabilitylistener/10099.md?page=2)
