Jump to content

Arbitrarily complex "Combination Lock" using a KPL


mcm

Recommended Posts

Posted

Here is a combination lock / key code implementation using only a KeyPadLinc with the ISY 99i.

 

It makes use of program status (enabled/disabled) to maintain state, along with a flag variable. I'm not sure if this is done much but I found it fairly useful for this implementation which basically needs to establish the order of key presses in a sequence.

 

1) Create a scene for the keys you wish to use to enter a code. This is to allow blanking/resetting of the "key pad". I used the 2x3 pad of C thru H and named the scene "Code Keys".

 

2) Create an empty program to use as a variable, I named this CodeArmMistakeFlag. This is used to prevent combinatorial attempts at iterating through the key pad state sequence, which would otherwise be possible. It is the else condition for all code step programs except the first (because this is the "entry point" which any key pad state prior to "all blank" is irrelevant) and the last (because it is evaluated in the IF condition to the last step).

 

CodeArmMistakeFlag

 

If
  - No Conditions - (To add one, press 'Schedule' or 'Condition')

Then
  - No Actions - (To add one, press 'Action')

Else
  - No Actions - (To add one, press 'Action')

Comment: This is used to capture a sequence error during code entry. Evaluated at the final sequence step (prevents trial and error in terms of button order.)

 

3) Create the necessary sequence programs. This consists of steps of the code sequence that evaluate the state of all buttons in the key pad. The ISY evaluates a program's IF condition when the state of any device involved in the condition changes, so this is ideal to evaluate which buttons are pressed whenever a button is pressed.

 

Note well that each step disables itself then enables the next within the THEN branch. This is effectively how state is "passed on" down the code sequence and controls what is the next expected key pad state at each step in the sequence.

 

If you scroll down through these steps, it will be obvious as to the progression of key pad button states that is required to successfully enter the code. It should be clear also how the ISY's state-change based execution of programs permits this set of programs to enforce a specific order of button presses.

 

Of course, each subsequent step does not need to be more and more buttons turned on, in fact the next step could require turning a button off again. This allows an arbitrarily complex/long code to be used.

 

CodeArmStepA:

 

If
       Status  'Living Room / Living Room Fan - Switch / Living Room Fan - C' is On
   And Status  'Living Room / Living Room Fan - Switch / Living Room Fan - D' is not On
   And Status  'Living Room / Living Room Fan - Switch / Living Room Fan - E' is not On
   And Status  'Living Room / Living Room Fan - Switch / Living Room Fan - F' is not On
   And Status  'Living Room / Living Room Fan - Switch / Living Room Fan - G' is not On
   And Status  'Living Room / Living Room Fan - Switch / Living Room Fan - H' is not On

Then
       Disable Program 'CodeArmStepA'
       Enable Program 'CodeArmStepB'
       Disable Program 'CodeArmStepC'
       Disable Program 'CodeArmStepD'

Else
  - No Actions - (To add one, press 'Action')

 

CodeArmStepB:

 

If
       Status  'Living Room / Living Room Fan - Switch / Living Room Fan - C' is On
   And Status  'Living Room / Living Room Fan - Switch / Living Room Fan - D' is not On
   And Status  'Living Room / Living Room Fan - Switch / Living Room Fan - E' is not On
   And Status  'Living Room / Living Room Fan - Switch / Living Room Fan - F' is On
   And Status  'Living Room / Living Room Fan - Switch / Living Room Fan - G' is not On
   And Status  'Living Room / Living Room Fan - Switch / Living Room Fan - H' is not On

Then
       Disable Program 'CodeArmStepA'
       Disable Program 'CodeArmStepB'
       Enable Program 'CodeArmStepC'
       Disable Program 'CodeArmStepD'

Else
       Run Program 'CodeArmMistakeFlag' (Then Path)

 

CodeArmStepC:

 

If
       Status  'Living Room / Living Room Fan - Switch / Living Room Fan - C' is On
   And Status  'Living Room / Living Room Fan - Switch / Living Room Fan - D' is not On
   And Status  'Living Room / Living Room Fan - Switch / Living Room Fan - E' is not On
   And Status  'Living Room / Living Room Fan - Switch / Living Room Fan - F' is On
   And Status  'Living Room / Living Room Fan - Switch / Living Room Fan - G' is On
   And Status  'Living Room / Living Room Fan - Switch / Living Room Fan - H' is not On

Then
       Disable Program 'CodeArmStepA'
       Disable Program 'CodeArmStepB'
       Disable Program 'CodeArmStepC'
       Enable Program 'CodeArmStepD'

Else
       Run Program 'CodeArmMistakeFlag' (Then Path)


 

CodeArmStepD:

 

If
       Status  'Living Room / Living Room Fan - Switch / Living Room Fan - C' is On
   And Status  'Living Room / Living Room Fan - Switch / Living Room Fan - D' is On
   And Status  'Living Room / Living Room Fan - Switch / Living Room Fan - E' is not On
   And Status  'Living Room / Living Room Fan - Switch / Living Room Fan - F' is On
   And Status  'Living Room / Living Room Fan - Switch / Living Room Fan - G' is On
   And Status  'Living Room / Living Room Fan - Switch / Living Room Fan - H' is not On
   And Program 'CodeArmMistakeFlag' is False

Then
       Run Program 'CodeArm' (If)
       Run Program 'CodeArmReset' (Then Path)

Else
       Run Program 'CodeArmReset' (Then Path)

Comment: Final step in key code sequence, calls CodeArm to handle arming/disarming then resets sequence for subsequent entry.

 

Note that the final step does the actual "success or failure" action handling. Success actions go into THEN, failure go into ELSE. Under either condition, the state reset program should be executed (so you can punch the code in again, of course!)

 

4) Create a program (or in my case, a pair programs just for encapsulation of step resetting as a subroutine from the main reset program) to reset the state of the key pad. This is called either when the IF condition (all keys off) is met, or as explicitly called by the last step.

 

CodeArmReset:

 

If
       Status  'Living Room / Living Room Fan - Switch / Living Room Fan - C' is not On
   And Status  'Living Room / Living Room Fan - Switch / Living Room Fan - D' is not On
   And Status  'Living Room / Living Room Fan - Switch / Living Room Fan - E' is not On
   And Status  'Living Room / Living Room Fan - Switch / Living Room Fan - F' is not On
   And Status  'Living Room / Living Room Fan - Switch / Living Room Fan - G' is not On
   And Status  'Living Room / Living Room Fan - Switch / Living Room Fan - H' is not On

Then
       Disable Program 'CodeArmReset'
       Run Program 'CodeArmResetSteps' (Then Path)
       Run Program 'CodeArmMistakeFlag' (Else Path)
       Set Scene 'Code Keys' Off
       Set 'Living Room / Living Room Fan - Switch' 100 (Beep Duration)
       Enable Program 'CodeArmReset'

Else
  - No Actions - (To add one, press 'Action')

 

CodeArmResetSteps:

 

If
  - No Conditions - (To add one, press 'Schedule' or 'Condition')

Then
       Enable Program 'CodeArmStepA'
       Disable Program 'CodeArmStepB'
       Disable Program 'CodeArmStepC'
       Disable Program 'CodeArmStepD'

Else
  - No Actions - (To add one, press 'Action')

 

5) (Optionally) Create a program to run when the code is successfully entered. You could of course stuff this all in THEN of the final step, but I wanted to additionally evaluate the state of yet another key pad button (this time, the B key which is not part of the "code key pad"). In my application, if B is ON when the code is punched in, the program runs a network resource that remotely arms a camera (enabling recording and video motion detection, event handling, notification, etc). If B is OFF when the code is punched in, the camera is disarmed. You can of course do whatever you want as an action handler.

 

CodeArm:

 

If
       Status  'Living Room / Living Room Fan - Switch / Living Room Fan - B' is On

Then
       Resource 'Arm LivingRoom'

Else
       Resource 'Disarm LivingRoom'

Comment: Arms cameras if "B" button is on, otherwise disarms.

Guest
This topic is now closed to further replies.

  • Recently Browsing

    • No registered users viewing this page.
  • Who's Online (See full list)

    • There are no registered users currently online
  • Forum Statistics

    • Total Topics
      37k
    • Total Posts
      371.4k
×
×
  • Create New...