Can an app share information with other apps

Hi all,

Does Hubitat offer a means for an application to publish information that's then accessible to other apps?

I have ~10 custom apps that all handle small bits of automation but I find they're often acting on similar constructs (rooms, temp sensors, motion sensors, switches, thermostats) and I thought it would be simple to write an app that publishes the key status values of every room (temp, motion, thermostat, lights, etc...) so that I don't need to configure the relevant sensors for each app.

I was hoping I could publish a simple API (e.g. getRoomInfo(roomID) or getRoomTemp(roomID)) available to all apps & rules but I have yet to figure out how to do so.

Here's what I've tried so far:

  • Gobal Variable - only supports simple dataTypes & limited to 1024 characters
  • Virtual Device - A single virtual device to store the collected roomInfo. I have this working but it's kludgy as commands don't return any values so you have to store everything in attributes

Any other ideas? Is there a way for an app to publish an API?

You could architect your applications in a Parent-Child model. The Parent App would create each child app. Once this relationship is established, it is fairly easy for the Parent to make calls into the child, and vice versa, IIRC.

Apps can define callable HTTP endpoints and pass information back and forth using them without having a parent-child relationship or even being on the same hub or LAN (similar to what MakerAPI does). That being said the parent-child is an easier implementation.

2 Likes

Thanks for the quick response! Do you happen to have an example of this?

There are also location events. See [Groovy] getting data from app - #2 by bravenel

Not sure about your use case but it’s also possible to dump a json in a file file and read it back using the File Manager API.

Lots of ways.

1 Like

This one primarily shares information with another instance of itself on another hub so it's both the the provider and subscriber (also has a NodeRed endpoint in it).

Wrote it before HubMesh could support Hub Variables directly, so some of its functionality is no longer needed but the code is still running on my 4 hubs.

1 Like

Thx all for the helpful info. I was able to get things working via Location Events (Thanks for that idea @hubitrep ) but I'm also taking your collective advice and migrating my apps into a parent/child relationship.

Quick question on that front: can child apps of the same parent communicate with each other (something like parent. findChildByAppName("someName").someMethod()?) or should all of the shared information be stored with the parent?

1 Like

You'd have to write the findChildAppByName method to bring back the child ID, but essentially yes.

1 Like