# A little help with my first SmartApp please

**URL:** <https://community.smartthings.com/t/a-little-help-with-my-first-smartapp-please/43669>\
**Category:** Writing SmartApps\
**Created:** [March 29, 2016, 11:19pm UTC](https://community.smartthings.com/t/a-little-help-with-my-first-smartapp-please/43669 "2016-03-29T23:19:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![royeiror](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/royeiror/32/22078_2.png) [@royeiror](https://community.smartthings.com/u/royeiror)\
**Post date:** [March 29, 2016, 11:19pm UTC](https://community.smartthings.com/t/a-little-help-with-my-first-smartapp-please/43669/1 "2016-03-29T23:19:31Z")

</div>

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](https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png)”,  
> iconX2Url: “[https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png](https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png)”,  
> iconX3Url: “[https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png](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!”)  
> }  
> }

---

<div class="post-metadata">

**Author:** ![ahndee](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/ahndee/32/18084_2.png) [@ahndee](https://community.smartthings.com/u/ahndee)\
**Post date:** [March 29, 2016, 11:23pm UTC](https://community.smartthings.com/t/a-little-help-with-my-first-smartapp-please/43669/2 "2016-03-29T23:23:49Z")

</div>

You should probably take a look at Rule Machine:

> [@Rule machine - as per the app developer, this app is no longer available for new installs, distribution, or support](https://community.smartthings.com/t/release-rule-machine/28730):
>
> Rule Machine is no longer available.

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

---

<div class="post-metadata">

**Author:** ![bravenel](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/bravenel/32/13223_2.png) [@bravenel](https://community.smartthings.com/u/bravenel)\
**Post date:** [March 29, 2016, 11:26pm UTC](https://community.smartthings.com/t/a-little-help-with-my-first-smartapp-please/43669/3 "2016-03-29T23:26:01Z")

</div>

> [@ahndee](#):
>
> This would be easy using a “Triggered Rule”:

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

---

<div class="post-metadata">

**Author:** ![Ron](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/ron/32/80532_2.png) [@Ron](https://community.smartthings.com/u/Ron)\
**Post date:** [March 30, 2016, 3:33am UTC](https://community.smartthings.com/t/a-little-help-with-my-first-smartapp-please/43669/4 "2016-03-30T03:33:56Z")

</div>

I second Rule Machine !

I used to write my own smart apps, not anymore 🙂

---

<div class="post-metadata">

**Author:** ![royeiror](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/royeiror/32/22078_2.png) [@royeiror](https://community.smartthings.com/u/royeiror)\
**Post date:** [March 30, 2016, 6:59am UTC](https://community.smartthings.com/t/a-little-help-with-my-first-smartapp-please/43669/5 "2016-03-30T06:59:19Z")

</div>

Just tied it, it’s amazing.
