Access /eventstream from cloud? Or, alternative ways for hub to 'push' updates to a mobile device

Hi,

I've been working on an Android dashboard for a while now (here). It's working using a combination of the MakerAPI and the /eventsocket for receiving device state updates.

I'm also supporting remote access using the cloud token with MakerAPI. But, at least as far as I know the /eventsocket isn't accessible outside of the network.

I know MakerAPI offers a webhook - a URL you can set which will get called any time there's an update to report. However, that's not practical for a mobile device which typically can't be reached this way. So, I'm looking for some thoughts on alternative ideas.

The best way to reach a mobile device is push notifications (aka: GCM or FCM).. Hubitat uses these already to send out mobile notifications to your device. But, I don't imagine this would be available to 3rd party apps.

Another way would be to have a websocket (aka /eventsocket) available via the cloud API.. to be honest this might already be available and I just need some help what the URL would be to reach it.

The only other thought I can think of is some 3rd party service which might turn that webhook and turn it into a push notification.. it's not ideal as I'd like to avoid needing any servers at all - but at least it would offer a solution when you're away from home.

(of course a custom hubitat app running on the hub might be the best solution.. but I'm an Android developer so that's not something I'd be comfortable with without a lot of help!)

thanks,
joe

This is an old post but one I'd really like to ask again now that I have more experience developing an app for Hubitat.

I wrote the Hubitat Dashboard for Android which initially was designed for wall-mounted tablets throughout your house but has evolved into a pretty full-featured app that works anywhere.

There's over 2,000 active devices using it today and I've heard a lot of great feedback from the community. I'm constantly updating it to handle requests for all kinds of devices that I don't have myself but I like being able to contribute to help Hubitat grow!

Anyway, I'm pretty happy with how the app works locally (on the same network as the hub). It uses a combination of MakerAPI's and /eventsocket for realtime updates.

BUT, when in 'cloud' mode (outside of the network) things aren't as great. The app can't use the /eventsocket endpoint and needs to rely on polling the MakerAPI's for device state changes.

My app (and anyone's for that matter) would really benefit from being able to receive notifications of device state changes remotely (cloud mode). I can think of 2 ways to do this -- and probably not too difficult either:

  1. allow the /eventstream websocket endpoint to be hit from outside the network.. maybe with some additional protections such as the 'allow HSM' toggle option in MakerAPI. Basically, a client can keep an open HTTP connection to this endpoint and receive updates real-time.

  2. add logic to send out push notifications (GCM/FCM). The Hubitat app does this today to receive notifications. Admittedly, this is more of an Android solution than iOS as I don't know if iOS allows for 'background notifications' (ie: not just displaying everything in the notification panel).

For #2, I thought about creating a Hub app which would be able to listen to events and send them out to the user's device(s) via push notifications. I imagine it can be done and isn't super difficult but I'm not a server-developer anymore and I'd need help getting that one off the ground..

#1 seems like an easy win for everyone IMO.. I know a lot of developers rely on /eventstream today.. just allowing it to be accessed remotely using the MakerAPI's authentication token would allow my app (and anyone else's) to stop polling for changes and just wait for them.

I'd love it if any Hubitat devs would be able to comment on how feasible these ideas are. I don't know anyone personally as I've been focused on my app.. but, now that I've got some downtime this would be a good time for me to start asking around too

1 Like

Tagging @gopher.ny from Hubitat, as he may be best qualified to answer these questions.

1 Like

That’s a significant issue. One that is likely to bite more people is when their WAN IP changes. Whatever mechanism you envisage would work best if it used Hubitat’s cloud. Which has the negative effect of increasing their expenses.

As long as it is optional/disable-able with the default being disabled, then I'm good with any change. :slight_smile:

I'm not sure that's the case.. Right now I'm polling the MakerAPI every few seconds.. and because the /devices/all endpoint is so slow - I have to fetch each device individually.. so, for 100 devices that's 100 API calls every few seconds while the app is running in the foreground.

A websocket is a persistent (keep-alive) connection to your local Hub. If the connection is closed for some reason (ie: walk into an elevator) - it'll reconnect. It should be a lot less overhead than polling.

As for Hubitat's cloud expenses, I'm sure they're not free. But, ultimately they just need to direct traffic to your local hub. There's no server in the middle to maintain AFAIK.

1 Like

I'm not sure I see the security risk if that's what you're getting at.. not any more than any other MakerAPI endpoint which is accessible from anywhere.

Like any MakerAPI endpoint it'd still require:

  • maker api installed & devices selected
  • app ID
  • app token
  • cloud token

I don't want something I have zero intention of using accessible externally, regardless of the other mitigations. Just my preference.

No argument that it would probably be fine even if it was externally available with the other protections though.

But less is more when it comes to unused connectivity.

Just wanted to revisit this topic to see if anything's being planned.. I have to imagine it wouldn't only help just my app to be able to receive realtime updates remotely without constantly polling MakerAPI.

I don't think it would introduce any new security risks either.. there's already an option in MakerAPI to access via cloud..
image

In my mind, all you'd need to do is add an /eventstream-like endpoint to MakerAPI and let it be protected the same way all of MakerAPI app is protected. It already has to be manually added - and then also has both local and remote protect options from there

1 Like

@gopher.ny would you be available to shed any light on this please?

This whole thing fell off the radar for a while. Let me see what can be cooked up, and don't hesitate to remind me every now and then. I can see the use cases for it.

4 Likes

Download the Hubitat app