Really would appreciate if anyone could give me some help or guidance. I’m trying to write an app so that I will get a notification ONLY if acceleration happens twice in a user defined period of time. I’ve pieced the following together from other smart apps.
preferences {
section("Which Accelerometer?"){
input "accelerometers", "capability.accelerationSensor", title: "Which", multiple: true
}
section ("What Period of Time?"){
input "frequency", "decimal", title: "Minutes", required: true
}
section("Send this message (optional, sends standard status message if not specified)"){
input "messageText", "text", title: "Message Text", required: false
}
section("Via a push notification and/or an SMS message"){
input "phone", "phone", title: "Phone Number (for SMS, optional)", required: false
input "pushAndPhone", "enum", title: "Both Push and SMS?", required: false, metadata: [values: ["Yes","No"]]
}
}
def installed()
{
subscribe(accelerometers, "accelerometer.active", accelerometerActiveHandler)
}
def updated()
{
unsubscribe()
subscribe(accelerometer, "accerlometer.active", accelerometerActiveHandler)
}
def accelerationActiveHandler(evt) {
def deltaMinues = "frequency"
def timeAgo = new Date(now() - (60 * deltaMinutes))
def recentEvents = accelerationSensor.eventsSince(timeAgo)
log.trace "Found ${recentEvents?.size() ?: 0} events in the last $deltaMinutes minutes"
def alreadySentSms = recentEvents.count { it.value && it.value == "active" } > 1
if (alreadySentSms) {
sendMessage
} else {
log.debug "did not happen twice"
}
}
private sendMessage(evt) {
def msg = messageText ?: defaultText(evt)
log.debug "$evt.name:$evt.value, pushAndPhone:$pushAndPhone, '$msg'"
if (!phone || pushAndPhone != "No") {
log.debug "sending push"
sendPush(msg)
}
if (phone) {
log.debug "sending SMS"
sendSms(phone, msg)
}
}
I have FINALLY stopped getting errors while trying to just save the app. However now when I run it in the simulator I get the following error
(groovy.lang.GroovyRuntimeException: Ambiguous method overloading for method script14063079272841487926851#subscribe.
Cannot resolve which method to invoke for [null, class java.lang.String, null] due to overlapping prototypes between:
[interface java.util.Collection, class java.lang.String, class java.lang.String]
[class physicalgraph.app.InstalledSmartAppWrapper, class java.lang.String, interface java.util.Map]
[class physicalgraph.app.LocationWrapper, class java.lang.String, interface java.util.Map] @ line 50)
Thanks in advance.