# Homey Pro - homey-api package

**URL:** <https://community.homey.app/t/homey-pro-homey-api-package/113477>\
**Category:** Questions & Help\
**Tags:** webapp, homey-pro\
**Created:** [July 26, 2024, 7:24pm UTC](https://community.homey.app/t/homey-pro-homey-api-package/113477 "2024-07-26T19:24:35Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sebastien.L](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/sebastien.l/32/80542_2.png) [@Sebastien.L](https://community.homey.app/u/Sebastien.L)\
**Post date:** [July 26, 2024, 7:24pm UTC](https://community.homey.app/t/homey-pro-homey-api-package/113477/1 "2024-07-26T19:24:35Z")

</div>

Hello Homey Community,

I am using the homey-api package (NPM NODE/JS) to create my own dashboard. I am using the Angular IO Framework to load homey-api.

I am able to successfully connect to my Homey and access the list of my devices, but I am unable to subscribe to the device.update event as stated in the documentation. I am not encountering any JS errors or otherwise, but a device status update does not trigger any event on my end.

```auto
 private async init() {
    try {
      // Connect to Homey API
      const homeyApi = await HomeyAPI.createLocalAPI({
        address: environment.homey_ip,
        token: environment.homey_token,
        debug: null
      });
      console.log('Connected to Homey locally'); // OK HERE

      // Load devices
      const devices = await homeyApi.devices.getDevices();
      console.log('Loaded devices:', devices); // OK HERE, LIST OF DEVICE IS AVAILABLE

      // Subscribe to device update events globally
      homeyApi.devices.on('device.update', (updatedDevice:any) => {
        console.log('Global device.update event triggered:', updatedDevice); // KO NEVER PASS HERE
        // Add your update logic here
      });
      console.log('Subscribed to global device update events');

      // Subscribe to specific device updates
      const specificDeviceId = 'b515b4ca-5570-4a9b-bef8-XXX';
      const device = await homeyApi.devices.getDevice({ id: specificDeviceId });

      if (device) {
        console.log('Device found:', device); // OK HERE, DEVICE IS AVAILABLE
        device.on('device.update', (updatedDevice:any) => {
          console.log('Specific device.update event triggered:', updatedDevice); // KO NEVER PASS HERE
          // Add your update logic here
        });
        console.log('Subscribed to specific device updates');
      } else {
        console.error('Device not found');
      }

    } catch (error) {
      console.error('Error initializing Homey API:', error);
    }
  }

```

Please find attached my code so that you can better understand my issue.

Thank you in advance for your help and response.

Best regards,

---

<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:** [July 27, 2024, 4:39am UTC](https://community.homey.app/t/homey-pro-homey-api-package/113477/2 "2024-07-27T04:39:46Z")

</div>

Before you receive these events you need to use [`connect()`](https://athombv.github.io/node-homey-api/HomeyAPIV2.ManagerDevices.html#connect) (which is one of those things that isn’t documented anywhere AFAIK):

```auto
await homeyApi.devices.connect();
homeyApi.devices.on('device.update', ...);

```

Also, there is no event `device.update` on `Device` instances, only [`update`](https://athombv.github.io/node-homey-api/HomeyAPIV2.ManagerDevices.Device.html#.event:update).

FWIW, these events aren’t triggered on capability changes, only on underlying device changes (for instance when a capability has been added or deleted from the device, or when a device becomes ready).

---

<div class="post-metadata">

**Author:** ![Sebastien.L](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/sebastien.l/32/80542_2.png) [@Sebastien.L](https://community.homey.app/u/Sebastien.L)\
**Post date:** [July 27, 2024, 8:37am UTC](https://community.homey.app/t/homey-pro-homey-api-package/113477/3 "2024-07-27T08:37:52Z")

</div>

Hello,

Thank you very much for your prompt response. It is greatly appreciated, thank you!

Is there a way to monitor status changes in this case?

A light turns on, my alarm changes status, a door opens… all the changes of state?

Thank you in advance,  
Sébastien

---

<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:** [July 27, 2024, 8:45am UTC](https://community.homey.app/t/homey-pro-homey-api-package/113477/4 "2024-07-27T08:45:01Z")

</div>

There’s an undocumented event `capability` that you can use:

```auto
device.on('capability', ({ capabilityId, value }) => {
  console.log(`Capability "${ capabilityId }" changed to "${ value }"`);
});

```

---

<div class="post-metadata">

**Author:** ![Sebastien.L](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/sebastien.l/32/80542_2.png) [@Sebastien.L](https://community.homey.app/u/Sebastien.L)\
**Post date:** [July 27, 2024, 3:37pm UTC](https://community.homey.app/t/homey-pro-homey-api-package/113477/5 "2024-07-27T15:37:30Z")

</div>

Thanks so much for your return.

I tried this code, but not working

```auto
      await this.homeyApi.devices.connect(); // Fetch all devices.

    // Get device
    const device = await this.homeyApi.devices.getDevice({id: 'b515b4ca-5570-4a9b-bef8-752a48141acb'});

    // Test 1
    device.on('capability', (event:any) => {
      console.log('NOT WORKGING');
    })

    // Test 2
    this.homeyApi.devices.on('capability', (device: any) => {
      // Subscribe to device update events.
      console.log('NOT WORKGING'); // NOT WORKING DON'T HAVE THIS LOG ON CHANGE STATUS DEVICE.
      if (this.subscribedDevices.has(device.id)) {
        // Check if the device is subscribed.
        this.deviceDataService.updateDevice(device); // Update the device data.
      }
    });
    this.homeyApi.devices.on('update', (device: any) => {
      // Subscribe to device update events.
      console.log('WORKING'); // NOT WORKING DON'T HAVE THIS LOG ON CHANGE STATUS DEVICE.
      if (this.subscribedDevices.has(device.id)) {
        // Check if the device is subscribed.
        this.deviceDataService.updateDevice(device); // Update the device data.
      }
    });

```

Best regards,

---

<div class="post-metadata">

**Author:** ![Sebastien.L](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/sebastien.l/32/80542_2.png) [@Sebastien.L](https://community.homey.app/u/Sebastien.L)\
**Post date:** [July 27, 2024, 3:49pm UTC](https://community.homey.app/t/homey-pro-homey-api-package/113477/6 "2024-07-27T15:49:30Z")

</div>

It’s OK ! Thanks.

It’s not possible to event capability for all devices for have all devices updated some times ?

```
// Get device
const device = await this.homeyApi.devices.getDevice({id: 'fd0fef76-ef51-44af-b5ad-ee6caffb835e'});
device.makeCapabilityInstance('onoff', (value:any) => {
  console.log('Device onoff changed to:', value); // OK
});

// Test 1
device.on('capability', (event:any) => {
  console.log(event); // OK
})

```

---

<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:** [July 27, 2024, 4:42pm UTC](https://community.homey.app/t/homey-pro-homey-api-package/113477/7 "2024-07-27T16:42:10Z")

</div>

Apologies, it should be this:

```auto
const device = await this.homeyApi.devices.getDevice({id: 'b515b4ca-5570-4a9b-bef8-752a48141acb'});

device.on('capability', (event:any) => {
  console.log('NOT WORKGING');
}).connect();

```

---

<div class="post-metadata">

**Author:** ![Sebastien.L](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/sebastien.l/32/80542_2.png) [@Sebastien.L](https://community.homey.app/u/Sebastien.L)\
**Post date:** [July 27, 2024, 5:15pm UTC](https://community.homey.app/t/homey-pro-homey-api-package/113477/8 "2024-07-27T17:15:28Z")

</div>

Thank you very much for your invaluable help. I now have a functional foundation that allows me to move forward with my interface!

A thousand thanks!
