Storing Multiple values for an App

I writing my 1st App. It should be simple but I'm stuck on how to store more than one variable in a ChildDevice. I see how one variable is stored but I can't find or figure how to store more. I think it is likely a Map but the approach and syntax is beyond me.

Does anyone know of an example I could use to understand the approach and syntax?

Thanks
John

Is the child device using a driver that you wrote, or are you using a Hubitat-provided component (or virtual or otherwise standard) driver?

In general, you have free reign for a child device that you create--the app has full access to all (non-private) methods of that device. You could create a method that retrieves or stores values in the device's state if that is your goal (there is no direct access to state). I'm not sure any of the built-in component drivers provide methods for anything other than event generation (parse()), and I don't think any virtual device I've seen has anything at all besides (usually custom) commands for setting specific attribute values (both of these achieve the same outcome in different ways), so it depends on what kind of "value" you're trying to "store" and why.

I'm writing a simple App to calculate the DEW point from temperature and Humidity. I'm using the built in Virtual Temperature Device for the display of DEW.

As I read your reply I realized that the ChildDevice is the "Virtual Temperature Device".

So now I'm at a loss for how to store the:

  • Last temperature
  • Last Humidity
  • An probably the last DEW point.

Is storing them as "states" of my App a reasonable option or is it too hokey?

John

You won't be able to create them as attributes on the Virtual Temperature Sensor device since it doesn't implement the relevant capabilities (and attributes that come along with it), or at least you won't be able to do so reliably (I think I've heard of people who [ab]use the behavior where Hubitat does seem to temporarily store attribute values for attributes that aren't part of a declared capability or declared as custom attributes, but they'll disappear later).

Since it's your app, if storing it in the app's state works for you, that's certainly an option. :slight_smile: If you want them in a device that already has these capabilities, something like Virtual Omni Sensor might work (it has a bunch more than you probably really need...), or you could use multiple child devices of different types (one for humidity, one for temperature, etc.) or write a custom device driver tailored to your exact capability/attribute set. The biggest disadvantage of keeping them in your app's state is that users won't be able to use these values in other apps like they would with device attributes (in the form of event subscriptions, current value comparisons, and whatnot). But again, since it's all your code...whatever works for you! (Or whoever you expect to use the app, I suppose.)

Thank your insight has been very helpful.

Its well beyond me at the moment but I could see a couple of Virtual Devices being useful.

  • Virtual "Custom" Device
  • Virtual "Storage" Device (with multiple capabilities say 10 or 12)

John