# Push notifications from Homey Web Api

**URL:** <https://community.homey.app/t/push-notifications-from-homey-web-api/15555>\
**Category:** Developers\
**Created:** [July 14, 2019, 8:37am UTC](https://community.homey.app/t/push-notifications-from-homey-web-api/15555 "2019-07-14T08:37:30Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![ismar.slomic](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ismar.slomic/32/13411_2.png) [@ismar.slomic](https://community.homey.app/u/ismar.slomic)\
**Post date:** [July 14, 2019, 8:37am UTC](https://community.homey.app/t/push-notifications-from-homey-web-api/15555/1 "2019-07-14T08:37:30Z")

</div>

Im using Web Api for building web based Homey Dashboard. To retrieve updates (for devices, activities, alarms,) from my Homey, does Web Api support pushing events/notification to my web app or do I need to poll for new updates frequently?

Couldnt find this answer in the doc ([https://developer.athom.com/docs/api](https://developer.athom.com/docs/api))

---

<div class="post-metadata">

**Author:** ![Jamie](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jamie/32/5274_2.png) [@Jamie](https://community.homey.app/u/Jamie)\
**Post date:** [July 14, 2019, 1:29pm UTC](https://community.homey.app/t/push-notifications-from-homey-web-api/15555/2 "2019-07-14T13:29:56Z")

</div>

The webAPI uses even emitters, for example for device capability updates it would look something 🙂

 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/2X/7/7e5b43c96bf9dcd8dfbaac02cdebcf2b264aed4e.png)

With the group app I do it in the following way :

```auto
 try {
                            // Link our event to a state change of the capability.
                            this.instances[device.id][this.capabilities[i]] = device.makeCapabilityInstance(this.capabilities[i], listener);
                        } catch (error) {
                            this.error('validateDeviceInstances: error setting ' + device.id + ' capability ' + this.capabilities[i] + ' for ' + device.name + '. Is device is ready? : ' + device.ready + '. Does the instance exist ' + exists)
}

```

---

<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 14, 2019, 1:54pm UTC](https://community.homey.app/t/push-notifications-from-homey-web-api/15555/3 "2019-07-14T13:54:32Z")

</div>

I’m pretty sure that `makeCapabilityInstance` doesn’t work from a web app (one that runs in a browser). I remember having tried and got errors inside of `athom-api.min.js` that I didn’t bother debugging because of lack of source maps.

---

<div class="post-metadata">

**Author:** ![Jamie](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jamie/32/5274_2.png) [@Jamie](https://community.homey.app/u/Jamie)\
**Post date:** [July 14, 2019, 2:56pm UTC](https://community.homey.app/t/push-notifications-from-homey-web-api/15555/4 "2019-07-14T14:56:47Z")

</div>

That may have been the case, but it looks like it is "fixed’ now.

Homeydash uses the same method

> <https://github.com/daneedk/homeydash.com/blob/90c8d9ca77320e91b25e31ab73c274894809eac6/app/js/homeydash.app.js#L401-L410>

---

<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 14, 2019, 4:01pm UTC](https://community.homey.app/t/push-notifications-from-homey-web-api/15555/5 "2019-07-14T16:01:39Z")

</div>

I see, that’s problem #1 solved. Problem #2 is that you’ll need dozens, if not hundreds of listeners if you want to catch all capability changes, but it looks like `socket.io` is being used under the hood, so it should be possible to tap into that event stream. I’ll try and see if I can get something to work.

---

<div class="post-metadata">

**Author:** ![ismar.slomic](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ismar.slomic/32/13411_2.png) [@ismar.slomic](https://community.homey.app/u/ismar.slomic)\
**Post date:** [July 14, 2019, 5:05pm UTC](https://community.homey.app/t/push-notifications-from-homey-web-api/15555/6 "2019-07-14T17:05:40Z")

</div>

Nice, this is very useful! It would be good if we could subscribe on specific topic/group in stead of each device capability, but it is still doable.

What exactly is [HomeyAPI.ManagerFlowToken.getFlowTokens()](https://developer.athom.com/docs/api/HomeyAPI.ManagerFlowToken.html#getFlowTokens) used for? I thought this was also two-way sync for latest device and Homey status, but maybe I misunderstood?

---

<div class="post-metadata">

**Author:** ![Jamie](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jamie/32/5274_2.png) [@Jamie](https://community.homey.app/u/Jamie)\
**Post date:** [July 15, 2019, 5:57am UTC](https://community.homey.app/t/push-notifications-from-homey-web-api/15555/7 "2019-07-15T05:57:49Z")

</div>

I dont know anything about tapping into the [socket.io](http://socket.io) event steam, but it sounds like a good way to go about it.

A dashboard is in fact incredibility similar to how the groups app works.

There are two ‘tricks’ a) you only need to subscribe to the capabilities the devices you have. b) You can easily loop though ‘all devices’ and for each device - loop through ’ all capabilities and just add a listener. - three lines of code 🙂

Sorry I have not used the webAPI flow manager - Based on the name, I do know that flow tokens in the SDK refer to tags - and the two API generally match up. ( [https://apps.developer.athom.com/tutorial-Flow-Tokens.html](https://apps.developer.athom.com/tutorial-Flow-Tokens.html) )

---

<div class="post-metadata">

**Author:** ![DaneedeKruyff](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/daneedekruyff/32/964_2.png) [@DaneedeKruyff](https://community.homey.app/u/DaneedeKruyff)\
**Post date:** [July 15, 2019, 6:39am UTC](https://community.homey.app/t/push-notifications-from-homey-web-api/15555/8 "2019-07-15T06:39:15Z")

</div>

GetFlowTokens() does indeed return all ‘tags’ as they are called in the floweditor. In [homeydas.com](http://homeydas.com) I use it to retrieve the sunrise, sunset and battery levels: [https://github.com/daneedk/homeydash.com/blob/90c8d9ca77320e91b25e31ab73c274894809eac6/app/js/homeydash.app.js#L264](https://github.com/daneedk/homeydash.com/blob/90c8d9ca77320e91b25e31ab73c274894809eac6/app/js/homeydash.app.js#L264)

---

<div class="post-metadata">

**Author:** ![ismar.slomic](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ismar.slomic/32/13411_2.png) [@ismar.slomic](https://community.homey.app/u/ismar.slomic)\
**Post date:** [August 4, 2019, 9:07pm UTC](https://community.homey.app/t/push-notifications-from-homey-web-api/15555/9 "2019-08-04T21:07:57Z")

</div>

> [@DaneedeKruyff](#):
>
> GetFlowTokens() does indeed return all ‘tags’ as they are called in the floweditor

Could you please explain what `tags` are and when to use `makeCapabilityInstance()` and `getFlowTokens()`?

---

<div class="post-metadata">

**Author:** ![ismar.slomic](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ismar.slomic/32/13411_2.png) [@ismar.slomic](https://community.homey.app/u/ismar.slomic)\
**Post date:** [August 4, 2019, 10:59pm UTC](https://community.homey.app/t/push-notifications-from-homey-web-api/15555/10 "2019-08-04T22:59:56Z")

</div>

> [@Jamie](#):
>
> The webAPI uses even emitters, for example for device capability updates it would look something

I managed to get event emitters to work for device capability updates. 👍 But can it also be used for Notifications?
