Adding a way to set door codes - Part 1: Write a script
Setting door codes is a lot more complex than locking and unlocking. I will walk through the steps with a lot of detail.
- Write a 'script' to set the door code.
- Create 'helpers' to make it easy to select the door to use, the code slot, and to enter the door code itself.
- Use the 'helpers' in the script.
- Create a 'card' that uses the helpers and the script. This is like the lock card, but uses the helpers to get the door, code slot and door code.
Write a 'script' to set the door code
This may sound a little scary, and techie, but I'll walk you through it.
First - open up the Home Assistant - http://homeassistant.local:8123/, then go to 'Configuration in the sidebar.
This will bring up the "New Script" page
Enter the name for the Script (As soon and you put the name in, the 'Entity ID' will change to something very similar to the name you entered)
Change "Action Type" to "Call Service"
Now Select the 'Service' by clicking on the 'Service' beneath the "Action Type"...
and select 'lock.set_usercode'
You now need to scroll down on the page to see the "Service data"
We will 'hardcode' the data for this right now. Later, we will have a way to enter the data from a more friendly web page, or your mobile device.
I will use similar values to the ones I used in Setting a Code. I am changing the usercode, because I want to test it on the lock, so it needs to change to test it.
- node_id: 2
- code_slot: 4
- usercode: '2112'
Enter this as the "Service Data"
Now select "Save Script", Now select the 'back' arrow from the upper left 
You will now see your new script in the list

You will now see your new script in the list
Select "execute" to run the script. If you watch the Z-Wave dongle on the Raspberry Pi, it should light up for a bit. Now you can try the code on your lock to see it work. Remember, it sometimes takes a few seconds.
Now we will create the 'helpers' so we have a way to tell the script which door (node_id), code slot and usercode to use.
Comments
Post a Comment
Thanks for the comment!