Ezlo http API how to set door lock code using method hub.item.dictionary.value.set

Hello if anyone has a working example of setting door lock code via ezlo http api that would be great, I have scanned the entire community and the examples available are for simple bool toggle using method hub.item.value.set however there is not a single example on how to use method hub.item.dictionary.value.set and sending http json.
my code here gets a response that is blank can anyone please correct the format of my json
REQUEST

{
"method" : "hub.item.dictionary.value.set" ,
"id": "_ID_" ,
"params" : {  
    "_id":"63978315d53954635316b0e1",
    
    "value":{
    "code" : "3395",
    "mode":"enabled",
    "name":"person"
    }  
}
}

RESPONSE

{
    "error": null,
    "id": "_ID_",
    "result": {}
}

device item definition

_id: "63978315d53954635316b0e1"
deviceId: "_ID_"
elementType: "userCode"
elementsMaxNumber: 30
hasGetter: true
hasSetter: true
info: Object {"zwave.references":[{"channel":0,"class":99,"managing_commands":["USER_CODE_SET"]}]}
name: "user_codes"
show: true
userCodeModes:
0: "enabled"
1: "disabled"
userCodeRestriction: "^\d{4,10}$"
value:
1: Object {"code":"5544","mode":"enabled","name":"guy"}
2:
code: "1122"
mode: "enabled"
name: "ghhg"
valueFormatted: ""
valueType: "dictionary"

Hello @Wael_Ali,

If you’re interested, in the post below you will find detailed instructions on how to set up an HTTP client on your Ezlo hub so that you can send HTTP requests without having to send the JSON payload

They should look like

https://<ip>:port/v1/method/hub/item/dictionary/value/set?_id=63978315d53954635316b0e1&code=3395&mode=enabled&name=person

On the other hand, your API request should look like

{
    "method": "hub.item.dictionary.value.add",
    "id":"_ID_",
    "params": {
        "_id": "item_ID",
        "element": {
            "type": "userCode",
            "value": {
                "code": "1234",
                "name": "person",
                "mode": "enabled"
            }
        }
    }
}

So that should be fine. If you run a hub.items.list on that doorlock, do you not see the new pincode?

{
"method": "hub.items.list",
"id": "_ID_",
"params": {
"deviceIds": [
"**deviceId0** "
]
}
}

Provided you have correctly set up the HTTP client with the python file, the following http request


https://<ip>:port/v1/method/hub/item/dictionary/value/set?_id=63978315d53954635316b0e1&code=3395&mode=enabled&name=person

should do the same as the API request that you reference in your original post hub.time.dictionary.value.add.

See the following guide for that matter

Ezlo platform - How to use HTTP API commands aka Luup Requests.pdf (672.7 KB)

The empty response, although odd, does not seem to be catching any errors, which is why I asked if maybe you could see the pincode that you just created if you run a hub.items.list and put in the device_id. It should show the list of pincodes.

Let us know if that’s the case.

Hi @Thiago I just reviewed the code you sent again it works actually :grinning: i was missing element tag now I am wondering how someone would go about setting time limit for the code lock created the item.list shows the following

:
_id: "63978315d53954635316b0e4"
deviceId: "_ID_"
elementType: "array.daily_interval"
elementsMaxNumberPerArray: 30
hasGetter: true
hasSetter: true
name: "daily_user_code_intervals"
show: true
value:
2:
0:
startDateTime: "2022-12-13T16:07:54"
stopDateTime: "2022-12-13T17:07:54"
valueFormatted: ""
valueType: "dictionary"

Hi @Wael_Ali ,

If you want to set a daily restriction using the API tool you could use:

{
   "method":"hub.item.dictionary.value.set",
   "id":"_ID_",
   "params":{
      "_id":"63978315d53954635316b0e4",
      "key":"5",
      "element":{
         "type":"array.daily_interval",
         "value":[
            {
               "startDateTime":"2023-07-15T09:35:00",
               "stopDateTime":"2023-07-17T10:35:00"
            }
         ]
      }
   }
}

Note that _id= Daily restriction id. In your case: 63978315d53954635316b0e4
key = Code position. You would need to list the Device items to identify the code key.

1 Like

perfect thank you so much you are so helpful :star_struck:

1 Like

Anytime @Wael_Ali !

would there be a call that sets the time limit interval and the code at the same time?

We need to know the code key the restriction will be applied to, therefore, it’s necessary to add the Pincode first, identify the key number, and then set the restriction.

1 Like