Link Switch And Lock

echo
smartapp_locks

#1

I’m using an Amazon Echo which now integrates with SmartThings but doesn’t support controlling Locks. It can however control switches. In response, I wrote a very simple application that will link the on/off and locked/unlocked state between a switch device and a lock device. Specifically, this means:

  • Locking the lock will turn on the switch
  • Unlocking the lock will turn off the switch
  • Turning on the switch will lock the lock
  • Turning off the switch will unlock the lock

The result is that SmartApps or device integrations which are able to control a switch device can now control a lock device too.

To use, create a new device with the “On/Off Button Tile” type. Install this app and select your new Button Tile virtual device and a Lock device. This will link the on/off state of the Button Tile to the locked/unlocked state of the lock. Now you can use Amazon Echo to say “Alexa, turn on the garage door lock” which will turn on the Button Tile, which in turn will lock the specified lock.


Use Alexa to open a Kiwkset lock connected to Smarthings
Trouble discovering Kwikset Z-wave Lock on Amazon Echo
Help getting Alexa to unlock front door
FAQ: Amazon Echo: The Official SmartThings Integration is here! (Initial SetUp FAQ)
Can someone help me lock my door with Alexa?
FAQ: Amazon Echo: The Official SmartThings Integration is here! (Initial SetUp FAQ)
Rule machine - as per the app developer, this app is no longer available for new installs, distribution, or support
#2

This application keeps locking and unlocking the door after I use Alexa to turn it on. Is there a fix?


(Benji) #3

Have you tried locking/unlocking the door via another means without Alexa or this SmartApp, does it still behave the same?


(Bernie H) #4

Or use an virtual switch instead. Doe the button stay on or is it momentary?


#5

Make sure that the virtual device you are using is a “On/Off Button Tile”. It sounds like you might be using a momentary contact device.


#6

Luma. Thanks for working on this. I was also having the issue where my lock and switch would occasionally loop. I found some example code from another app that works with the “simulated switch” device. It allows you to set the state of the switch without triggering the event. So I changed the device from On/OFF button tile to “simulated switched” and modifed your code. onPhysical and offPyshical. So far working good.

At the top:

preferences {
section(“When this switch is turned on”) {
input “switch1”, “device.simulatedSwitch”

and subs at the bottom:

def lockedHandler(evt) {
log.debug evt.value
log.debug "Turning on switch: $switch1"
switch1.onPhysical()
}

def unlockedHandler(evt) {
log.debug evt.value
log.debug "Turning off switch: $switch1"
switch1.offPhysical()
}


(A Patel) #7

So haven’t tested this with Alexa yet, but I got the virtual lock to control the real lock. Now I have to just discover the virtual lock from alexa. So am I forced to say “Alex turn on virtual lock”??

Can I not say “Alexa lock the virtual lock”

Of course, I’d change “Virtual Lock” to be “Front Door”. But point is to use the “lock” phrase vs “turn on”. Any way to do that?


#8

To th best of my knowledge, no. You need to say “turn on the front door lock”.


(Dave) #9

I set this up and it works in the simulator, but when I go into “Things” in the ST app and tap “off”, thus turning the switch to “on”, it doesn’t actually lock the door.
Same if I ask “Alexa, turn on back door lock”, the virtual switch gets turned on, but the lock doesn’t actually lock.
Any idea? As I said, it works in the simulator, just not in the App.


(Dtm) #10

Why aren’t more ppl working on this!? I can’t believe there’s no option to just use a virtual switch to control one of your devices of choice, why is it so complicated? I just want to lock my schlage connect with my google home.


#11

The joy of open source is that you are absolutely free to continue working on this. The code here is simple and pretty readable and it would probably make a good first project for trying your own ideas. Give it a shot!


(Lance) #12

If anyone else is wondering how to lock/unlock their door, here is a somewhat roundabout way that doesn’t require a custom smart app, you just need to create a virtual button. Also you can create a custom IFTTT app so it can be activated with whatever phrase you want (you don’t have to say “turn on…”).

-Create a routine to unlock the door
-On https://graph.api.smartthings.com under “My Devices” click “New Device” and create a “Momentary button tile” called “Unlock the front door button”
-Edit your routine to be triggered by the tile
-At this point you can unlock the door by saying “Ok Google, turn on unlock the front door button”
-Go to https://ifttt.com/my_applets and create a new applet. For “if this” link to the Google Assistant service and select “Say a simple phrase”. I recommend you use a code phrase, for example “open sesame”, so someone can’t unlock your door by yelling from outside
-For “then that” select the SmartThings service and have it activate the “Unlock the front door button” tile

Now you can do something similar for locking the door.


(jkp) #13

https://account.smartthings.com


(Narayan Venkataraman) #14

I used the information here to control locking and unlocking the Schlage lock with Alexa. Thank you very much.