Use Dashboard to Manage Lock Codes

A question that comes up frequently is how to manage lock codes from a Dashboard. This is actually fairly easy with a Rule Machine rule and a Global Variable Connector.

First, each lock code is defined by 3 values: the slot number (Code position), the code itself (PIN code), and a name (Name) for the code. These can be set from a lock's device page:

Screen Shot 2020-12-26 at 7.49.47 PM

What we want is a tile on a Dashboard to set those three values for a particular lock. This will look like this:

Screen Shot 2020-12-26 at 7.45.50 PM

The string in the center of that tile can be set, and contains the 3 values. In this case 3 is the slot number, 4567 is the code, and Jason is the name. These 3 values must be in that order and separated by colons, as shown.

Create a Hub Variable of type string. In our example this is called Lock Code. Also create a Connector for it, which creates a virtual device also named Lock Code. In the Dashboard we include this device, and it is selected for the desired tile. The template for the tile is Variable String.

Finally, create this rule below. Note that it has 4 local variables defined.

Some notes about this rule: The action after the IF is a Custom Action (setCode) on the lock to set the codes for. The custom action has 3 parameters. The first parameter is a number (%slot%), and the other two are strings (%code% and %name%). The action after the ELSE is also a custom action (deleteCode) on the lock, with one parameter. The parameter is a number (%slot%) . The lock used in this rule is called "My Lock", which is a virtual lock I keep around for stuff like this. At the end of the rule, we set Lock Code to display "slot:code:name:" so as to hide the previously set lock code and show what to do next time.

Screen Shot 2020-12-26 at 9.00.22 PM

After the string shown above (3:4567:Jason) was entered into the Dashboard tile, the resulting lock code was created:

Screen Shot 2020-12-26 at 7.45.32 PM

To remove a lock code, enter the slot number and 0 separated by a colon, like this: 2:0.

Screen Shot 2020-12-26 at 7.59.52 PM

This will erase slot 2, leaving the lock in this state:

Screen Shot 2020-12-26 at 7.59.12 PM

One final thought: Perhaps this Dashboard should have a Pin to protect access to it, given that it can create a lock code with which the lock can be unlocked. You can do this in the Dashboard app for this Dashboard under Advanced options:

13 Likes

Tagging @tim5.

1 Like

Useful. Thanks.

For those that prefer to use webCore, I reverse engineered the device driver and added an alternate set routine (the one the dashboard needs conflicts with WC).

You can import it using: https://raw.githubusercontent.com/thebearmay/hubitat/main/dashVariable.groovy

1 Like

I'm trying to follow these instructions and I got to "create a Connector", but I don't know what that is. What is a "Connector" and how do I create one?

A connector is a variable that will be created as a device and usable by other apps.

You create it by first creating a variable in your rule, and then once the variable has been created, clicking on the “Create” link in the “Connector” column for the variable.

Once the variable has been made into a Connector, it will appear in your device list as such:

Hope that helps!

3 Likes

Thanks @Sebastien - and also for anyone following along - remember to add permission to the virtual device to the Dashboard app for the new "LockCode" otherwise it won't show up in the dashboard. (this has caught me out more than once).

2 Likes

I'm having a problem with the "Actions to run". The second action

"IF (Variable temp(2) = slot(FALSE) Exit Rule

seems to be an "IF" "Variable" type rule, but if I select "temp" as my first variable, "slot" doesn't show up in the list for the second variable. I think maybe it's because "slot" is a number whereas "temp" is a string. Any thoughts about what I'm getting wrong?

No, in this case "slot" is a string. This is checking for the "slot:code:name" value put in by the rule itself. So you should select set variable temp to a string, and the string value is "slot".

1 Like

I can't figure out the setCode Custom Action on the IF. This is a screenshot:

It looks like my Lock only has two actions "locked" and "unlocked" - or I'm looking in the wrong place for the Custom Action.

What you're showing is a Conditional Action setup, not a Custom Action setup.

Call me crazy but to me "IF" is a conditional action, so I'm expecting to select condition first, then after I've selected the condition - then select the action. I'm new to this but I'm finding this backwards way of thinking hard to get my mind around.

1 Like

Ok so I managed to do "SetCode" but can't seem to do IF (Variable code(0) != 0 (F) (FALSE)) THEN. I tried it twice, so now I have two incorrect SetCode lines with no IF. It looks like this:

It seems to be stuck halfway adding a conditional, but what I really need to do is go back and delete the two SetCodes I've put in then and the IF THEN. Do I really have to delete the whole thing and start again?

Just delete the action that is messed up. Here is the setup for that Conditional Action below. You want Capability Variable:

1 Like

When I run this rule I get this in the log:

dev:402020-12-28 03:45:34.276 pm errorjava.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer (setCode)

dev:402020-12-28 03:45:34.144 pm debugsetCode- slot

app:852020-12-28 03:45:34.075 pm infoAction: setCode(slot, code, name) on Lock Front Door

Because slot is defined as a number, it needs to be converted to a string to pass to SetCode.

Show your rule. Use screenshots, not copy paste.

I tried changing the first parameter to "temp" instead of "slot" because temp is a string. I got the same error. I'm thinking my rule is actually passing the value "temp" instead of the value of the temp variable to the SetCode command. How do I set the parameter to use the variable name, should I use "%slot% for the parameter? This is the rule:

Did you set some value into the LockCode connector (or variable) for it to work? Such as "1:1234:Name"... Show the local variable section of the rule.

Sorry - now I see you already explained that.