# makeCapabilityInstance listener for onoff capacity fires random times

**URL:** <https://community.homey.app/t/makecapabilityinstance-listener-for-onoff-capacity-fires-random-times/143240>\
**Category:** Developers\
**Tags:** app, devices, homey-pro, advancedflow\
**Created:** [September 20, 2025, 7:08pm UTC](https://community.homey.app/t/makecapabilityinstance-listener-for-onoff-capacity-fires-random-times/143240 "2025-09-20T19:08:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Svensei38](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/svensei38/32/140297_2.png) [@Svensei38](https://community.homey.app/u/Svensei38)\
**Post date:** [September 20, 2025, 7:08pm UTC](https://community.homey.app/t/makecapabilityinstance-listener-for-onoff-capacity-fires-random-times/143240/1 "2025-09-20T19:08:51Z")

</div>

My app registers for all devices a capacity listener (only for `onoff`) .

But when a device is turned on or off, it fires a random amount of times.

 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/1/b/1b40e7cf6b6f2c9006044227ac0c4277513051e7.png)

In some cases I saw 4 to 6 times the same event for the same device. It increases and decreases completely unpredictable.

I register the capacity listener per device once during initialization of the app:

```typescript
  protected async wireEvents(api: any, devices: Map<string, HomeyAPITypes.HomeyAPIV3Local.ManagerDevices.Device>): Promise<void> {
    //await api.devices.connect();
    api.devices.on("device.create", (device: any) => { this.addEntity(device as HomeyAPITypes.HomeyAPIV3Local.ManagerDevices.Device); });
    api.devices.on("device.update", (device: any) => { this.updateEntity(device as HomeyAPITypes.HomeyAPIV3Local.ManagerDevices.Device); });
    api.devices.on("device.delete", (device: any) => { this.deleteEntity(device as HomeyAPITypes.HomeyAPIV3Local.ManagerDevices.Device); });

    for(let deviceId of devices.keys()) {
      let device = devices.get(deviceId)!;
      if(!device.capabilities.includes(DeviceCapabilities.onOff)) continue;
      device.makeCapabilityInstance(DeviceCapabilities.onOff, async (newValue: any) => { await this.updateOnOffCapability(device.id, newValue); });
    }
  }

```

I’ve tried removing the `api.devices.on("device.xxx", …)` listeners, but they are unrelated.

```typescript
  private async updateOnOffCapability(deviceId: string, newValue: any): Promise<void> {
    // LOGGING IN SCREENSHOT ↓
    this.app.log(`Device '${deviceId}' onoff capability changed to '${newValue}'.`);
    
    let device = this.getDeviceById(deviceId);
    if(device === null) {
      throw new Error(`Device with ID '${deviceId}' not found.`);
    }

    this.app.emit(EventNames.deviceOnOffChange, new DeviceOnOffChangeEventArguments(device, newValue));
  }

```

**Does anyone have an idea why this is happening?**  
Please help, I have the feeling I’ve tried everything.

I’ve compare the behavior of my app with [Device Capabilities App](https://homey.app/en-be/app/nl.qluster-it.DeviceCapabilities/Device-Capabilities/), and that app works perfectly, so I must be doing something wrong…

Thanks in advance for any help.  
#device-capabilities
