Looking for thoughts on using a persistent variable

Morning all.

I am working with @gmhanna on a THR project, and one of the requirements is for the Tablet to be “location aware” - in other words to know where it is, and therefore have some visibility or controls restricted based on what room the tablet is installed into.

I have created a new Plugin and Device called “ContextAware” that has the capability of Location, so we can hold a string that defines the location, and so the setting can be persistent between launches/reboots and so on, and be specific to the Tablet as it is set through the settings page. It works great.

BUT - we’d like to be a little more creative… we’d like to detect if the Location is not set on launch, and have the user set the location INTO the Device Setting (to allow it to be persistent). And then under a PIN number, we’d like the ability for an admin user to be able to change the Location Setting at Run Time.

But I think we have a problem that the Device Settings cannot be written at Run Time… only through the Designer, or by using the Settings Page on the Tablet… What I think we want is a function like App.SetDeviceAttribute that is more like App.SetDeviceSetting to allow us to change a device setting at Run Time.

I know that another way to achieve the persistence we want is to move the variable off the device and into a Raspberry Pi or something running some Python or something that would allow our Tablet to read/write its own location using an external device, but it would be neater if we could set the device settings at run time in a script.

Are we barking up the wrong tree, or is there a solution to this ?

thanks

If you want a changing variable to be persistent, then it has to be “remembered.” This isn’t possible for software and so it requires hardware. Once I got things set up, I think it’s neater to have that central piece of hardware to do all the syncing. RPi or a hub, they are pretty affordable, and now the door is open for all kinds of other persistent data to bring in. You can even create a dashboard showing the status of all your devices.

Hi Greg. Thanks for your thoughts. Though it’s not strictly true that persistence needs to mean additional hardware. All kinds of Apps store data in a persistent cache on the device. As I suggested in my earlier post if we could change the device settings at run time in a script (without having to swipe right and go into settings) then that would work.

But you’re right as well. If we can’t do that then I think we are left with a hardware solution.

@Martyn_Barnett Yes you’re absolutely right - I was very short-sighted in my comment. I’m trying this again with a more open mind and if I see this clearly, what you’re doing by swiping and going into settings to change something is basically changing the .hrp, saving it, and reloading it. All the device settings have to be read during the startup of the app. You’re wanting a way to do that during runtime. Read the device settings again while the app is running, without having to swipe. Have you tried App.Refresh or App.RefreshDevice?

But now I’m thinking this through, refreshing doesn’t take care of the “saving” part.

Many people use virtual devices or variable stores on their home automation controller to store data. Whether it be SmartThings, Hubitat, Home Assistant, HomeSeer, Vera, or Fibaro. They all have ways to create virtual devices. I would recommend looking into something like that.

2 Likes

Thanks for chiming in @bill, I was trying to force something that I knew wouldn’t work. I personally do what you’re describing - I use my ISY to store state variables and that directly integrates with HR.

This may not be possible, but I am still new to Home Remote.

Maybe it is possible to write a Javascript that reads an external file placed on the tablet? I know that code running on browsers will generate a security violation, but would this work on Home Remote’s implementation of Javascript?

Hi all… thanks for your comments guys… your contributions are always welcome here and your input is valued.

Ok, so we… (@gmhanna and I) have resigned ourselves to using an external hub for persistent variable storage.

@gmhanna has created a virtual device in his SmartThings account, and we confirm that this is visible in THR… so far so good.

BUT… the problem we now have is that although the Virtual Device we created in SmartThings had Attributes for variables such as textInput, we can’t seem to create a Capability in THR to set or retrieve that variable.

I am guessing its because the handlers inside the code implementation of SmartThings inside THR does not contain all of the permutations of all of the virtual devices and their associated variables into the handlers in the code…

So we need a steer on what IS implemented because of course we can’t see the code (unlike a Plugin)…

We need a Capability that allows us to SET and READ a string… we’re ok with Switch On and Off, but we need to move beyond the Switch to find a virtual device that is implemented that has a string attribute.

Is this making sense?

thanks in advance.

Sounds like a job for a Vera hub with the multistring plugin.

Hi John. Yes agree. If there was a VERA hub in this project I could do what we want in a few mins. I’m an advanced Vera plugin creator. But this project has SmartThings and I’m not so familiar.

Thanks.

1 Like

Not the best but when I had smartthings, I used a virtual dimmer. In my case, I used the dimmer values to sync my Home Remote tablets to represent the activity I was using.
For example:
0 -off
1 - FireTV
2 - spotify streaming
3 - turntable
4 - DVD player
…and so on.

That was my work around.

Hi mate… I think that could work actually… this would give us different levels of access. thanks !

I’ve asked @gmhanna if he can set up a virtual dimmer in ST and I will have a play from the THR end

thank you

1 Like

You can manually add your custom SmartThings attribute textInput to the Attributes property on the Home Remote device object. Don’t add it as a Capability on the Home Remote Device Object. It must be added to the Attributes property.

Thanks all for the suggestions. In the end we used a SmartThings Virtual Dimmer with the range 0-100, and used good old fashioned Binary to set/clear a set of flags that gives us the persistence we were looking for. Solved. thanks