How to set z-wave device configuration via REST api?

I am in the process of writing an application to handle the security side of things for my smart house - users, secure logins, etc. It doesn’t actually need to directly interact with OpenHAB except in one specific area: setting entry codes on my smart locks.

I can GET information from OpenHAB quite easily, parsing out what user numbers and door codes are in use, but my experiments with trying to PUT information in have failed rather spectacularly. Using the REST API user interface, “/things/{thingUID}/config”, I PUT this configuration:

{
"usercode_label_2": "user two",
"usercode_code_2": "12345"
}

…which set absolutely everything in the lock to blanks, from codes to the node ID (which it turns out you need, who knew). I managed, by sending the entire response body I previously got from /things/{thingUID}, to set it all back to normal… but I’m rather afraid to try again, in case I can’t rescue it. Thus, my question:

Where did I go wrong? What is the minimum amount of information I can send to set a given configuration value?

The UIs all use the REST API so if you can do that through HABmin you should also be able to do it with the REST API. @chris might be able to help if you posted more information. What model of lock? What command are you using to access the API?
There are many places for this to fail and most volunteers here do not relish playing guessing games.

1 Like

It’s an older Z-Wave lock, a Kwickset 914TRL; the curl statement the REST API gave me was:

curl -X PUT --header "Content-Type: application/json" --header "Accept: application/json" -d "{\"usercode_label_2\":\"user two\",\"usercode_code_2\":\"12345\"}" "http://127.0.0.1:8080/rest/things/[zwave device uid]/config"

…though I just used the REST API interface, entering the information and clicking “Try it”. Doing so set every setting, id, etc. to a blank. My error obviously exists in the command I’m sending, via the PUT command; HABmin can correctly set the information I need, so it’s not a problem with the API. The lock receives the command and sets the values correctly, so it’s not a problem with the lock or the Z-Wave network.

Given that the configuration values I want to set are “usercode_label_2”, which I want to set to “user two”, and “usercode_code_2”, which I want to set to “12345”, I would assume that command should work, but it didn’t. Did I use incorrect syntax? Do I need to pull all the values first, change the one(s) I want to change, then send the whole thing back?

Why not just use the browser debugger to see what HABmin is sending and then replicate that.

1 Like

Sigh. Obvious solution is obvious. Thanks! That sorted it. I’m not sure what happened the first time I ran the command, but using the HABmin command got it done.