Turn On/Off and/or Change Mode When Door Unlocks/Locks

I have an automatic door lock but no door sensor so I made this app to save me a little money. It’s pretty simple and this was the first thing I was hoping to set up when I bought an ST. It can turn on switches when a door is unlocked and turn off switches when a door is locked.



  1. Added ability to change modes.
  2. Changed switches to not be required.
  3. Added option to only run between a certain time.

If you find this app useful, please support the developer:


very clean. good work

Would it be possible for this app to also change modes?

1 Like

Thanks for doing this. I tweaked mine to turn off lights xx minutes after unlocking the door. Fits our lifestyle.

Just add:
section(“Turn lights off after…”){
input “minutesOff”, “number”, title: “Minutes”, required: false

And under “switches.on()” add:
switches.off(delay: 60000 * minutesOff)

@dlee I actually added this in there a couple days ago but I didn’t have a chance to upload the change yet. I was trying to figure out how to make the preferences look a little nicer but I haven’t had time. The code with the delay is up there now.

@brianless I’ll add this in there when I have some extra time.

@dlee Whoops. I just reread your post and that’s not what I did. Usually I lock the door after I come in so I didn’t think of having the light turn off after just unlocking.

I would also like a simple app that changes modes or runs a hello home command based on the Kwikset lock status. Great for dog walkers.

1 Like

Ya, what I did might not suit many who want the light to stay on when unlocked. Just sharing since it works well for us.

@brianlees @RichardH I added the ability to change modes. It’s still required to choose a switch for now.

THANKS! That’ll still work. Is the turning on a switch a limitation of ST and changing modes?

@brianlees No. I just need to take some time to rearrange the code and add some error checking in there. I just finished adding it in. Now I just need to get the only run during a certain time of day working.

1 Like

Added the only run between certain times functionality.

I know this is stupid - but can someone point me to a FAQ or Sticky that tells me how to INSTALL this app? Thanks in advance!

@texaszman There’s some videos but I haven’t found anything quick and simple. You basically need to log into the developer’s IDE and then create a new SmartApp under My SmartApps. Fill in the required information (it doesn’t matter what you put because it will be overwritten). Overwrite all the code with the app you want to create and then Publish -> For Me. Click the + on your phone and then the app should show under My Apps.

Thanks much! Will apparently have to self educate myself :smiley:

I have this setup to open my garage door (Evolve LFM-20), when my door unlocks (Kwikset).

However, it does not always open my garage door. Not sure what the error could be…

Sorry for bumping an old thread…I was just searching the forum for something like this, thank you for the code!

I have a newbie question which I am hoping someone might be able to help me with. I added + installed this app via the Web Ide, but I am curious if once installed this will show up anywhere in the mobile app? i.e. is there any way to use the mobile app to reconfigure/edit the settings I installed via the Web IDE (say I want to add another switch or add a delay or something). Thanks!

you are awesome, thanks for the smartapp!

Wanted to say thanks for this simple code. I made a small change to reverse On and Off, and am using it with a virtual switch and Amazon Echo. I have a virtual Switch named “Front Door Lock” When the switch is on, the door is locked and when it’s off the door is unlocked. So I can say “Turn off Front door lock” to unlock the front door, and “Turn on Front door lock”.

I found this smart app yesterday and it solves a problem I’ve been having for awhile - namely setting the mode when I return home (to HOME during the day, and EVENING in the evening).

There is one thing that would make this absolutely perfect for me - the ability to change the STOP TIME to SUNSET.

How hard would it be to add that to this smart app?
Could someone post directions for a novice (me) to do that?
I know how to copy code from GitHub and create smart apps on IDE (including turning on OAuth) … I just don’t know what the code is for SUNSET, and where it would need to be added with this smart app code.

Any help would be appreciated. And if not possible, I can certainly live with this just being active from 8am until 6:30pm everyday (and adjusting the end time monthly as the seasons progress).


1 Like