Remove user variables from a device

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…


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.

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

Removing a variable is possible, but relatively complicated and dangerous.,6277.0.html

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+

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.

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.

Theoretically it’s possible using ModifyUserData, but it’s relatively complicated and risky. I haven’t tried it so I don’t know if it works or not.

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?).

You could uncompress and edit /etc/cmh/user_data.json.lzo.

… 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?

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? :slight_smile:

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)

Follow these steps:

[ol][li]Stop LuaUPnP:
[tt]/etc/init.d/cmh stop[/tt][/li]
[li]Make a backup of you current user_data (/etc/cmh/user_data.json.lzo)[/li]
[li]Uncompress user_data
[tt]pluto-lzo d /etc/cmh/user_data.json.lzo /tmp/user_data.json[/tt][/li]
[li]Remove the variables you want (see how variables look in the user_data in the code below)[/li]
[li]Validate your new user_data on[/li]
[li]Compress the new user_data
[tt]pluto-lzo c /tmp/user_data.json /etc/cmh/user_data.json.lzo[/tt][/li]
[li]Start LuaUPnP
[tt]/etc/init.d/cmh start[/tt][/li][/ol]

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 If these steps are made, then the whole operation is pretty safe.

"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 } ],

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:
Voting +1 for a convenience method to delete variables, like so: luup.variable_delete(service, name, device_id)

[quote=“mcvflorin, post:14, topic:169472”]Follow these steps:

[ol][li]Stop LuaUPnP:
[tt]/etc/init.d/cmh stop[/tt][/li]
[li]Make a backup of you current user_data (/etc/cmh/user_data.json.lzo)[/li]
[li]Uncompress user_data
[tt]pluto-lzo d /etc/cmh/user_data.json.lzo /tmp/user_data.json[/tt][/li][/ol][/quote]

Do I need putty for the last code or run this in the terminal?[/list]

Any syntax errors (accidental edits) and your Vera will NOT restart … be careful.

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.

This worked fine on my Vera3:


Note that the value is left empty, which is the same state as the boolean “nil”. (Using “nil” just put that in the field.)

Best Home Automation shopping experience. Shop at getvera!

© 2021 Ezlo Innovation, All Rights Reserved. Terms of Use | Privacy Policy | Forum Rules