The Vera Community forums have moved!

Advanced => Programming => General => Topic started by: usmampoer on October 31, 2011, 10:56:57 am

Title: Remove user variables from a device
Post by: usmampoer on October 31, 2011, 10:56:57 am
I have some code that will add a new variable to a device when I need to track specific information like the time that a door has been opened.

I create the variable using a luup.variable_set("urn:upnp-org:serviceId:HVAC_UserOperatingMode1", "UserState", "", 19)

Is there a way to remove these variables from the device when they are no longer needed...

Andre
Title: Re: Remove user variables from a device
Post by: futzle on October 31, 2011, 04:03:22 pm
Is there a way to remove these variables from the device when they are no longer needed...

No, so they're going to start cluttering up your device's Advanced tab over time.

That also means that you need to nominate a value (empty string, or "0" or something else reasonable) that stands in for "deleted", and when you read the variable check against this value as well as nil.
Title: Re: Remove user variables from a device
Post by: usmampoer on November 01, 2011, 09:06:13 am
Thanks for the reply, would it be reasonable to expect that the development team will consider this as a future "enhancement".

If it is that easy to add a variable should be just as easy to remove it from the data table

Title: Re: Remove user variables from a device
Post by: mcvflorin on November 01, 2011, 10:31:09 am
Removing a variable is possible, but relatively complicated and dangerous.

http://wiki.micasaverde.com/index.php/ModifyUserData (http://wiki.micasaverde.com/index.php/ModifyUserData)
http://forum.micasaverde.com/index.php/topic,6277.0.html (http://forum.micasaverde.com/index.php/topic,6277.0.html)
Title: Re: Remove user variables from a device
Post by: usmampoer on November 01, 2011, 04:53:53 pm
Many thanks but not sure I have enough postings for me to try this......

I will wait for Micasaverde to offer this a new "feature" in U15+
Title: Re: Remove user variables from a device
Post by: usmampoer on November 02, 2011, 09:56:20 am
Thought about a workaround.....

Create a user plugin and use this to hold the various user created variables, does add some complexity to make sure that the naming conventions are good to "find" the correct variable for a specific device, might need to think of using the device name + device ID to create the variable. not yet sure how do that with string conjugation. and might not even be possible with luup.

Is it possible to create a variable name using something like ...

local name = "Sensor"+tostring(v)
luup.variable_set(SS_SID, name, somedata, v)

(where v is the device ID)

So if the variables get out of hand you should be able to delete the device and recreate the device. This will delete all user variables. In my case this is not a big issue I do not store long term variable so I will not lose valuable data, but it also smacks of bad programming techniques.

Title: delete variables
Post by: utz on November 14, 2011, 05:38:46 am
Is there a way to delete variables stored in a name space? For example, I can use the UI to create a new variable (the advanced tab). Is there a way to delete some? I know I can delete the whole device and create it again but I do not want to do that.
Title: Re: delete variables
Post by: mcvflorin on November 14, 2011, 06:26:40 am
Theoretically it's possible using ModifyUserData (http://wiki.micasaverde.com/index.php/ModifyUserData), but it's relatively complicated and risky. I haven't tried it so I don't know if it works or not.
Title: Re: Remove user variables from a device
Post by: utz on November 15, 2011, 05:53:30 am
ok, that looks complicated. I assume there is no easier way (e.g. edit a file/database on vera directly where the stuff is stored?).
Title: Re: Remove user variables from a device
Post by: mcvflorin on November 15, 2011, 09:43:25 am
You could uncompress and edit /etc/cmh/user_data.json.lzo.
Title: Re: Remove user variables from a device
Post by: Ap15e on November 15, 2011, 01:02:51 pm
... or write a Luup plugin, that removes variables (VRD - Variable Remover Device) - but joking aside: is there a specific reason why removing variables isn't implemented in MiOS?
Title: Re: Remove user variables from a device
Post by: mcvflorin on November 15, 2011, 01:44:42 pm
is there a specific reason why removing variables isn't implemented in MiOS?

Maybe it's harder to implement and it's not worth allocating time for it? We'll never know... though a Luup plugin that does this is possible. Any volunteers? :)

Title: Re: Remove user variables from a device
Post by: utz on November 16, 2011, 06:53:35 am
You could uncompress and edit /etc/cmh/user_data.json.lzo.

Ok. So I could uncompress and edit. After edit do I have to restart some services? Or reboot? Can I copy the old file in place as a backup in case I make a mistake and destroy the whole system? How save is this operation?

In general, I would say you could just add a variable delete button to the advanced tab (I know, you probably don't like the idea because you would have a lot of dopes that delete variables and then complain that the system is not working)
Title: Re: Remove user variables from a device
Post by: mcvflorin on November 17, 2011, 06:37:48 am
Ok. So I could uncompress and edit. After edit do I have to restart some services? Or reboot? Can I copy the old file in place as a backup in case I make a mistake and destroy the whole system? How save is this operation?

Follow these steps:
I'd say that the most important steps are to make a backup of the old user_data and to check your new user_data on http://jsonlint.com (http://jsonlint.com). If these steps are made, then the whole operation is pretty safe.

Code: [Select]
"states": [
{
"service": "urn:micasaverde-com:serviceId:VistaAlarmPanel1",
"variable": "PluginVersion",
"value": "2.32",
"id": 0
},
{
"service": "urn:micasaverde-com:serviceId:VistaAlarmPanel1",
"variable": "DebugMode",
"value": "1",
"id": 1
},
{
"service": "urn:micasaverde-com:serviceId:VistaAlarmPanel1",
"variable": "NumPartitions",
"value": "0",
"id": 2
},
{
"service": "urn:micasaverde-com:serviceId:HaDevice1",
"variable": "CommFailure",
"value": "1",
"id": 3
}
],
Title: Re: Remove user variables from a device
Post by: wezzix on September 21, 2012, 07:02:34 am
The above steps works fine, apart from the validator that times out in my FF browser.
This link is more stable and provides option to format the json for easier reading: http://jsonformatter.curiousconcept.com/ (http://jsonformatter.curiousconcept.com/)
Voting +1 for a convenience method to delete variables, like so: luup.variable_delete(service, name, device_id)
Thanks.
Title: Re: Remove user variables from a device
Post by: TwannieM on March 28, 2015, 04:53:35 pm
Follow these steps:
  • Stop LuaUPnP:
    /etc/init.d/cmh stop
  • Make a backup of you current user_data (/etc/cmh/user_data.json.lzo)
  • Uncompress user_data
    pluto-lzo d /etc/cmh/user_data.json.lzo /tmp/user_data.json

Do I need putty for the last code or run this in the terminal?[/list]
Title: Re: Remove user variables from a device
Post by: RichardTSchaefer on March 28, 2015, 08:08:22 pm
Any syntax errors (accidental edits) and your Vera will NOT restart ... be careful.
Title: Re: Remove user variables from a device
Post by: aviddv1 on April 24, 2015, 12:26:16 am
I can confirm this method works on Vera Edge, but WTF Vera? How 'bout a little 'delete' button next to the user created variable that let's use do this easily? I'd even put up with an "Are you sure?" prompt.
Title: Re: Remove user variables from a device
Post by: Spanners on September 28, 2015, 06:52:16 am
I can confirm this method works on Vera Edge, but WTF Vera? How 'bout a little 'delete' button next to the user created variable that let's use do this easily? I'd even put up with an "Are you sure?" prompt.

BlueSmurf likes this.
Title: Re: Remove user variables from a device
Post by: OldChas on March 03, 2016, 04:44:00 pm
This worked fine on my Vera3:

http://<IP>:3480/data_request?id=variableset&DeviceNum=<id>&serviceId=<service>&Variable=<variable name>&Value=

Note that the value is left empty, which is the same state as the boolean "nil". (Using "nil" just put that in the field.)
Title: Re: Remove user variables from a device
Post by: Chelseagroup on February 18, 2019, 04:42:59 pm
Worked for me - Brilliant!
Thanks