Function not executing

I have used this code for over a year and today it stopped working.

def initialize() {                  
    if (modeSwitch != null) {
        subscribe(modeSwitch , "switch", modeHandler)
    }
    
    log.debug("settings: ${settings}")
}

def modeHandler(evt) {
	log.debug("mode handler ${evt.value}")
    
	statusCheck(evt.value)
}

The weird part, other than that it use to work, is that it always responds to Off, but not On. If I comment out statusCheck, it responds to both On and Off (by the way, if statusCheck is included, the debug line never executes). Lastly, regardless of what statusCheck does (i.e. an empty function or something useful), if it’s there, On’s do not execute (no errors, no debug statements, nothing). Removing and reinstalling the smart app didn’t fix it either.

Ideas?

Known issue with smartapps/routines today. Intermittent, apparently. See the Status page

Or other forum threads.

Sorry to correct you, but not a known issue with SmartApps.

The known issues that your link refers to points out issues with routines controlling devices, email issues, etc. (although they’re fine now according to the status page).

Thanks, @JDRoberts, but the status page makes no mention of my issue. I would expect it to show up under SmartApp execution.

Any thoughts @slagle?

It was both smartapps and routines, although the status page announcement only mentioned routines, the thread I linked to discusses both and gave a smartapp example in a screen shot. You make be seeing yet another problem, that’s always possible.

I saw that. So the status page wasn’t accurate (thanks for noticing that - lol). As for the SmartApp screen shots, they directly reference routines.

So I stand by my original statement. Could be related, but definitely different circumstances.

And by the way, the code doesn’t fail, it just never executes.

I think @ady624 ran into a similar issue, couple of weeks ago, but it was supposed to be fixed. I looked for the conversation on the CoRE thread, but I couldn’t find it. Maybe Ady can chime in.

1 Like

Rename statusCheck… See if that helps? Thinking maybe ST invented an inherited/injected function with that name that messes with your code?

1 Like

Good idea. I tried that before I posted (and just tried again just in case). No dice.

Is that all the code? Can I try it too? Paste it here, should be tiny? :wink:

1 Like

Other than statusCheck, yes, it’s all the code. Any function called causes the On to fail 100% of the time - none of the code executes (not even the debug line). I can call statusCheck with nothing in it other than a debug statement (or empty for that matter) and it will fail to run (I tried it). BUT Off always works - 100% success (???).

def statusCheck(mode) {
	log.debug(">>>>> statusCheck ${mode}")
}

Can you please paste all the code, so I can just paste it into a SmartApp?

I had stripped virtually everything out as shown below and it was failing.

I should have tried this earlier, but creating a new app and pasting in the original code, and (now) it works. Somehow an error or corruption occurred and was associated with the original app. When I came home I noticed that off worked, but on didn’t. I checked live logging and noticed that on appeared not to fire. I wish I knew what caused the corruption. Thanks for the help.

definition(
    name: "Test App",
    namespace: "johnlcox",
    author: "john.l.cox@live.com",
    description: "Test",
    category: "Convenience",
    iconUrl: "http://cdn.device-icons.smartthings.com/Seasonal%20Winter/seasonal-winter-002-icn@2x.png",
    iconX2Url: "http://cdn.device-icons.smartthings.com/Seasonal%20Winter/seasonal-winter-002-icn@2x.png"
)

preferences {
	page(name:  "pageMovie", title: "About", nextPage: "pageNotification", uninstall: true) {
      	section("Fun") {       
        	paragraph "Select the switch that initiates fun mode." 
            
			input "modeSwitch", "capability.switch", title: "Switch?", required: false, multiple: true          
		}
	}
    
	page(name: "pageNotification", title: "Notifications", install: true, uninstall: true) {
    	section( "Notifications" ) {
        	input "sendPushMessage", "enum", title: "Send a push notification?", metadata:[values:["Yes","No"]], required:false, defaultValue: "No"
			input name: "phone1", type: "phone", title: "Text phone number 1", required: false
       	}

		section([mobileOnly:true]) {
            label title: "Assign a name", required: false
            //mode title: "Set for specific mode(s)", required: false
        }
    }
}

def installed() {
    initialize()
}

def updated() {
	unsubscribe()
    unschedule()
    state.clear()
    initialize()
}

def initialize() {                  
    if (modeSwitch != null) {
        subscribe(modeSwitch , "switch", modeHandler)
    }
    
    log.debug("settings: ${settings}")
}

def modeHandler(evt) {
	log.debug("***** mode handler ${evt.value}")
    
	statusCheck(evt.value)
}


def statusCheck(mode) {
	log.debug(">>>>> statusCheck ${mode}")
}

One thing I noticed, during the three months I’ve had ST (wow, just three months) - if you try to set a “wrapper” into the state, the whole app fails with NO logs, NO errors, NO nothing. Make sure you’re not saving a Device, an Event, a SmartApp, etc. into any state variables. If you do…

If you copy the non-stripped version into a new SmartApp, does it work?

1 Like

Yes. Copying the exact code and pasting as a new app - Yes. I had deleted it from the mobile app and re-installed - didn’t work. Sorry. I should have deleted the SmartApp from the IDE and re-added it.

I wasn’t trying to set a wrapper - thanks for the heads up.

Thanks for helping.

2 Likes

Can anyone tell me my the switch event handler fires but the light event handler does not?

Here is a snippet:

input “switches”, “capability.switch”, title: “Which Switches?”, required:false, multiple: true
input “lights”, “capability.switch”, title: “Which Lights?”, required:false, multiple: true

def initialize() {
subscribe(switches, “switch”, handleSwitchEvent)
subscribe(lights, “switch”, handleSwitchEvent)
}

def handleSwitchEvent(evt) {
sendValue(evt) { it == “on” ? “true” : “false” }
}

I’m experiencing a similar thing.

I can get the Off to execute, but the On won’'t execute if there is anything in the function other than a debug statement. I noticed the issue today. It worked yesterday for me. The code has worked for over a year.

Interesting,do you have a similar situation where you have 2 different groups of devices with the same capability? Where the handler works for one set but not the other?

I do. I did get my issue fixed (at least for now). Deleting the app from the IDE, re-adding it, and subsequently re-installing it fixed my issue. All of which would imply some sort of corruption (in the cloud).

That solution does not work for me. Can anyone reproduce the issue I described with the code I provided above and explain what is going on?

Why are you subscribing to two sets of the same capability type for the same method. In theory that should work but try consolidating. If that works we’ve found a bug but will have fixed your issue.