[SOLVED] Schlage Lock add usercode

I have installed the latest OpenHAB 2.3 and the zwave-2.4.0-SNAPSHOT binding. The lock shows secure connection and I can add codes with HABMIN. I have been messing with curl commands and the API. I have set the status on/off for the lights and lock. How can I use curl to add and remove usercodes from the lock?

{
    "statusInfo": {
      "status": "ONLINE",
      "statusDetail": "NONE"
    },
    "editable": true,
    "label": "Lock",
    "bridgeUID": "zwave:serial_zstick:1651146928c",
    "configuration": {
      "usercode_code_27": "",
      "config_10_1": 3,
      "usercode_code_28": "",
      "usercode_code_29": "",
      "doorlock_timeout": 0,
      "group_1": [
        "node_1"
      ],
      "config_12_4": 499,
      "config_16_1": 4,
      "usercode_code_23": "",
      "config_14_4": 166,
      "usercode_code_24": "",
      "config_18_1": 1,
      "usercode_code_25": "",
      "usercode_code_26": "",
      "usercode_code_20": "",
      "usercode_code_21": "",
      "usercode_code_22": "",
      "action_heal": false,
      "config_7_1": 0,
      "config_9_1": 3,
      "config_3_1": -1,
      "usercode_code_30": "",
      "config_5_1": -1,
      "binding_cmdrepollperiod": 1500,
      "config_11_1": -1,
      "usercode_label_3": "test",
      "action_reinit": false,
      "config_13_4": 223,
      "config_15_1": 0,
      "usercode_code_16": "",
      "usercode_code_17": "",
      "usercode_code_18": "",
      "usercode_code_19": "",
      "action_failed": false,
      "action_remove": false,
      "binding_pollperiod": 86400,
      "usercode_code_7": "",
      "usercode_code_8": "",
      "usercode_code_9": "",
      "usercode_code_3": "2A 2A 2A 2A 2A 2A 2A 2A 2A 2A",
      "usercode_code_4": "",
      "usercode_code_5": "",
      "usercode_code_6": "",
      "usercode_code_12": "",
      "config_8_1": 3,
      "usercode_code_13": "",
      "config_6_4": 117440512,
      "usercode_code_1": "2A 2A 2A 2A 2A 2A 2A 2A 2A 2A",
      "usercode_code_14": "",
      "usercode_code_2": "2A 2A 2A 2A 2A 2A 2A 2A 2A 2A",
      "usercode_code_15": "",
      "config_4_1": 0,
      "usercode_code_10": "",
      "node_id": 5,
      "usercode_code_11": ""
    },
    "properties": {
      "zwave_class_basic": "BASIC_TYPE_ROUTING_SLAVE",
      "zwave_class_generic": "GENERIC_TYPE_ENTRY_CONTROL",
      "zwave_neighbours": "1,3,4",
      "zwave_frequent": "true",
      "modelId": "BE469",
      "zwave_version": "113.22",
      "zwave_listening": "false",
      "manufacturerId": "003B",
      "manufacturerRef": "6341:5044",
      "dbReference": "303",
      "zwave_deviceid": "20548",
      "zwave_nodeid": "5",
      "zwave_lastheal": "2018-08-07T07:58:02Z",
      "vendor": "Allegion",
      "defaultAssociations": "1",
      "zwave_routing": "true",
      "zwave_beaming": "true",
      "zwave_secure": "true",
      "zwave_class_specific": "SPECIFIC_TYPE_SECURE_KEYPAD_DOOR_LOCK",
      "zwave_manufacturer": "59",
      "zwave_devicetype": "25409"
    },
    "UID": "zwave:device:1651146928c:node5",
    "thingTypeUID": "zwave:schlage_be469_00_000",
    "channels": [
      {
        "linkedItems": [
          "ZWaveNode005_DoorLock"
        ],
        "uid": "zwave:device:1651146928c:node5:lock_door",
        "id": "lock_door",
        "channelTypeUID": "zwave:lock_door",
        "itemType": "Switch",
        "kind": "STATE",
        "label": "Door Lock",
        "description": "Lock and unlock the door",
        "defaultTags": [],
        "properties": {
          "binding:*:OnOffType": "COMMAND_CLASS_DOOR_LOCK"
        },
        "configuration": {}
      },
      {
        "linkedItems": [],
        "uid": "zwave:device:1651146928c:node5:alarm_raw",
        "id": "alarm_raw",
        "channelTypeUID": "zwave:alarm_raw",
        "itemType": "String",
        "kind": "STATE",
        "label": "Alarm (raw)",
        "description": "Provides alarm parameters as json string",
        "defaultTags": [],
        "properties": {
          "binding:*:StringType": "COMMAND_CLASS_ALARM"
        },
        "configuration": {}
      },
      {
        "linkedItems": [
          "ZWaveNode005_BatteryLevel"
        ],
        "uid": "zwave:device:1651146928c:node5:battery-level",
        "id": "battery-level",
        "channelTypeUID": "system:battery-level",
        "itemType": "Number",
        "kind": "STATE",
        "label": "Battery Level",
        "defaultTags": [],
        "properties": {
          "binding:*:PercentType": "COMMAND_CLASS_BATTERY"
        },
        "configuration": {}
      }
    ]
  }

That’s a very interesting question. Normally, you would either enter them through Habmin or PaperUI. Or you could enter them into the device’s XML file. When setting a code through Habmin, you can see something like this being sent…

usercode_code_5: 123456

Sending the following through the REST API seems to work, and the response has the numbers sent, but when checking the config and in Habmin, the code is always displayed as 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A.

{ “usercode_code_5”: “123456” }

To do this through the REST API, you’d need your device’s ThingUID (i.e., zwave:device:55555:node100). Then you’d do something like this…

val String updateResponse = executeCommandLine("/bin/sh@@-c@@/usr/bin/curl -o /dev/null -s -w \"%{http_code}\" --connect-timeout 10 --max-time 10 -X PUT --header \"Content-Type: application/json\" --header \"Accept: application/json\" -d \"{ \\\"usercode_code_5\\\": \\\"123456\\\" }\" \"http://localhost:8080/rest/things/zwave:device:55555:node100/config\"",10000)
logDebug("Rules","Test: updateResponse=[{}]",updateResponse)

I’m pretty sure there can’t be gaps in the codes, so if you have codes 1-3, don’t try a code 5 or it won’t work. Do code 4 instead. To clear them, send…

{ “usercode_code_5”: “” }

You can verify there is a code in that slot by checking…

http://<your OH server>:8080/rest/things/<the Thing UID>

Thank you for asking for this. I very rarely need a guest code, but now I can just ask Alexa to enable/disable it, instead of punching a code into the locks!

2 Likes

That was my issue. I wasnt using the /things/{thingUID}/config but trying to use /things/{thingUID} and wiping out all configuration. That did the trick.

1 Like

Hi @5iver thanks for this, I was starting to wonder if my skills as a dev were in question. I was putting numbers that stayed the same in the last few slots which explains why it wasn’t working. I’d have user_code_1, user_code_28 … 29,30. I’m going to try 1…4 instead as it seems to be the solution. One question, I’ve had to push the entire configuration for it to work, otherwise it would wipe out the rest of the values. Did you see this happen ever?

Nope, never. The only oddity I saw was that walking out of the house after playing with this, the door wouldn’t lock with the outer button press. The code needed to be put in to get it to lock. But after the one time, it was back to normal.

I plan to add a check in my rule for the next available slot, which shouldn’t be to hard to do. I also want to add in a few extra codes then manually remove one in the middle of the group, to see if the lock shifts the slot number. I’m guessing it must, in order to avoid gaps. This would also affect any rules using the codes, since the slot numbers would be changing.

You are very welcome! I really didn’t think I would use temporary codes but now I’m ready for when we do. I setup a rule to send a temporary code to our phones when a switch is thrown. A timer then runs to cancel it.

@5iver I extend my thanks too! Just set up all my codes to be disabled or enabled via this method. I was waiting for a channel(s) to be added to the Zwave security features for this, but this works just fine. Now I know how to do other REST things from the rules too. Awesome!

1 Like

I can confirm this works for the Kwikset SmartCode 888.

1 Like