First SmartApp not working

I’m following the First SmartApp tutorial and have reached the Simulator section. I can run the SmartApp on the simulator and I can see the log messages when simulated motion is detected, but theswitch never turns on. I’ve tried using both a simulated switch and one of my actual physical switches and the behavior is the same. I can toggle the switch from the simulator (and, on my physical switch, observe the actual switch toggle in response), but when simulated motion is detected, nothing happens to the switch (regardless of initial state) even though the log messages wrapping the .on() call are both printed. What can I do to fix this problem?

Here’s my code minus the definition block. Both the “motionDetectedHandler called” and “theswitch should have been turned on” log messages are printed when simulated motion is detected, but the switch does not turn on.

preferences {
    section("Turn on when motion detected:") {
        input "themotion", "capability.motionSensor", required: true, title: "Where?"
    section("Turn on this light") {
        input "theswitch", "capability.switch", required: true

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


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


def initialize() {
	subscribe(themotion, "", motionDetectedHandler)

def motionDetectedHandler(evt) {
    log.debug "motionDetectedHandler called: $evt"
    log.debug "theswitch should have been turned on"

I’m by no means an expert yet, but I’ll share my 2 cents, because no one else is chiming in.

I made my first app yesterday and it wasn’t working. I went home and tried it again,without changing the code, and it worked fine.
The simulator seems a little wonky to me (which is a bit concerning).

So maybe logging out of smarthings and back in would help.

As far as the physical switch not working, maybe reset your hub?

Are there any errors in live logging? The event should show up on the switch, assuming it supports the on() command, you should be able to look at the Device Handler code to see if it exists (most switches should have this). Use log.debug alot. Maybe the switch name is not being set correctly.

log.debug ("theswitch is ${theswitch}")

DH SImulators rarely work, so I wouldn’t depend on them.

John, thanks for the data point – that seems like the most likely reason to me. I’ll try again tonight. The physical switch does work though – at least, it works as well as the simulated switch. It’s still not activated by motion in the SmartApp, but I can turn it on and off by clicking on the switch tile in the web IDE.

desertblade, I haven’t seen any runtime errors in anything I’ve done with the SmartThings IDE. I’ve seen compile errors when I click save (when I do something wrong – my fault), but nothing during runtime yet. I have the .on() method wrapped in two log statements so I can see that it should be run. I’m not a Groovy expert; are there circumstances where a switch wouldn’t have/support on(), but invocation of that method would not throw any exception nor print any error (fail silently)?

As a partial aside, if there are log.debug statements in a device handler, should I expected those messages to show up in the log window when developing a SmartApp with the simulator?

Yes there are. The IDE is not a full development system, so you don’t always see the console logs if you were developing on locally.

When motion is triggered there should be an event in the Light Switch live log. If its getting to the the second debug statement that means the method is completing so it mush have fired the on command, just need to know if the switch picked it up.

In theory they should show up with the simulator.

post your ide logs.

John was right – I pulled up my SmartApp, didn’t change anything, and it worked correctly. Also, SmartThings said I had no SmartApps for a while (I have 3) and then suddenly decided to show them. Seems like the development environment is just a little flaky.