How to NOT show state.variables

@bravenel, @mike.maxwell

I'm working on a driver that has lots of state variables for calculations.
Each one appears under the 'state variables' column on the driver page.
Like this...

Is there any way to hide some of these as they could be confusing to the user?

Andy

There isnt a way to hide them, but if you give then acronyms for names they may be less likely to read them.
The other thing you might consider is combining related attributes into map elements:
[Wind:[wcf:12.72,wn:no data,wsf:1.0,wcn:no data]]
This will take better advantage of the horizontal display area that you have available.
Referencing these is simple as well wind.wcf and wind.wcf = 12.72

2 Likes

Just to capture the request, would you want a hidden property for a state variable?

Not saying we will do it, but curious the use cases.

If its more of how we display states. Then that is a ui issue.

But if its hiding a value from the end user, that's a different situation.

@patrick

Hi Patrick
If you look at the screenshot in my first post you can see lots of state variables showing on the driver page
I would like to hide selected ones (or all of them) from the user

Not just the value but the actual variable too

With the driver I'm writing, it creates lots of state variables for calculations ..
It just looks a bit messy and, I think, could confuse with them all on display

Thanks for the consideration

Andy

1 Like

I could see this being useful for marking out (*******) API key's, passwords, etc in state variables for Apps and Devices.

+1

Encrypt and decrypt methods will be in the next release.

5 Likes

@Cobra did you ever find a way to hide the state variables?

No, it’s not possible.

However, as a work around you can define it in a method as a normal variable not a state.variable and use getMethod() to call it
Only good for reading it rather than updating it though (as far as I know)

Edit: you might be able to set it via calling the method with an input variable

E.g method(var)

def variable = var.value
return = variable

Andy

Thanks for confirming.
I'm not sure I understand your workaround. I need to be able to access and update the variable from multiple methods. I thought this was only possible with state variables.

@stephack
Stephan, I sent you a PM

Andy

Just encrypt them on write, decrypt on read....

Thanks @mike.maxwell , but I meant to hide it from the device page altogether and not just mask the value.

Googling lead me to

import groovy.transform.Field
@Field String variable = "default"

Any downsides to having a "global" variable this way?

1 Like

No, we use them.

1 Like

@mike.maxwell, @stephack, @Cobra

Sorry to bump such an old thread...

I am working on some modifications to one of my drivers and it will involved storing a very large JSON string into a state.variable. I would really rather not clutter up the UI with such a large state variable.

I am just curious if anyone has found a way to prevent the display of a specific state.variable on the web UI? Any other options available to persist the data in question?

Dan
@stephack’s code should work for you...

So sudo code would be...

@Field String yourVariableName = yourJsonResponse

Then the json data would be in ‘yourVariableName’
Which would be equivelant to a state.yourVarableName which you can use anywhere in the driver or app.

Andy

1 Like

Thanks Andy. And just to be sure... the data will persist like a state.variable in the Hubitat Database? I want to make sure that it persists through a hub restart, for example.

I haven’t actually tested it with a reboot. (But I believe so)
Easy enough to test this though..

Just add something to an existing driver setup a log statement to log it and reboot! :slight_smile:

1 Like

Declaring variables that way will stay yes. I use this method in a few drivers including my Network UPS driver as an example. Only issue is these are static and you cannot update them once declared.

Hmmmm, this is a little concerning. Maybe I will simply parse the huge JSON object and keep the bare minimum that is required for my driver. That would probably reduce the size by a very large percentage and not clog up the UI too much.

Thanks!

Is there a reason you need to keep it? Can you get re-query it if you need it?