Help with modifying photo burst when app to delay how frequently it is triggered

This should be easy but I’m really new to groovy and struggling.

I want to modify the existing “photo burst when” app to delay how frequently it takes photos and sends alerts. I wanted to add a stopwatch to the event handler so that once it’s triggered it cannot be activated again for X minutes.

Since you cannot pass additional parameters into the event handler I’m at a loss. I tried unsubscribing the item that activated the event and then running a “runin5minutes” method that called the subscribe events. That causes an exception error though.

Any thoughts?

/**

  • 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.
  • Photo Burst When…
  • Author: SmartThings
  • Date: 2013-09-30
    */

definition(
name: “Photo Burst When…”,
namespace: “smartthings”,
author: “SmartThings”,
description: “Take a burst of photos and send a push notification when…”,
category: “SmartThings Labs”,
iconUrl: “https://s3.amazonaws.com/smartapp-icons/Partner/photo-burst-when.png”,
iconX2Url: “https://s3.amazonaws.com/smartapp-icons/Partner/photo-burst-when@2x.png
)

preferences {
section(“Choose one or more, when…”){
input “motion”, “capability.motionSensor”, title: “Motion Here”, required: false, multiple: true
input “contact”, “capability.contactSensor”, title: “Contact Opens”, required: false, multiple: true
input “acceleration”, “capability.accelerationSensor”, title: “Acceleration Detected”, required: false, multiple: true
input “mySwitch”, “capability.switch”, title: “Switch Turned On”, required: false, multiple: true
input “arrivalPresence”, “capability.presenceSensor”, title: “Arrival Of”, required: false, multiple: true
input “departurePresence”, “capability.presenceSensor”, title: “Departure Of”, required: false, multiple: true
}
section(“Take a burst of pictures”) {
input “camera”, "capability.imageCapture"
input “burstCount”, “number”, title: “How many? (default 5)”, defaultValue:5
}
section(“Then send this message in a push notification”){
input “messageText”, “text”, title: “Message Text”
}
section(“And as text message to this number (optional)”){
input(“recipients”, “contact”, title: “Send notifications to”) {
input “phone”, “phone”, title: “Phone Number”, required: false
}
}

}

def installed() {
log.debug "Installed with settings: ${settings}"
subscribeToEvents()
}

def updated() {
log.debug "Updated with settings: ${settings}"
unsubscribe()
subscribeToEvents()
}

def subscribeToEvents() {
subscribe(contact, “contact.open”, sendMessage)
subscribe(acceleration, “acceleration.active”, sendMessage)
subscribe(motion, “motion.active”, sendMessage)
subscribe(mySwitch, “switch.on”, sendMessage)
subscribe(arrivalPresence, “presence.present”, sendMessage)
subscribe(departurePresence, “presence.not present”, sendMessage)
}

def sendMessage(evt) {
log.debug “$evt.name: $evt.value, $messageText”

camera.take()
(1..((burstCount ?: 5) - 1)).each {
	camera.take(delay: (500 * it))
}

if (location.contactBookEnabled) {
    sendNotificationToContacts(messageText, recipients)
}
else {
    sendPush(messageText)
    if (phone) {
        sendSms(phone, messageText)
    }
}

}

Disregard! I learned about the “state” variable and was able to create a stopwatch that way.

1 Like