Actions - Turn on Light ONLY after Sunset AND Motion is Detected

Hi there,

In a hallway, I have installed a SmartThings motion sensor and a Hue lightbulb.

What I am trying to achieve is that, the light should ONLY turn on if it’s after sunset and motion is detected. The light should NOT turn on if motion is detected and it’s during the day.

I know I can create an action with 2 events (if motion is detected and if at sunset) but that won’t work as sunset only occurs once. I know I can also create an action with 2 events (if motion is detected and if after this specific time) but that is a huge pain as you will have to adjust it constantly to be this hour and that hour especially since the system already knows what time sunset is based on zip code or hub location. Not only that, but this is all assuming that the code statements for above are actually using an “AND” operation and not an “OR” operation which I have a feeling it might unfortunately be an “OR” which wouldn’t work.

What I’m hoping to achieve is an action with the following 2 events together in an “AND” operation…

  1. If motion is detected
  2. If after sunset

Such with that, the light should only turn on if it’s after sunset AND motion is detected.

I’m hoping I don’t have to create another device type with custom code as this seems like a very very basic piece of functionality in a system based on automatic schedules so I’m sure I’m missing something, if so, I’m sorry for the question.

Thanks all for any help!

You can create 2 modes (Before Sunset, After Sunset). Use Magic Home to change the modes of the house. The motion app only runs in after sunset mode.

Hi there Mike,

Thanks for the suggestion!

I went ahead and searched for the post containing Magic Home and gave it a try.

For being a new user and not first understanding the full functionality of smart things, which is my fault 100%, the app was pretty confusing, even after reading all the replys in that post.

I have never even used modes or phrases before, which I am now, and just relied on setting actions manually so perhaps ST will make these features more obvious in future updates as my brother ran into the same boat as me and isn’t fully utilizing the modes/phrases.

I have had no luck with the Sunset and Sunrise options of the mainstream apps, they work for one day and then falter. What I have had great success with is using a LUX sensor (AEON Multi) to detect low/high light conditions and the Smart Nightlight app. When it gets dark or there is a very overcast day the lights start to work on motion; no more waiting for just Sunset or Sunrise. I also have modified the LUX values for each floor (2 instances of the app) as the top floor receives more light than the bottom floor.

1 Like


I will keep an eye out for any inconsistencies with using sunset/sunrise so thanks for the update but so far for the past week it’s been working great “fingers crossed”! :smile:

I can definitely see a use case however with the sunset not being very useful in sections of the house which don’t receive much light as sunset is a tiny bit pointless in that aspect, but not totally pointless of course since you are still based on some sort of illumination levels!

You can try this app created by @AaronRon Dusk-to-Dawn Dimming Motion Light - RC1

1 Like

Hi! It’s @AaronZON (not AaronRon). No worries! This app should work but there is currently no option for the light to be off after sunset and before sunrise - only a selectable dimmed level. It should be a fairly simple matter to add a ‘0%’ option. However, there is also a routine that brings the lights on at 30% and then dims to the selected level at sunset. This is to resolve a problem with my LED bulbs that do not light off, but run fine at very low dimmed states. Logic could be added to look for a 0% setting and skip the start routine.

Also, it should be noted that, starting this year, I’m having problems getting the sunrise handler to fire. I’m not sure what is causing this. I may be looking into some changes and/or adding some redundancies.

UPDATE: Not sure if the OP is still interested. . . but, I have resolved the issue with the sunrise handler. The code linked in the thread noted in Navant604’s post above.

Totally lost here.

First, I am confused on the difference between Action and Modes. I can see within the St app how to create an action but nowhere can I create a mode. Am I to assume they are both the same thing? Assuming they are. I create this “Sunset” mode/action but nowhere can I specify this actually means a specific time of day for my location.
Like I said, totally lost. :frowning:

No, action and modes are not the same. Not 100% clear on this myself so take this FWIW. Actions are just SmartApps. ‘Mode’ is an attribute of a location. A location can have any number of possible modes (ST sets up a few by default). You can use SmartApps to change modes based on some conditions. SmartApps can also do things conditionally based on the current mode.

I understand how I can change a mode (Home, away, night) as well as have certain things happen when a particular mode is active (i.e. turn on light when mode=Night). What I dont understand is how to create a mode to specify either sunset or sunrise. Above, Jabbera suggested:

You can create 2 modes (Before Sunset, After Sunset). Use Magic Home to change the modes of the house. The motion app only runs in after sunset mode.

I understand how to change a mode using an app such as Magic Home but such change should only occur at a calculated time (i.e. at Sunset for my location). This is what confuses me.

There is a SmartApp ‘Sunrise/Sunset’ that will do this, I think. I don’t remember where it is exactly but I know you can get to it via the mobile app.

1 Like

Perfect… Found it and installed it :smile:
Now if I can only figure out how to add the sunset/sunrise modes I would be all set. I suppose I could use the default “Night” and “Home” modes but that would rather be limiting. Because I want to set a 30 minute offset for Sunset, in this scenario my modes would change from Home to Night 30 minutes prior to actual sunset.

Anyway, thank you for pointing me in the right direction.

Bingo… I found how to add new modes… The problems was I had been working on my (non-mobile) iPad ST App which does not appear to have the ability to add new modes. My Android Mobile phone app however does.

  • On the dashboard, click the menu icon at the top left of the screen (stripe bars)
  • On the new (Home) screen, click the gear icon at the top right. This displays the wscreen where you can set your physical home location via a map.
  • Scroll to the bottom of this screen and voila…There you will find a section labled “Modes”. Within the section is an option to add a new mode.

Pfft I have seen the light :smile:

Sorry for jumping in on this subject but I have a related question and help needed. I am trying to get a mode change when a contact closes and or opens but have not found exactly what I am needing. Any help would be appreciated.

@zuperman4ever, there must be something that already exists. If not, I think you can use the SmartThings app, Sunrise/Sunset as a pattern for a new app that does what you want. It uses sunrise and sunset events as triggers for mode changes that can be configured in the app preferences. Seems like it would be pretty easy to change it to use contact events to do the same.

Yeah, I figured that but I am still in the learning process on learning the code to do it properly and language to use. So yeah I am working on that, it will just take me a little bit.

Sorry about the delay, I have actually been using the “Magic Home” app listed by @jabbera and it’s been working great in terms of turning my light on ONLY when…

  1. It’s after sunset
  2. motion is detected
  3. someone is home

so therefore if we are away from home, the cat can’t set the home sensor light to always trigger on/off constantly but you may actually want that though!

@zuperman4ever yea it seems like by default, with the contact sensor, you can set it up to use the contact open/close when in particular modes but unfortunately not the other way around where you want a trigger a mode when the contact sensor is open or closed.

Listed below is a link to a post I made on configuring “Magic Home” if you guys were ever interested in trying that out, let me know if it helps out…

1 Like