Difference between revisions of "How to use Dashboard to Manage Lock Codes"

From Hubitat Documentation
Jump to: navigation, search
Line 3: Line 3:
 
The lock driver built-in to Hubitat Elevation defines each lock code with 3 values:
 
The lock driver built-in to Hubitat Elevation defines each lock code with 3 values:
  
* Slot Number, which is the code position in the lock.
+
*Slot Number, which is the code position in the lock.
* The Lock Code itself, which is your 4 to 6 digit PIN code.
+
*The Lock Code itself, which is your 4 to 6 digit PIN code.
* A name for the code.
+
*A name for the code.
  
 
Using Hubitat Dashboard, you can create a Dashboard tile to set each of those values for a particular lock.
 
Using Hubitat Dashboard, you can create a Dashboard tile to set each of those values for a particular lock.
Line 11: Line 11:
 
'''<span style="color: red;;">WARNING!</span>''' While it's possible to set the Slot, Lock Code and Name from the Dashboard with this technique, you will not be able to see what slots are occupied in the lock and by which codes. You will need to know yourself which slots are occupied. This rule will change the code and name you enter in any slot you enter on the lock, but without any feedback to the Dashboard. For the complete control and status of your lock codes, the Hubitat Remote Admin service is recommended.
 
'''<span style="color: red;;">WARNING!</span>''' While it's possible to set the Slot, Lock Code and Name from the Dashboard with this technique, you will not be able to see what slots are occupied in the lock and by which codes. You will need to know yourself which slots are occupied. This rule will change the code and name you enter in any slot you enter on the lock, but without any feedback to the Dashboard. For the complete control and status of your lock codes, the Hubitat Remote Admin service is recommended.
  
# In Rule Machine create a Global Variable.[[File:Step 1-Lock Code with Dashboard.png|none|thumb|600x600px]]
+
=== Part 1: Create a Global Variable ===
# Enter '''Lock Code''' for the global variable Name, set the Variable Type to '''String''', and enter '''2:0''' in the Set initial value field.
 
#* '''NOTE''': Be sure to include a colon between the 2 and 0.[[File:Step 2-Lock Code with Dashboard.png|none|thumb|600x600px]]
 
# Press '''Create''' to create a Connector for the Global Variable. This will create a virtual device which will also be named '''Lock Code'''.[[File:Step 3-Lock Code with Dashboard.png|none|thumb|600x600px]]
 
# Set Connector Type to '''Variable''' and press '''Done'''.[[File:Step 4-Lock Code with Dashboard.png|none|thumb|600x600px]]
 
# Create a new Rule Machine rule.[[File:Step 5-Lock Code with Dashboard.png|none|thumb|600x600px]]
 
# Name the rule '''Lock Codes'''.[[File:Step 6-Lock Code with Dashboard.png|none|thumb|600x600px]]
 
# Set the Capability of the Trigger to '''Variable'''.[[File:Step 7-Lock Code with Dashboard.png|none|thumb|600x600px]]
 
# Set the Variable to '''Lock Code''' (This is the Global Variable that was created in '''Step 1''') and set the Comparison to '''*changed*'''
 
# Press '''Done with this Trigger Event''', and then press '''Done with Trigger Events'''.[[File:Step 8-Lock Code with Dashboard.png|none|thumb|600x600px]]
 
# Scroll down within the same rule window and select '''Create Local Variables.''' [[File:Step 10-Lock Code with Dashboard.png|none|thumb|600x600px]]
 
# Set Local Variables with the following '''Name''', '''Type''' and '''Value''' for each.
 
#* '''NOTE:''' For the Local Variable labelled '''name''', the Value field cannot be blank. Press the spacebar once in its '''Value''' field so you will be able to continue. For the Local Variable labelled slot, the type is '''Number''', rather than '''String''' like the other Local Variables in the list.[[File:Step 11-Lock Code with Dashboard.png|none|thumb|600x600px]]
 
# Create the first action in the rule by choosing '''Set Variables''' for the Action Type, and then '''Set Variable''' for the Action.
 
# Choose '''temp''' for the Variable to Set, and '''Token''' for the string operation.
 
# In the '''String to get token from''' field, enter '''%Lock Code%'''
 
# Enter a ''':''' (colon) in the Delimiter field, and '''0''' in the Index field, then press the '''Done with this action''' button.[[File:Step 13-Lock Code with Dashboard.png|none|thumb|600x600px]]
 
# For the next action, choose '''Conditional Actions''' for the Action Type, and then select '''Simple Conditional Action'''.[[File:Step 12-Lock Code with Dashboard.png|none|thumb|600x600px]]
 
# Select '''Variable''' for the Action Condition capability.[[File:Step 17.1-Lock Code with Dashboard.png|none|thumb|615x615px]]
 
# Choose '''temp''' for the Variable and '''=''' (equals) for the Comparison, then enter '''slot''' in the String Value field.
 
# Press the '''Done with this Condition''' button.[[File:Step 19.1-Lock Code with Dashboard.png|none|thumb|600x600px]]
 
# Select '''Repeat Actions, Wait''' for Action Type of the Simple Conditional Action, and '''Exit Rule''' for the Action.
 
# Press the '''Done with this action''' button.[[File:Step 20-Lock Code with Dashboard.png|none|thumb|600x600px]]
 
# For the third action, select '''Set Variables''', then '''Set Variable'''.
 
# Select '''slot''' for the Variable to Set, and choose '''string''' for the operation.
 
# Enter '''%temp%''' in the "Numeric string" field, and press the '''Done with this action''' button.[[File:Step 22-Lock Code with Dashboard.png|none|thumb|600x600px]]
 
# In the fourth action, you will again select '''Set Variables''', then '''Set Variable'''.
 
# Select '''code''' for the Variable to Set, and choose '''Token''' for the string operation.
 
# Enter '''%Lock Code%''' in the "String to get token from" field
 
# Type a ''':''' (colon) in the Delimiter field, and '''1''' in the Index field and press the '''Done with this action''' button.[[File:Step 25.1-Lock Code with Dashboard.png|none|thumb|600x600px]]
 
# For the fifth action, you will once again select '''Set Variables''', then '''Set Variable'''.
 
# Select '''name''' for the Variable to Set, and choose '''Token''' for the string operation.
 
# Enter '''%Lock Code%''' in the "String to get token from" field
 
# Type a ''':''' (colon) in the Delimiter field, and '''2''' in the Index field and press the '''Done with this action''' button.[[File:Step 29-Lock Code with Dashboard.png|none|thumb|600x600px]]
 
# In the sixth action, choose '''Conditional Actions''' for the Action Type, and then select '''IF (conditions) THEN'''
 
# Define the condition and select '''Variable''' for the Action Condition capability.
 
# Select '''code''' for the Variable and '''!=''' (not equal to) for the Comparison. Enter '''0''' in the String Value field.
 
# Press the '''Done with this Condition''' button., then press the '''Done with Conditional Action''' button.[[File:Step 33-Lock Code with Dashboard.png|none|thumb|600x600px]]
 
# Select the Action Type '''Run Custom Action'''.[[File:Step 37-Lock Code with Dashboard.png|none|thumb|600x600px]]
 
# Choose '''Run Custom Action''', and Lock for the capability of the action device.
 
#
 
  
The string in the center of t'''hat ti'''le 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.
+
#In Rule Machine create a Global Variable.[[File:Step 1-Lock Code with Dashboard.png|none|thumb|600x600px]]
 +
#Enter '''Lock Code''' for the global variable Name, set the Variable Type to '''String''', and enter '''2:0''' in the Set initial value field.
 +
#*'''NOTE''': Be sure to include a colon between the 2 and 0.[[File:Step 2-Lock Code with Dashboard.png|none|thumb|600x600px]]
 +
#Press '''Create''' to create a Connector for the Global Variable. This will create a virtual device which will also be named '''Lock Code'''.[[File:Step 3-Lock Code with Dashboard.png|none|thumb|600x600px]]
 +
#Set Connector Type to '''Variable''' and press '''Done'''.[[File:Step 4-Lock Code with Dashboard.png|none|thumb|600x600px]]
  
Finally, create this rule below. Note that it has 4 local variables defined.
+
=== Part 2: Create a Rule Machine rule ===
  
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.
+
#Create a new Rule Machine rule.[[File:Step 5-Lock Code with Dashboard.png|none|thumb|600x600px]]
 +
#Name the rule '''Lock Codes'''.[[File:Step 6-Lock Code with Dashboard.png|none|thumb|600x600px]]
 +
#Set the Capability of the Trigger to '''Variable'''.[[File:Step 7-Lock Code with Dashboard.png|none|thumb|600x600px]]
 +
#Set the Variable to '''Lock Code''' (This is the Global Variable that was created in '''Step 1''') and set the Comparison to '''*changed*'''
 +
#Press '''Done with this Trigger Event''', and then press '''Done with Trigger Events'''.[[File:Step 8-Lock Code with Dashboard.png|none|thumb|600x600px]]
 +
#Scroll down within the same rule window and select '''Create Local Variables.''' [[File:Step 10-Lock Code with Dashboard.png|none|thumb|600x600px]]
 +
#Set Local Variables with the following '''Name''', '''Type''' and '''Value''' for each.
 +
#*'''NOTE:''' For the Local Variable labelled '''name''', the Value field cannot be blank. Press the spacebar once in its '''Value''' field so you will be able to continue. For the Local Variable labelled slot, the type is '''Number''', rather than '''String''' like the other Local Variables in the list.[[File:Step 11-Lock Code with Dashboard.png|none|thumb|600x600px]]
 +
#Create the first action in the rule by choosing '''Set Variables''' for the Action Type, and then '''Set Variable''' for the Action.
 +
#Choose '''temp''' for the Variable to Set, and '''Token''' for the string operation.
 +
#In the '''String to get token from''' field, enter '''%Lock Code%'''
 +
#Enter a ''':''' (colon) in the Delimiter field, and '''0''' in the Index field, then press the '''Done with this action''' button.[[File:Step 13-Lock Code with Dashboard.png|none|thumb|600x600px]]
 +
#For the next action, choose '''Conditional Actions''' for the Action Type, and then select '''Simple Conditional Action'''.[[File:Step 12-Lock Code with Dashboard.png|none|thumb|600x600px]]
 +
#Select '''Variable''' for the Action Condition capability.[[File:Step 17.1-Lock Code with Dashboard.png|none|thumb|615x615px]]
 +
#Choose '''temp''' for the Variable and '''=''' (equals) for the Comparison, then enter '''slot''' in the String Value field.
 +
#Press the '''Done with this Condition''' button.[[File:Step 19.1-Lock Code with Dashboard.png|none|thumb|600x600px]]
 +
#Select '''Repeat Actions, Wait''' for Action Type of the Simple Conditional Action, and '''Exit Rule''' for the Action.
 +
#Press the '''Done with this action''' button.[[File:Step 20-Lock Code with Dashboard.png|none|thumb|600x600px]]
 +
#For the third action, select '''Set Variables''', then '''Set Variable'''.
 +
#Select '''slot''' for the Variable to Set, and choose '''string''' for the operation.
 +
#Enter '''%temp%''' in the "Numeric string" field, and press the '''Done with this action''' button.[[File:Step 22-Lock Code with Dashboard.png|none|thumb|600x600px]]
 +
#In the fourth action, you will again select '''Set Variables''', then '''Set Variable'''.
 +
#Select '''code''' for the Variable to Set, and choose '''Token''' for the string operation.
 +
#Enter '''%Lock Code%''' in the "String to get token from" field
 +
#Type a ''':''' (colon) in the Delimiter field, and '''1''' in the Index field and press the '''Done with this action''' button.[[File:Step 25.1-Lock Code with Dashboard.png|none|thumb|600x600px]]
 +
#For the fifth action, you will once again select '''Set Variables''', then '''Set Variable'''.
 +
#Select '''name''' for the Variable to Set, and choose '''Token''' for the string operation.
 +
#Enter '''%Lock Code%''' in the "String to get token from" field
 +
#Type a ''':''' (colon) in the Delimiter field, and '''2''' in the Index field and press the '''Done with this action''' button.[[File:Step 29-Lock Code with Dashboard.png|none|thumb|600x600px]]
 +
#In the sixth action, choose '''Conditional Actions''' for the Action Type, and then select '''IF (conditions) THEN'''
 +
#Define the condition and select '''Variable''' for the Action Condition capability.
 +
#Select '''code''' for the Variable and '''!=''' (not equal to) for the Comparison. Enter '''0''' in the String Value field.
 +
#Press the '''Done with this Condition''' button., then press the '''Done with Conditional Action''' button.[[File:Step 33-Lock Code with Dashboard.png|none|thumb|600x600px]]
 +
#Select the Action Type '''Run Custom Action'''.[[File:Step 37-Lock Code with Dashboard.png|none|thumb|600x600px]]
 +
#Choose '''Run Custom Action''', and '''Lock''' for the capability of the action device.
 +
#Select the Lock to act on and press the '''Update''' button.[[File:Step 38-Lock Code with Dashboard.png|none|thumb|600x600px]]
 +
#Select '''setCode''' for the custom command and choose '''string''' for the parameter type.
 +
#In the "string value" field, enter '''%slot%''' and then press the Tab key to update or tap in the white space of the rule.[[File:Step 40.1-Lock Code with Dashboard.png|none|thumb|600x600px]]
 +
#Press the '''Add another parameter button.'''[[File:Step 42-Lock Code with Dashboard.png|none|thumb|600x600px]]
 +
#Choose '''string''' for the parameter type, entering '''%code%''' in the "string value" field.
 +
#One last time, press the '''Add another parameter button''' and choose '''string''' for the parameter type, entering '''%name%''' in the "string value" field.
 +
#When all three parameters have been entered, press the '''Done with this action''' button.[[File:Step 45-Lock Code with Dashboard.png|none|thumb|600x600px]]
 +
#Select '''Conditional Actions''' for the Action Type and the select '''ELSE'''.
 +
#Press the '''Done with this action''' button.[[File:Step 46-Lock Code with Dashboard.png|none|thumb|600x600px]]
 +
#Select the Action Type '''Run Custom Action''' again, just as you did in '''Step 37''', and again choose '''Run Custom Action''', and '''Lock''' for the capability of the action device.
 +
#Select the Lock to act on and press the '''Update''' button.
 +
#Select '''deleteCode''' for the custom command and choose '''string''' for the parameter type.
 +
#In the "string value" field, enter '''%slot%''' and then press the Tab key to update or tap in the white space of the rule.
 +
#Press the '''Done with this action''' button.[[File:Step 50-Lock Code with Dashboard.png|none|thumb|600x600px]]
 +
#Select '''Conditional Actions''' for the Action Type and the select '''END-IF'''.
 +
#Press the '''Done with this action''' button.[[File:Step 53-Lock Code with Dashboard.png|none|thumb|600x600px]]
 +
#Select '''Set Variables''', then '''Set Variable.'''
 +
#Select '''Lock Code''' for the Variable to Set and the select '''Set string''' for the operation.
 +
#In the "String to set Lock Code to" field, enter '''slot:code:name''' (don't forget to add colons between each string value.
 +
#Press the '''Done with this action''' button, then the '''Done with actions''' button, and finally the '''Done''' button for the rule.
 +
#*The purpose of this last action is to set the displayed name to slot:code:name so the previously entered lock code will not be shown.
  
After the string shown above (3:4567:Jason) was entered into the Dashboard tile, the resulting lock code was created:
+
=== Part 3: Create a Dashboard Lock Code Tile ===
  
To remove a lock code, enter the slot number and 0 separated by a colon, like this: 2:0.
+
#
  
This will erase slot 2, leaving the lock in this state:
+
# From the Apps menu, create a new Dashboard.
 
 
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:
 

Revision as of 05:43, 20 March 2021

Managing lock codes isn't a difficult task with Lock Code Manager, and Hubitat Remote Admin is easiest way to do this when you're away from home. However, if you're comfortable with creating Rule Machine rules and a Global Variable Connector., it's possible to create and change lock codes with Hubitat Dashboard.

The lock driver built-in to Hubitat Elevation defines each lock code with 3 values:

  • Slot Number, which is the code position in the lock.
  • The Lock Code itself, which is your 4 to 6 digit PIN code.
  • A name for the code.

Using Hubitat Dashboard, you can create a Dashboard tile to set each of those values for a particular lock.

WARNING! While it's possible to set the Slot, Lock Code and Name from the Dashboard with this technique, you will not be able to see what slots are occupied in the lock and by which codes. You will need to know yourself which slots are occupied. This rule will change the code and name you enter in any slot you enter on the lock, but without any feedback to the Dashboard. For the complete control and status of your lock codes, the Hubitat Remote Admin service is recommended.

Part 1: Create a Global Variable

  1. In Rule Machine create a Global Variable.
    Step 1-Lock Code with Dashboard.png
  2. Enter Lock Code for the global variable Name, set the Variable Type to String, and enter 2:0 in the Set initial value field.
    • NOTE: Be sure to include a colon between the 2 and 0.
      Step 2-Lock Code with Dashboard.png
  3. Press Create to create a Connector for the Global Variable. This will create a virtual device which will also be named Lock Code.
    Step 3-Lock Code with Dashboard.png
  4. Set Connector Type to Variable and press Done.
    Step 4-Lock Code with Dashboard.png

Part 2: Create a Rule Machine rule

  1. Create a new Rule Machine rule.
    Step 5-Lock Code with Dashboard.png
  2. Name the rule Lock Codes.
    Step 6-Lock Code with Dashboard.png
  3. Set the Capability of the Trigger to Variable.
    Step 7-Lock Code with Dashboard.png
  4. Set the Variable to Lock Code (This is the Global Variable that was created in Step 1) and set the Comparison to *changed*
  5. Press Done with this Trigger Event, and then press Done with Trigger Events.
    Step 8-Lock Code with Dashboard.png
  6. Scroll down within the same rule window and select Create Local Variables.
    Step 10-Lock Code with Dashboard.png
  7. Set Local Variables with the following Name, Type and Value for each.
    • NOTE: For the Local Variable labelled name, the Value field cannot be blank. Press the spacebar once in its Value field so you will be able to continue. For the Local Variable labelled slot, the type is Number, rather than String like the other Local Variables in the list.
      Step 11-Lock Code with Dashboard.png
  8. Create the first action in the rule by choosing Set Variables for the Action Type, and then Set Variable for the Action.
  9. Choose temp for the Variable to Set, and Token for the string operation.
  10. In the String to get token from field, enter %Lock Code%
  11. Enter a : (colon) in the Delimiter field, and 0 in the Index field, then press the Done with this action button.
    Step 13-Lock Code with Dashboard.png
  12. For the next action, choose Conditional Actions for the Action Type, and then select Simple Conditional Action.
    Step 12-Lock Code with Dashboard.png
  13. Select Variable for the Action Condition capability.
    Step 17.1-Lock Code with Dashboard.png
  14. Choose temp for the Variable and = (equals) for the Comparison, then enter slot in the String Value field.
  15. Press the Done with this Condition button.
    Step 19.1-Lock Code with Dashboard.png
  16. Select Repeat Actions, Wait for Action Type of the Simple Conditional Action, and Exit Rule for the Action.
  17. Press the Done with this action button.
    Step 20-Lock Code with Dashboard.png
  18. For the third action, select Set Variables, then Set Variable.
  19. Select slot for the Variable to Set, and choose string for the operation.
  20. Enter %temp% in the "Numeric string" field, and press the Done with this action button.
    Step 22-Lock Code with Dashboard.png
  21. In the fourth action, you will again select Set Variables, then Set Variable.
  22. Select code for the Variable to Set, and choose Token for the string operation.
  23. Enter %Lock Code% in the "String to get token from" field
  24. Type a : (colon) in the Delimiter field, and 1 in the Index field and press the Done with this action button.
    Step 25.1-Lock Code with Dashboard.png
  25. For the fifth action, you will once again select Set Variables, then Set Variable.
  26. Select name for the Variable to Set, and choose Token for the string operation.
  27. Enter %Lock Code% in the "String to get token from" field
  28. Type a : (colon) in the Delimiter field, and 2 in the Index field and press the Done with this action button.
    Step 29-Lock Code with Dashboard.png
  29. In the sixth action, choose Conditional Actions for the Action Type, and then select IF (conditions) THEN
  30. Define the condition and select Variable for the Action Condition capability.
  31. Select code for the Variable and != (not equal to) for the Comparison. Enter 0 in the String Value field.
  32. Press the Done with this Condition button., then press the Done with Conditional Action button.
    Step 33-Lock Code with Dashboard.png
  33. Select the Action Type Run Custom Action.
    Step 37-Lock Code with Dashboard.png
  34. Choose Run Custom Action, and Lock for the capability of the action device.
  35. Select the Lock to act on and press the Update button.
    Step 38-Lock Code with Dashboard.png
  36. Select setCode for the custom command and choose string for the parameter type.
  37. In the "string value" field, enter %slot% and then press the Tab key to update or tap in the white space of the rule.
    Step 40.1-Lock Code with Dashboard.png
  38. Press the Add another parameter button.
    Step 42-Lock Code with Dashboard.png
  39. Choose string for the parameter type, entering %code% in the "string value" field.
  40. One last time, press the Add another parameter button and choose string for the parameter type, entering %name% in the "string value" field.
  41. When all three parameters have been entered, press the Done with this action button.
    Step 45-Lock Code with Dashboard.png
  42. Select Conditional Actions for the Action Type and the select ELSE.
  43. Press the Done with this action button.
    Step 46-Lock Code with Dashboard.png
  44. Select the Action Type Run Custom Action again, just as you did in Step 37, and again choose Run Custom Action, and Lock for the capability of the action device.
  45. Select the Lock to act on and press the Update button.
  46. Select deleteCode for the custom command and choose string for the parameter type.
  47. In the "string value" field, enter %slot% and then press the Tab key to update or tap in the white space of the rule.
  48. Press the Done with this action button.
    Step 50-Lock Code with Dashboard.png
  49. Select Conditional Actions for the Action Type and the select END-IF.
  50. Press the Done with this action button.
    Step 53-Lock Code with Dashboard.png
  51. Select Set Variables, then Set Variable.
  52. Select Lock Code for the Variable to Set and the select Set string for the operation.
  53. In the "String to set Lock Code to" field, enter slot:code:name (don't forget to add colons between each string value.
  54. Press the Done with this action button, then the Done with actions button, and finally the Done button for the rule.
    • The purpose of this last action is to set the displayed name to slot:code:name so the previously entered lock code will not be shown.

Part 3: Create a Dashboard Lock Code Tile

  1. From the Apps menu, create a new Dashboard.