Advertisement
Guest User

Untitled

a guest
Oct 21st, 2017
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. definition(
  2. name: "Automatic Door Unlock",
  3. namespace: "io.goodintentions.autounlock",
  4. author: "Good Intentions",
  5. description: "Unlocks a door a specified time after locking.",
  6. category: "Safety & Security",
  7. iconUrl: "http://i.imgur.com/Wo5HCef.jpg",
  8. iconX2Url: "http://i.imgur.com/Wo5HCef.jpg",
  9. iconX3Url: "http://i.imgur.com/Wo5HCef.jpg")
  10.  
  11. preferences {
  12. section("Lock Confguration:") {
  13. input "lock","capability.lock", title: "Lock", required: true
  14. input "delay", "number", title: "Unlock after locked(minutes):", defaultValue: 7, required: true
  15. }
  16. }
  17.  
  18. def installed()
  19. {
  20. subscribe(lock, "lock", lockHandler)
  21. }
  22.  
  23. def updated()
  24. {
  25. unsubscribe()
  26. subscribe(lock, "lock", lockHandler)
  27. }
  28.  
  29. def lockHandler(evt) {
  30. if (evt.value == "locked") {
  31. runIn(getDelaySeconds(delay), unlockDoor)
  32. log.debug("${evt.displayName} locked.")
  33. }
  34. }
  35.  
  36. void unlockDoor() {
  37. unschedule(unlockDoor)
  38.  
  39. log.debug("Unlocking${lock.displayName} now.")
  40. lock.unlock()
  41. }
  42.  
  43. def getDelaySeconds(delay) {
  44. return (delay * 60)
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement