How to change preferences by script?

Hi @ all,

I would like to know if there is a way to update the edge driver preferences via the script.

I’ve tried things like this:

device:set_field(device.preferences[id], value, {persist = true})

But that doesn’t seem to work. The settings in the app still remain the same.

I would like to synchronize or manipulate them afterwards, as I would like to add Configuration.DefaultReset("") to my Z-Wave device driver, which works, but the settings then become asynchronous …

Thank you in advance.


No, the preference’s value cannot be modified within the driver’s code, it’s only done through the user input in the app.
You can use the function try_update_metadata, it overrides the current device profile with the one you use in the parameter.
I’ll make some tests to see what happens with the preferences if we send the same profile name…

I would also be interested in this feature, it’s something groovy can do (for both SmartApps and Device Handlers), it would be of great help to extend this feature to both SmartApps and Drivers in the new platform to effectively migrate the existing implementations. There are lots of use cases for this for both SmartApps (which I’ve already submitted requests and use cases in the past) and for drivers, for example with LAN driver that auto detect a camera feature has been enabled directly on the camera, this now needs to be reflected in the device settings. Perfect example if motion detection options. The user can select options X, but then the driver detects that the settings on the camera were updated to Y, it now needs to update the settings so that they are in sync. This is the current implementation in the groovy DTH’s.

So, after making some tests I found out that even using try_update_metadata doesn’t reset the preferences unless you use different names in the other profile, so, I’ll check this with the internal team.

Thank you for providing your feedback about this, @RBoy.

@nayelyz OK, I am curious about your results.