Run, if light/audio is not on


I have some apps that run based on motion, and it works great, but I have scenarios that cause issues.

For example when the lights turn on, 90% of the time I am happy with the 60% light level and everything works great, but the one time I turn up the lights to full, 30-60 seconds later I trigger the motion and the lights go back to 60%.

Same thing with Music, I turn on my Sonos with motion and set the audio level, I want it a little louder so I turn it up, but as soon as I trigger motion it turns it down again…

How do I stop this? I can create a custom app, use virtual switches, but seems like it should simpler than that…ie: if motion, only turn the light on if its off, same with sonos!!!

I am using the Smartthings Smart Lighting for most of these apps…


I am doing something very similar with using a Hue bulb as a notification indicator (ie when someone is arriving home). The trick is storing the current state of the device’s properties BEFORE manipulating it in response to a trigger and then returning it to those original values after running your app’s main logic.

Here’s the general logic flow in my custom app:

  1. Person arrives home (trigger)
  2. Collect current state of hue bulb (is it already on? what color/intensity is it?)
  3. Process logic for notification (set color, turn on, blink, etc)
  4. Turn bulb off
  5. Reapply previous color settings
  6. Return bulb to the on/off state it was in previously.

You can see the code here:

Thats funny, not really what I am looking for here, but its the exact other topic I have been wanting to investigate… I am going to try your code now!!

As for my current issue, I can see how this applies, but really what I am looking for is to just have nothing happen…to be honest I have looked at a bunch of custom ideas to tackle, but I feel like I am missing something and it should be simpler.


I think I understand your goal now! Hopefully you can use a similar approach by checking the existing state of the target device before running your app’s logic.


IF sonos is OFF
run logic
do nothing

I will get in line with you and wait for smartthings’ default apps to provide an UNLESS attribute so we can use things like smart lighting automation and specify a situation in which it should NOT run the app (other than based on home mode).

You need to define your toggle situation. When motion is active turns volume. When you manually change volume, you could suspend the motion trigger, but then when would you want to resume the motion activity? I am still defining a similar use case, but…I am not there yet. Maybe you can help me…And I write the app.


Just playing with your app, really nice! I added contact sensors as I have my garage doors working with them and your code works great for HUE lights…now I need to see if I can get it to work with my LIFX too! Your colour selection is not working for me (at least in the simulator) bu tI will take a closer look…

This is a great app, I have wanted to use this for many triggers and really unleash the power of HUE/LIFX but I have not had time to play with it much…

thanks for the feedback! It’s the first one I’ve been able to write from start to finish, and most of the actual Hue code was inspired by the Hue Mood Lighting template. It had just enough to get me through some of the syntax needs. Definitely check that out if you need more examples to check.

I have been away from my system all week for work, but I intend to test with real light as soon as I get home.


If we are going to write a new app, I think the best way from my research is to use virtual switches to create states… I don’t really want to stop the motion from being detected and acted on, but I do want to stop it from changing the state on multi state devices such as dimmers, and audio.

I have thought about using multiple apps to first turn it on, then set level/volume but it kind of defeats the purpose, I don’t want SONOS super loud for the 2 seconds while the second trigger runs!

The basic logic in Smartapps can make it difficult to really define the needs, and understand if one custom app is better then a bunch of smaller apps essentially all doing the same thing…

The other issue is…from what I understand only the Smart Lights app is running local and thus allows motion activated scenes to happen quickly… As soon as you go custom, you are in the cloud (for now at least) and this means that motion activated apps sometimes fire so late there is no point turning on the light anymore!!

Sorry, that got a little rambly!! but I think you will get the point!

Unfortunately, the motion doesn’t change the state of your switch, but rather the switch changes its state based on the motion event. So to prevent the motion to trigger a change, you will need to find another condition to restrict the switch from acting on the motion event. For example, when motion is active AND something else happens, don’t dim the switch.

As for the local processing, while it is true that only Smart Lighting runs locally, only locally installed official devices qualify. So none of the cloud based or custom type devices are running locally. That includes Hue bulbs connected to a Hue bridge, Sonos speakers, Wemo switches, virtual switches, etc. The only advantage for local processing is not that runs faster, but that it runs without Internet. Most of my apps using motion sensors run in the cloud and the delay is really not that noticable comparing to those that run locally.

Would Rule Machine help? I haven’t installed it yet so I don’t know for sure whether it will do what you want but it seems promising.