location.mode.getId() missing method exception?

when trying to retrieve unique system identifier of the mode it throw this error:

3:34:28 PM: error groovy.lang.MissingMethodException: No signature of method: java.lang.String.getId() is applicable for argument types: () values: []
Possible solutions: getAt(groovy.lang.EmptyRange), getAt(java.util.Collection), getAt(java.util.Collection), getAt(groovy.lang.EmptyRange), getAt(groovy.lang.Range), getAt(java.lang.String)

according to doc here that should be an available property for mode:

http://docs.smartthings.com/en/latest/ref-docs/mode-ref.html#mode-ref

tried both with location.mode and user input mode from smartapp settings. also tried location.mode.id with same results.

thanks.

I have it working fine in a smartapp method using it like this:

def updated() {
	log.debug "Updated with settings: ${settings}"
    def curMode = location.currentMode.getId()
    log.debug "The current Mode ID is: ${curMode}"
}

‎6‎:‎09‎:‎41‎ ‎PM: debug The current Mode ID is: dac2e714-3898-4ee9-b6ce-832eef3594aa

Which matches the mode UUID I can find in my Hub modes definitions in the IDE page.

For the mode name:

def updated() {
	log.debug "Updated with settings: ${settings}"
	unsubscribe()
	subscribeToEvents()
    def curMode = location.currentMode.getName()
    log.debug "The current Mode name is: ${curMode}"
}

‎6‎:‎09‎:‎41‎ ‎PM: debug The current Mode name is: Home

It works in a device too.

I am not sure what you are trying to do but you can refer to this smartapp code https://github.com/tslagle13/SmartThingsPersonal/blob/master/smartapps/tslagle13/thermostat-mode-director.src/thermostat-mode-director.groovy when it comes to comparing a mode to apply a action versus the current mode. It doesn’t use the getID or getName but just directly location.mode.

Hope it helps.

2 Likes

first, thank you.

yes, getId() seems to work fine on location.currentMode. however, when trying the same on an input it seems to consistently fail when trying something this:

    input "modeSelected", "mode", title: "Which mode?", required: false, multiple: false
    ...
    def modeID = modeSelected.getId()

trying to figure out how to get the id for an user selected mode .

thank you for the link, but i am trying to do something a little different for the app i am working on.

EDIT: should note i was mistakenly using location.mode instead of location.currentMode in the test. fixing that fixes the issue for getId() on current mode as @Philippe_Portes pointed out. however, getId() on an user selected mode from settings still does not seem to work.

Hooo… take care, I believe an input delivers a string. That’s not enough to make it a mode so basically, if you apply the getId() to the result of input, you are asking what is the getID of a string and that cannot work.
You might refer to this documentation example that compares modes like strings in my understanding.
http://docs.smartthings.com/en/latest/smartapp-developers-guide/modes.html, the example at the end.

1 Like

yeah just finding that out. :slight_smile: was thinking like device input which delivers a device object, mode would also deliver a mode object. unfortunately that doesnt seem to be the case. :frowning:

thanks again.

1 Like

Preferences section (Inputs and Tiles) are parsed contents with very basic features so either you end-up with strings or with proprietary attributes which makes it very basic in term of usage. Nothing fancy to expect there.

1 Like

I don’t believe that location.mode has an Id. AFAIK it only returns a string.

@Jim

yes, found that out the hard way. thought mode input returns the mode object just as device input returns the device object.

thank you.

1 Like