A little help with my first SmartApp please

I went around trying to get a cookie cutter way to get a notification when my cat was at the door using a motion sensor. But since I don’t want to be flooded with notifications I want to make it so the notification is only sent when the door is closed. If the door is open, the cat can come and go as she pleases and I don’t want to have a notification, but if the cat is at the door, I’d like to be notified so I can open the door and let her in.

I have no experience programming so I got stuck following the tutorials because I found no way to have the two conditions met before the message being pushed.

This is what I have right now.

/**

  • Pet Doorbell
  • Copyright 2016 Rodrigo Carvajal
  • 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: “Pet Doorbell”,
namespace: “royeiror”,
author: “Rodrigo Carvajal”,
description: “This app is meant to notify when the main door is closed and movement is detected outside the door.”,
category: “Pets”,
iconUrl: “https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png”,
iconX2Url: “https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png”,
iconX3Url: “https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png”)

preferences {
section(“Motion sensor for pet detection:”) {
input “motionSensors”, “capability.motionSensor”, required: true
}
section(“Door to monitor:”) {
input “contactSensors”, “capability.contactSensor”, required: true
}
section(“Send Push Notification?”) {
input “sendPush”, “bool”, required: false,
title: “Send Push Notification when motion sensed and door closed”
}
}
def installed() {
log.debug “Installed with settings: ${settings}”

initialize()
}

def updated() {
log.debug “Updated with settings: ${settings}”

unsubscribe()
initialize()
}

def initialize() {
subscribe(motionSensors, “motion.active”, motionDetectedHandler)
subscribe(contactSensors, “contact”, contactHandler)
}

def contactHandler(evt) {
if(“open” == evt.value)
// In case the door is open, ignore the motion sensor
log.debug “Contact is in ${evt.value} state”
if(“closed” == evt.value)
// If the door is closed then notify of motion
log.debug “Contact is in ${evt.value} state”
}
def motionDetectedHandler(evt) {
log.debug “motionDetectedHandler called: $evt”
}
def doorClosedHandler(evt) {
if (sendPush) {
sendPush(“It seems like your pet wants to get inside!”)
}
}

You should probably take a look at Rule Machine:

This would be easy using a “Triggered Rule”:

Set “motion occurred” as a trigger
Set “door closed” as a condition
Set “Push message” as the action when true

2 Likes

It’s called a Conditional Trigger, and that’s the way you find it in the app.

2 Likes

I second Rule Machine !

I used to write my own smart apps, not anymore :slight_smile:

Just tied it, it’s amazing.