How to turn on a light when 2 triggers happen not one OR the other?


I apologize first hand if i am posting this on a too general of a discussion board AND if this has already been asked several times before. I did find this other post here: When configuring a routine, is each trigger an AND or an OR. That seems to answer my questions. However, this didn’t work for me when i created a routine and put 2 triggers (when my iPhone is not present i.e. i leave AND after sunset).

I noticed it didn’t work, since i left to work and i got a push notification that the lamp turned on.

My settings were:

What do you want to happen?

  • Turn on desk lamp
  • Set dimming to 60%
    Under additional settings:
  • Everyone leaves
  • At sunset

enable push notification.

I have nothing else. I really want to know how to work the app successfully so i set this simple routine to give a nightlight to my dog when i am away from home AND its sunset already.

I know there are many ways to do this, but i want to know the straight forward way to do it or how many ways are there to do this as i am confused on how to make the app work for me. It seems it is simple enough, but i’m not sure i have start coding to do this.

Any help would be greatly appreciated.



Forgive me, I’m confused. Did you try to do this in a routine, or with the smartlighting feature? You mentioned both. These work differently, so it does make a difference.

If you could post a screenshot of what you have set up, we could help you better.

Also note that “after sunset” and “at sunset” are two different conditions. Again, you mentioned both. That’s why the screenshot would help. :sunglasses:

Also, are you using a mode for “away”?

If what you actually want is an “and” condition meaning “if I’m away and it’s after sunset then turn on the light” Mode would be the easiest way.

If I understand you correctly, These are the situations you have to handle:

One) I leave the house before sunset. Then when it is sunset, turn on the light. Sequential events.

Two) I leave the house after sunset. Turn on the light. Simultaneous events.

There are several different ways to do this with the basic features. It may require two rules to catch the two situations. But first I’d just like to know how you tried to do it. And if you’re going to use an away mode or not. :sunglasses:

One more thing…

Arrival/departure is an event that detects someone crossing the Geopresence barrier. You just left or you just came home. So that works well for simultaneous events like “turn on the lights when I get home if it’s after sunset.”

It doesn’t work at all for sequential events. If you leave home at two in the afternoon, then the departure registers at two in the afternoon. But in your case, you want to have a light come on maybe four hours later.

For those, we would usually use the mode “Away.” That one isn’t an event, it’s a state. It’s initiated by an event like someone leaving, but then it persists. So if you left the house at two, and that set the mode two away, the house would stay in away mode until you got home again.

That’s why mode is usually the easiest for these “and” situations because we can test against it when another event happens like “the time is sunset.”

I hope that made sense.

Most of the conditions on a routine are only evaluated in order to determine if it’s time to run that routine. You can’t have two events four hours apart initiating the same routine.

But you can set a mode at two in the afternoon and then use the persistent state of that mode at 6 PM when it’s sunset to see if The system should run a particular routine.

So that’s why the details of how you’re trying to set it up matter, as well as the details of what you’re trying to accomplish.

I know none of this is very intuitive, so don’t worry if it seems confusing at first. Smart things is very powerful, but not very easy to figure out.

You could create a routine that only works when you are in “Away” mode, and turns on the light if it is after sunset. one rule. Should work on entry into Away mode, or passing the terminus while Away.

Yes, if he’s using an Away mode, everything is pretty simple. If he’s not, it gets more complicated. :sunglasses:

I pieced this together, it may work, it may need tweaking for your use:


  • Lights on if nobody home
  • Copyright 2016 Glenn Brockett
  • 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:
  • 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.

name: “Lights on if nobody home”,
namespace: “ac7ss”,
author: “Glenn Brockett”,
description: “Turn on lights if it is dark and presence is absent”,
category: “”,
iconUrl: “”,
iconX2Url: “”,
iconX3Url: “”)

preferences {
section(“Title”) {
input “Switch1”, “capability.switch”, title: "Which lights to turn on?"
input “dusk1”, “capability.illuminanceMeasurement”, title: "Where to get your light reading?"
input “who1”, “capability.presenceSensor”, title: “When who is gone?”

def installed() {
log.debug “Installed with settings: ${settings}”


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


def initialize() {
subscribe(dusk1,“illuminance”, CheckstatusIllum)
subscribe(who1,“presence”, CheckstatusPres)

// TODO: implement event handlers
def CheckstatusIllum(evt)
def Presence = who1.currentPresence
log.debug "$who1.currentPresence $Presence"
if (dusk1.currentValue(“illuminance”) < 900){
If (Presence != “present”) {

def CheckstatusPres(evt)
def Presence = who1.currentPresence
log.debug "$who1.currentPresence $Presence"
if (Presence != “present”) {
if (dusk1.currentValue(“illuminance”) < 900) {

First off thanks JDR! and Ac7ss!!!

Let try to explain what has happened as this has evolved over the course of today since i have been playing with it.

To reiterate what i’m trying to do (now) is the followin (Goal)

  • Turn on desk lamp when i am not home and it is after sunset
  • Turn on my living room sonos speaker (2 Play 1’s together in stereo) to play the classical station on my pandora

What i did before was focused on only the light and not yet tackling the sonos piece.

However, I will talk about what i have now going as it has greatly evolved and i think that now i am getting a bit more, but still not really working. Now i am using modes FYI :slight_smile:

I have 4 routines and 3 smartapps running to make this happen beyond doing a few other things


  1. Good Morning!
  • Change mode to ‘Home’
  • Automatically perform “Good Morning!” at Sunrise
  • Advanced Options: Don’t automatically do this if I am in one of these modes ‘Away’
  1. Goodbye!
  • Turns off: ALL Harmony activities, desk lamp, Living room sonos
  • Change mode to ‘Away’
  • Automatically perform “Goodbye!” when Everyone leaves (myself only)
  1. I’m Back!
  • Change mode to ‘Home’
  • Automatically perform “I’m Back!” when Someone Arrives (myself only)
  1. Good Night!
  • Turns off: Desk lamp, Living Room Sonos, Harmony activities
  • Change mode to ‘Night’
    (I toggle this at night before going to sleep.)


  1. Smart Lighting
  • Control Desk Lamp
  • Do what turn on
  • Trigger at Sunset
  • Sunset offset in minutes (+/-) -90mins
  • Only during certain days of the week Monday, Tuesday, Wednesday, Thursday, Friday
  • Only when mode is Away
  1. Sonos Smartapp: Stop Playing Music for Ami (aka my dogs name)
  • Arrival of Miguel’s iPhone
  • System Changes Mode Home
  • Action? Stop playing
  • Speaker Music Player Living Room Sonos Master (this is because it is 2 Play 1’s)
  • Assign name Stop Playing Music for Ami
  • Set for specific mode(s) Home
  1. Sonos Smartapp: Start Playing Music for Ami
  • Departure of Miguel’s iPhone
  • System Changes mode Away
  • On this Speaker player Living Room Sonos Master
  • Set volume 30
  • Only on certain days of the week Monday, Tuesday, Wednesday, Thursday, Friday
  • Play this track Classical
  • Assign name Start Playing Music for Ami
  • Set for specific mode(s) Away

This is each thing i have running. Essentially the flow of what i want to happen is this:

  1. Before i wake up ST will put me back into ‘Home’ mode and do nothing
  2. When i leave ST will turn off everything and put the mode to ‘Away’
  3. After i leave Sonos turns back on and plays classical music

If I don’t come back from work by sunset (which is normal) then:
4. Lamp turns on since mode is ‘away’ and it is 90mins before sunset
5. ST will detect i’m back and change mode to ‘Home’ and does nothing else
6. Then when i want to go to sleep i click the ‘Good Night!’ to turn off everything

If I do come back before Sunset then:
4. Lamp doesn’t turn on
5. ST will detect i’m back and change mode to ‘Home’ and does nothing else
6. Then when i want to go to sleep i click the ‘Good Night!’ to turn off everything

If I leave after sunset out of my house:
4. lamp should turn on since i am away and technically it is after sunset.
When i come back
5. ST will detect i’m back and change mode to ‘Home’ and does nothing else
6. Then when i want to go to sleep i click the ‘Good Night!’ to turn off everything

Here is what it is not doing:

  • When i leave the ‘Goodbye’ routine will turn everything off including sonos (as i list above) and when the smart apps for Sonos tries to play music it gets paused (not stopped this is key as it tells me that everything happens very quickly together) - I think i need to have some kind of delay to turn off Sonos and turn it back on to play classical. I want to do this on and off sequence since i could be playing something on sonos in the morning or i could not.
  • Lamp is not even turning on at all i don’t see anything in the logging of this happening.

Here is what it IS doing:

  • detects i’m leaving and ‘Goodbye’ kicks in good
  • detects i’m arriving and the ‘I’m Back’ kicks in and actually stops the Living Room Sonos Master
  • All switching of home to away, away to home, home to night, night to home are all working good (i had head that iOS had an issue responding what mode ST was actually on)

Hope you guys understand what i’m talking about and can help.

Thanks again!!!


Busy night at work, more programming resources are being assigned to getting people off work on time tonight. But here goes…

My suggestion is to break the leaving routines into two parts. One triggers if leaving after dusk, the other triggers if during daytime. (Just make another goodbye routine such as “Goodbye-Night”)

I can’t really help unless you can post the screenshots. I rely on text to speech and it’s hard to follow the flow of lists like you have.

(I can see somewhat but I get double vision if I read too much so I mostly listen. Screenshots are a lot easier to read.)

One obvious question just to get out of the way: are you sure you saved the smart lighting automation that is supposed to turn a light on at sunset -90 minutes?

There is one last page where you have to click done in the upper right after you said all the parameters. If you don’t do that it doesn’t get saved.

You can check to make sure it’s there with the following steps:

One) open the mobile app

Two) choose the checkmark icon at the bottom of the screen

Three) choose “smart apps” at the top of the next screen

  1. now you should see a list of whatever smartapps you have installed, including Smart Lighting. Tap on “smart lighting.”

  1. The next screen will say automations near the top and should list all your individual smart lighting automations.

Just checking make sure that you don’t have any extra automations and that the one that turns on the light is there.

Device log

Now check the recent activity for that specific light.

  1. choose the rooms icon (four little squares) at the bottom of the screen)

  2. choose “things” at the top of the next screen. This will open your list of devices.

  3. scroll through the list of devices until you find the specific lamp that is controlled by your sunset routine. Then tap on the name of that lamp (not the icon on the left or the right of it, just the name) this will open that device’s detail screen.

  4. on the detail screen, click on “recently” at the top of the screen.

  1. This will open the recent events for this specific device. Now you can see any smart lighting automations or other smart apps that sent commands to the lamp.

In the example below, “guestroom table” is the name of the lamp and “guest room SL” is the name of the smart lighting automation which is turning it on and off. :sunglasses::bulb:

I use the ios SmartRules app to do this myself. Its simple and works well.

Thanks Everyone!

I have changed things a bit today on this.

I have also added stringify to my flow for the light and separated my good bye flow.

Now i have this (adding screenshots).


  1. Good Morning!
  1. Goodbye!

basically all it does is place it in away except that i put a delay here that is longer than the ‘turn everything on routine’

  1. I’m Back!
  1. Good Night!
  • Turns off: Desk lamp, Living Room Sonos, Harmony activities
  • Change mode to ‘Night’
    (I toggle this at night before going to sleep.)
  1. Turn everything off

Right now i am no longer using smarttlights and using stringify to turn on the desk lamp for my dog. It seems stringify will periodically check if the lamp is still on even despite the fact that my “turn everything off” is executing. I will see how well it works as the days go by. I also put a ticket on stringify to very if this is how it works.

David H. - Thanks for the suggestion! I didn’t know that existed! I am using Stringify and may use it more and more if it works as i think it does (periodically checking if the flow is still working).




I did save if properly. What i think was happening is that my ‘good bye’ routine was cancelling out the smart lighting. This is because the ‘good bye’ routine was both turning everything off AND turning the mode to away. Since now i have separated the two into two different routines with each different delays i think now it will work with anything that i want to turn back on. Since i have the ‘turn everything off’ to execute 10min after my phone is away and then after 10 more mins i change modes to away. This way whatever turned off that is suppose to turn back on will turn back on.

Thanks David!

Do you use this for all your rules on smartthings? As in do you use any routines on smartthings native app?



I use them for the majority of my rules.

ST seem to be limiting. To do what you needed in Routines, I woukd have to set and away day and away night. Seemed like a lot of work for one rule. I could use Smart lighting app but seemd limited. Smart rules basically lets me do just about everything. I can back the rules up and import them as well. It has great IFTTT CAPABILITIES. Hers my current routines.

To do what you want in smart rules. Let ST handle the presence of everyone and switch to away mode (or whatever mode you prefer) when they are all gone.

Then right this rule…

1 Like

SmartRules is excellent and very easy to use. :sunglasses: I found it Well worth the $10 in the App Store. It’s basically “if A while B, then C.” so it adds one more level of complexity, but it’s a very useful level.

Core is much more powerful, but also much more complex to set up and use. Quite a few people use both just because SmartRules is nice for the simpler stuff. And many people find SmartRules is all they need.

Unfortunately, there’s no android version – – it’s only available for iOS. But if you have an iOS device, it’s well worth looking at.

Hi David,

So your routines in ST don’t technically do anything except toggle the mode
to your desire? Is this correct?



My routines set the initial state of everything. Goodbye will set all lights off, doors locked, camera on, motion sensor activation and so on.

Thanks David!

I am currently using a combo between ST and Stringify which seem to work well for the time being.

Will look into smartrules to see how it runs when i get more sensors, but seems to do the same thing as stringify.