[SOLVED] Alexa notification after sensor open > x Minutes

Hello

I’ve spent a few hours searching for an answer and come across nothing. When a smarthings door/window sensor is opened for > x minutes I want Alexa to tell me so. There are scripts for sending an SMS - but the trouble I’m having is triggering Alexa - has anyone with the exception of Rboy figured this out?

You can open a virtual sensor and use that to trigger an Alexa routine as the final step of whatever your logic is.

This used to work really well with the original smartthings skill. Then they changed the skill a few months ago and now it can be flaky for some people. But it’s worth a try.

Here’s the FAQ:

FAQ: Can I trigger an Echo Action without Speaking to It?

JDRoberts

Thank you.

Using original code by Smarthings “Left it Open”, I created a new routine and virtual switch - then updated the SMS code in the Left it Open, added code to flip the switch and that than triggers the Alexa routine to speak along with sending an SMS to me. Thanks for the idea and if anyone wants the code changes I made, happy to share.

Solved: How to make a sensor trigger Alexa after X minutes.

1 Like

Schaffer,

Can you please share the code changes. This is exactly what I am looking for now.

Thank you!

RW - Here ya go - original code by Smartthings - Alexa call added by myself.

indent preformatted text by 4 spaces/**
  • Copyright 2015 SmartThings
  • Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except
  • in compliance with the License. You may obtain a copy of the License at:
  •  http://www.apache.org/licenses/LICENSE-2.0
    
  • Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
  • on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
  • for the specific language governing permissions and limitations under the License.
  • Left It Open
  • Author: SmartThings
  • Date: 2013-05-09
  • Updated : M.Schaffer 2020-10-10
    */
    definition(
    name: “Left It Open”,
    namespace: “smartthings”,
    author: “SmartThings”,
    description: “Notifies you when you have left a door or window open longer that a specified amount of time.”,
    category: “Convenience”,
    iconUrl: “https://s3.amazonaws.com/smartapp-icons/ModeMagic/bon-voyage.png”,
    iconX2Url: “https://s3.amazonaws.com/smartapp-icons/ModeMagic/bon-voyage%402x.png
    )

preferences {

section(“Monitor this door or window”) {
input “contact”, “capability.contactSensor”
}

section(“Flip this switch when it happens”) {
input “alexacall”, “capability.switch”
}

section(“And notify me if it’s open for more than this many minutes (default 10)”) {
input “openThreshold”, “number”, description: “Number of minutes”, required: false
}

section(“Delay between notifications (default 10 minutes”) {
input “frequency”, “number”, title: “Number of minutes”, description: “”, required: false
}

section(“Via text message at this number (or via push notification if not specified”) {
input(“recipients”, “contact”, title: “Send notifications to”) {
input “phone”, “phone”, title: “Phone number (optional)”, required: false
}
}
}

def installed() {
log.trace “installed()”
subscribe()
}

def updated() {
log.trace “updated()”
unsubscribe()
subscribe()
}

def subscribe() {
subscribe(contact, “contact.open”, doorOpen)
subscribe(contact, “contact.closed”, doorClosed)
}

def doorOpen(evt) {
log.trace “doorOpen($evt.name: $evt.value)”
def delay = (openThreshold != null && openThreshold != “”) ? openThreshold * 60 : 600
runIn(delay, doorOpenTooLong, [overwrite: true])
}

def doorClosed(evt) {
log.trace “doorClosed($evt.name: $evt.value)”
unschedule(doorOpenTooLong)
}

def doorOpenTooLong() {
def contactState = contact.currentState(“contact”)
def freq = (frequency != null && frequency != “”) ? frequency * 60 : 600

if (contactState.value == “open”) {
def elapsed = now() - contactState.rawDateCreated.time
def threshold = ((openThreshold != null && openThreshold != “”) ? openThreshold * 60000 : 60000) - 1000
if (elapsed >= threshold) {
log.debug “Contact has stayed open long enough since last check ($elapsed ms): calling sendMessage()”
sendMessage()
alexacall.on()
runIn(freq, doorOpenTooLong, [overwrite: false])
} else {
log.debug “Contact has not stayed open long enough since last check ($elapsed ms): doing nothing”
}
} else {
log.warn “doorOpenTooLong() called but contact is closed: doing nothing”
}
}

void sendMessage() {
def minutes = (openThreshold != null && openThreshold != “”) ? openThreshold : 10
def msg = “{contact.displayName} has been left open for {minutes} minutes.”
log.info msg
if (location.contactBookEnabled) {
sendNotificationToContacts(msg, recipients)
} else {
if (phone) {
sendSms phone, msg
} else {
sendPush msg
}
}
}