I was developing a custom app and went into the Settings and then when I selected Hub Variables I got UNEXPECTED ERROR. I found a reference to fix it but it wants me to hit the button Remove Hub Variables in the lower right of the Hub Variables Status page. Can I do something better than this?
Thanks
Probably not, but unless you have any hub variable connectors created (and then I think Bruce might be able to find a workaround for you...though I'd think twice about whether you really need a connector first), there is no effect. It doesn't remove your hub variables; this app is just an interface into that feature.
So, with that caveat, it is perfectly safe.
And if you still don't trust that, just take a backup first.
I appreciate your response. This happened about 8:30PM and I had made a local backup around 3:30PM. I have about 30 Hub Variables and I had added another handful after 3:30PM so restoring those is not a bigy. It sounds like I really do not need to use Hub Variables App??? Did I understand that correctly? If I follow you I can use these variables and they will not show up under Settings->Hub Variables. So without the page titled Hub Variables how would I create and init them? Am I totally confused?
Thanks
There seem to be a few misunderstandings:
I meant take a backup now before you perform the step above in the event that you do not trust it to be non-destructive (but, again, aside from variable connectors, I assure you it is--this just provides you an out if you don't want to trust that) -- i.e., if you somehow end up even worse, you can at least get back here.
Technically, you do, but it automatically adds itself whenever needed. Normally that's the first time you access this feature, but it would also happen if you happen to remove the app as you may want to do to get rid of this error.
Again, the only caveat is that hub variable connectors are child devices of this app, and removing this app removes all of its child devices (as it does for any app). So, you'd need to re-create those connectors and re-add them to any app you were using them in if you were using them at all. Hub variable connectors are not really needed anymore, and chances are you are not using them, especially if you have no idea what this means (this is distinct from just using a variable directly in an app, and the reason that many apps now support this is the reason you don't really need connectors anymore).
Settings > Hub Variables will never disappear. The next time you go to this page, the app (which is just the front-end to this feature) will re-add itself, and all your old variables will still be there.
For the most part, you can ignore the fact that the user interface to this feature is really an app at all; it just comes into play when odd things like this error crop up....
I am under the assumption that setting a variable during a callback that I subscribe to will not be preserved after the callback is done. When that next callback occurs I need to have persistent variables in some cases. I noticed in the documentation under Hub Variables->Connectors is a bolded section that says the direct use of a variable is preferred over a connector if the app offers direct use. I am used to a C++ environment in which global variables are those outside of the routines and therefore not stack variables but have a fixed location. Am I totally out to lunch?
Thanks
It sounds like there may be additional confusion.
Hub variables is a user-facing platform-level feature in Hubitat that allows sharing named variables -- and their values -- between different apps on the hub. This is an alternative approach to using virtual devices and other workarounds creative users have resorted to in the past (for example, you can now use a Boolean hub variable instead of a virtual switch for values that have two states). Many apps offer the option to "restrict" their functionality based on the value of a switch and often variable, as one practical example of their use--besides just storing any data you want for whatever purpose. Other apps may allow you to read or write the value of a hub variable as part of its operation. Some users may show the value of these variables on a dashboard, as part of a push notification text, or for a variety of other purposes.
This is entirely distinct from any variable you create in Groovy code, e.g., in Apps Code or Drivers Code on the hub. "Global" variables in app or driver code requires some care on Hubitat given that app or driver code is not always running but rather "sleeps" between executions, wakes in response to a callback or similar (event handler, scheduled job, etc.), and again sleeps, making persistence of that value a concern. I would typically recommend the use of state
instead. This is a built-in map unique to that installed app or driver instance that is automatically retrieved for you when the app or driver wakes and written out before it goes back to sleep and available anywhere inside your code). There are other options, like static field variables (shared among all instances of the app or driver code) if this kind of persistence is overkill (these are reinitialized on hub reboot, re-saving of the app or driver code, etc.) or a poor fit for whatever data you need (it's serialized to JSON with the rest of the app data but totally fine for most reasonable uses).
The latter is not at all visible to users of your app, or at least not normally intended to be (they can peek at the internal data using the App Status page, but it's not editable or somewhere most people look except for maybe troubleshooting).
I suppose a hub variable could work for this latter use case, too, though it's generally overkill unless this is the kind of data the user may want to use elsewhere.
That helped... thanks. It sounds like it would be a better choice for me to use state (I just need persistence between consecutive callbacks). I will do a little research and see what I can do.
Thanks Again
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.