Lights on Motion SmartApp?

You can have as many of them (shortcuts) as you want. They just have to have different names. When it says, “Living Room already configured”, that refers to the shortcut called “Living Room”, not the devices.

Or, I have an app that does it automatically for 3 modes and 3 levels. Send me a PM if you want that…

1 Like

Yep, I thought about that as well. However, that seems like it would unnecessarily clutter my interface…an interface that does not sort the same way every time you open it! So, two bad UI issues are deterring me from that.

You need to get over worrying about the mobile app as anything more than a configuration tool. If you need customized UI, just use ActiON. The mobile app is lousy as a UI tool for controlling ST. But, it’s essential for configuring things.


Oh, I agree and I’ll probably do it. (I’ll go find my big boy pants) However, even if you treat it just as a configuration tool, the unnecessary clutter is still not good and causes confusion. Thankfully, I generally have really good naming conventions that help identify and group things properly. Of course, the grouping doesn’t work because that part of the UI doesn’t actually work…and I’m still confused why they don’t just add a sort order of alphabetical and be done with it for now until some sort of re-write.

When you go into Lights & Switches, just hit the gear icon at the top. That will give you an alphabetized list of all of the shortcuts. Or, swipe left in Lights & Switches and you will get an alphabetized list with their current state.

1 Like

@brianlees @bravenel
There is a SmartApp called “Light Turn On Motion” that turn on light when there’s a motion, and turn it off again after motion stopped.

But, I can’t find the code from template at IDE.
Where is it ?

I want to create custom app start from that app, maybe any of you can help to find that code

I remember it being there in the past. Not sure why it isn’t there now. I could have thought I saw it when I was having a few glasses of wine!

Let me tag @Jim. Although this is not really documentation…it sort of is since it is a “core smartapp.” (kinda making that up, but it sounds about right!) Sorry, Jim. Tag, your it. :smile:

It’s called “Light Follows Me”. Let me know if you can’t find it in the IDE - I think it should be there…

Thanks @Jim
at “light turn on motion” there’s a dimming level, at “Light Follows Me” there’s no dimming choice

I’m not good at programming, so I need the exact example for editing the custom app that I want :smile:

Here is the code for a basic “Turn on with motion” app. It doesn’t turn them back off after x minutes, but you can use “Turn off when there is no motion” from Lights & Switches to do that. Maybe this will get you going:

 *  Turn on with Motion
 *  Copyright 2015 Bruce Ravenel
 *  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: "Turn on with Motion",
    namespace: "bravenel",
    author: "Bruce Ravenel",
    description: "Turn on dimmers to preset level",
    category: "My Apps",
    iconUrl: "",
    iconX2Url: "",
    iconX3Url: "")

preferences {
	section("Turn on these dimmers...") {
		input "dimmer1", "capability.switchLevel", title: "Which?", multiple: true, required: true
    section("To this dimmer level...") {
    	input "dimLevel", "number", title: "What level?", multiple: false, required: true, description: "0 - 99"
    section("When there is motion here...") {
    	input "motions", "capability.motionSensor", title: "Which?", multiple: true, required: true

def installed() {
//	log.debug "Installed with settings: ${settings}"


def updated() {
//	log.debug "Updated with settings: ${settings}"


def initialize() {
	subscribe(motions, "", motionOnHandler)

def motionOnHandler(evt) {

Thanks @bravenel
the “Light Follows Me” is almost perfect for me. I just need to add dimming function to that app.
I saw your app using capability.switch level, is that only what I need to add the dimming capability ?

One scenario that I want is, when there’s a motion my Hue bulb is set to 100% brightness, and when motion is stopped it will set to 50% brightness for example.

I already install “Light Turn On Motion” on my ST, that app is can set the dimming level of my light, just need to change the turn off command to reduce the brightness.
But that app is not available at template.

Waiting Jim to find it for me, hehe :smile:

This can be easily added to the app. Add this:

section("When motion stops, set to this level") {
    input "dimLevelOff", "number", title: "What level?", multiple: false, required: true


def motionOffHandler(evt) {

Have a look at Light Director, you have the dimming built in.

Thanks again @bravenel , let me try it

I can’t find ‘Light Director’ from template @daven , is it there with different name ?

Update :
Now I unable to create app that I want using setLevel command, setLevel is working to set my Hue brightness, but I got error message log

errorjava.lang.IllegalArgumentException: Command ‘setLevel’ is not supported. Supported commands: [on, off, poll, configure, refresh, reset] @ line 46

How to add “more option” section on smartapp ?

to chose time, day and mode settings

The code for more options is in two parts: The first part is the preferences, and the second part are the tests to see if the app should do anything when there is motion.

Here is the first part:

section(title: "Motion options", hidden: hideOptionsSection(), hideable: true) {

	def timeLabel = timeIntervalLabel()

	href "timeIntervalInput", title: "Only during a certain time", description: timeLabel ?: "Tap to set", state: timeLabel ? "complete" : null

	input "days", "enum", title: "Only on certain days of the week", multiple: true, required: false,
		options: ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]

	input "modes", "mode", title: "Only when mode is", multiple: true, required: false

And below is the part that does the tests. You would use if(allOk) {.... in the motion handler.

// execution filter methods
private getAllOk() {
	modeOk && daysOk && timeOk

private getModeOk() {
	def result = !modes || modes.contains(location.mode)
//	log.trace "modeOk = $result"

private getDaysOk() {
	def result = true
	if (days) {
		def df = new java.text.SimpleDateFormat("EEEE")
		if (location.timeZone) {
		else {
		def day = df.format(new Date())
		result = days.contains(day)
//	log.trace "daysOk = $result"

private getTimeOk() {
	def result = true
	if (starting && ending) {
		def currTime = now()
//		def start = timeToday(starting).time
        def start = timeToday(starting,location.timeZone).time
//		def stop = timeToday(ending).time
        def stop = timeToday(ending,location.timeZone).time
		result = start < stop ? currTime >= start && currTime <= stop : currTime <= stop || currTime >= start
//	log.trace "timeOk = $result"

private hhmm(time, fmt = "h:mm a")
	def t = timeToday(time, location.timeZone)
	def f = new java.text.SimpleDateFormat(fmt)
	f.setTimeZone(location.timeZone ?: timeZone(time))

private hideOptionsSection() {
	(starting || ending || days || modes) ? false : true

private timeIntervalLabel() {
	(starting && ending) ? hhmm(starting) + "-" + hhmm(ending, "h:mm a z") : ""
1 Like

@nico89s , just search for Light Director , copy and paste code in the IDE from here. New App: Lighting Director

1 Like

Thank you very much @bravenel , i’ll try it tomorrow
The link is not available @daven

Strange, I click on the link in my post or the one on the right labelled New App: and it jumps right there.

i mean the link to github, but it’s working now, thanks