Is it possible to code this Smart App?

Hey guys. I have a new idea for a smart app possibly for bathrooms or short time occupancy rooms.

is it possible to code this.

  • Door sensor (open or close) switches lights on for 45-60 seconds.
  • Motion Sensor detects motion, overrides door sensor timer and sets timer to 15-30min
  • when door sensor triggers again, override motion timer and set timer to 45 seconds.

Can this chain of events be set to reoccur in this format continuously. Without a reqiurement for either door or motion to occur first.

Thank You Guys

yes, this is possible

Can you help with coding this? or do you know if something like this already exsists?

You can use the runIn method, as long as your handler is the same each time, the previous job will get overwritten.

So… (mostly pseudo-code so you’ll have to fill in the gaps and this is only a basic guide)

*** Door sensor open/close ***
light.on()
runIn(60, turnOffLight) // Set timer for 60 seconds

*** Motions sensor detects motion ***
light.on()
runIn(60*15, turnOffLight) // Set timer for 15 minutes

...
def turnOffLight() {
    light.off()
}

So, when either of those things trigger, the timer will overwrite whichever one is currently running if there is one as long as it uses the same handler (according to the documentation)

Hope this is what you were looking for.

The documentation mentions something similar to what you want to do:

http://docs.smartthings.com/en/latest/smartapp-developers-guide/scheduling.html#schedule-from-now

1 Like

In my head, I would perhaps look at using the runIn scheduling method to schedule a defined TurnOffLight subroutine in "minutesLater for and use the unschedule method to cancel the scheduled TurnOffLight call if other priority events are observed by the other sensors.

  • runIn( minutesLater, TurnOffLight )
  • unschedule(TurnOffLight)

Thank you guys, is there any way to get a code that I can copy paste. Im not good at this at all.

Can someone help me actually code this. I can read endlessly and I still won’t get it?

You should look at installing the new Rule Machine smart app that @bravenel has so graciously gifted to us.

I am pretty sure it can do what you are looking for. [quote=“bravenel, post:852, topic:28730”]
Download both Rule Machine and Rule from Github: https://github.com/bravenel/Rule-Trigger/blob/master/smartapps/bravenel/rule-machine.src/rule-machine.groovy and https://github.com/bravenel/Rule-Trigger/blob/master/smartapps/bravenel/rule.src/rule.groovy

Install Rule Machine in your IDE and Publish for me
Install Rule in your IDE but do not publish
[/quote]

1 Like