Trying to create my first SmartApp so forgive me in advance. I’m trying to allow the user to select a mode, possible modes’ when installing the app. Then I set a schedule to watch for mode changes, and if the current mode is one of the selected modes, then continue. But it seems like the input mode is always null.
Trying to troubleshoot my idea, I simplified my code to a very basic scenario:
preferences { section("At this time every day") { input "time", "time", title: "Time of Day" } section("Change to this mode") { input "newMode", "mode", title: "Mode?" } } ... def changeMode() { log.debug "changeMode, location.mode = $location.mode, newMode = $newMode, location.modes = $location.modes" if (location.currentMode == newMode) { log.debug "currentMode equals newMode" } if(location.modes.find {it == newMode}) { log.debug "Newmode is a valid mode" } if (!(location.currentMode == newMode)) { log.debug "current Mode not equal to New Mode" } }
When I run this, and my user selected ‘Mode’ is the same as my current mode (Current mode is ‘HomeDaytime’, user selected mode is ‘HomeDaytime’), the first two ‘IF’ statements are returning false and the 3rd is executing. I would expect the 1st two to execute, but it seems that the input mode is always null.
Log:
7e735c0b-9289-4f0c-bb70-49d341294c0c 11:28:12 AM: debug current Mode not equal to New Mode 7e735c0b-9289-4f0c-bb70-49d341294c0c 11:28:12 AM: debug changeMode, location.mode = HomeDaytime, newMode = null, location.modes = [HomeEvening, AwayNight, HomeDaytime, SleepingDay, AwayDaytime, Sleeping] 7e735c0b-9289-4f0c-bb70-49d341294c0c 11:27:58 AM: debug changeMode, location.mode = HomeDaytime, newMode = null, location.modes = [HomeEvening, AwayNight, HomeDaytime, SleepingDay, AwayDaytime, Sleeping] 7e735c0b-9289-4f0c-bb70-49d341294c0c 11:27:58 AM: debug Installed with settings: [time:2016-09-03T11:30:00.000-0500, newMode:null]