Garage Door Virtual Open/Close Sensor no longer an option in SmartApp


(Matt B) #1

I just got around to updating the following code that we needed to change:

subscribe(multisensor, “acceleration”, accelerationHandler, [filterEvents: false])

I replaced the two instances it appeared in my code with the suggested:

runIn(delayInSeconds, “eventHandler”)

The app was working fine until recently (do the fact that I hadn’t updated the code). It sends me a push notification when the garage door is open, and I had it set up to send me alerts every 10 minutes if the garage was still open.

However, I have updated the app and published it to myself, but under the option to select which SmartSense multi I want it to monitor, I am only shown an option for one I have set up on my interior doors. The multi sensor that I have attached to my garage door is set up as a virtual open/close sensor and was working perfectly.

I’m not sure why I can no longer select it to be monitored by the app. Any help or suggestions would be greatly appreciate!

Here is the code for the app:

/**

  • Garage Door Time Open Push Notification
  • Copyright 2014 Matt Burrows
  • 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.

*/
definition(
name: “Garage Door Time Open Push Notification”,
namespace: “”,
author: “Matt Burrows”,
description: “Sends a push notification when the garage door is open. Also, sends push about how long garage door has been open”,
category: “”,
iconUrl: “https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png”,
iconX2Url: “https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png
)

preferences {
section(“When the garage door is open…”) {
input “multisensor”, “device.smartSenseMulti”, title: “Where?”
}
section(“For too long…”) {
input “maxOpenTime”, “number”, title: “Minutes?”
}
}

def installed()
{
runIn(delayInSeconds, “eventHandler”)
}

def updated()
{
unsubscribe()
runIn(delayInSeconds, “eventHandler”)
}

/*
The “acceleration” message comes during acceleration, but also is reported every 2.5 minutes, so we listen for
that and then check if the garage door has been open for longer than the threshold.
*/
def accelerationHandlerPush(evt) {
def latestThreeAxisState = multisensor.latestState(“threeAxis”) // e.g.: 0,0,-1000

if (latestThreeAxisState) {
def latestThreeAxisDate = latestThreeAxisState.dateCreated.toSystemDate()
def isOpen = Math.abs(latestThreeAxisState.xyzValue.z) > 250 // TODO: Test that this value works in most cases���������

if (isOpen) {
def deltaMillis = 1000 * 60 * maxOpenTime
def timeAgo = new Date(now() - deltaMillis)
def openTooLong = latestThreeAxisDate < timeAgo
log.debug "openTooLong: $openTooLong"
def recentTexts = state.smsHistory.find { it.sentDate.toSystemDate() > timeAgo }
log.debug “recentTexts: $recentTexts”

if (openTooLong && !recentTexts) {
def openMinutes = maxOpenTime * (state.smsHistory?.size() ?: 1)
sendTextMessage(openMinutes)
}
}
else {
clearSmsHistory()
}
}
else {
log.warn “COULD NOT FIND LATEST 3-AXIS STATE FOR: ${multisensor}”
}
}

def sendTextMessage(openMinutes) {
log.debug “$multisensor was open too long, texting $phone”

updateSmsHistory()
def message = "Your ${multisensor.label ?: multisensor.name} has been open for more than ${openMinutes} minutes!"
sendPush(message)
}

def updateSmsHistory() {
if (!state.smsHistory) state.smsHistory = []
state.smsHistory << [sentDate: new Date().toSystemFormat()]
}

def clearSmsHistory() {
state.smsHistory = null
}