Enumerate through settings/preferences

What’s the secret to walking through all the settings (${settings}), looking for Switch devices so I can .getNetworkDeviceId and see if it is the one I need to take action with>

I’ve tried messing around with settings.each {}, but then I end up with Name=Value, and I have been unsuccessful trying to use tokenize(’=’) or split(’=’) to break them up…
Would be nice if I could just use settings.each and then test hasCapability(‘switch’), but so far no luck…

Any great pointers you have, I’d appreciate them…


You’ve seen my other posts, the issue is RunIN() doesn’t properly pass MAPs
And I have some reusable callBacks that would point to one device or the other…

I’ve can pass the device ID, or Name, or other property ok, but I need to be able to re-establish a reference to the darn Device itself… One though was to walk through $settings, and compare each input… but obviously I cant .getNetworkDeviceId on all input types… it’ll throw an error…

Not sure what you’re trying to do, if you have a device object in one of your settings, then access it directly via the input parameter used to save the object references.

2 Likes

I’ve finally figured out how to get through the settings, but how the hell do I re-establish a pointer to a specific device in settings, so I can execute .on() or .off() against it? :sa:

def getSwitchById(id) {
     settings.each { 
      try {
        //def supportedCaps = it.value.capabilities
        //supportedCaps.each {cap ->
        //  log.debug "Device $it.key supports the ${cap.name} capability"
        //}
        if ( it.value.hasCapability("Switch") ) {
          //log.debug "Switch: $it.key = $it.value - ${it.value.getId()}" 
          if ( "${it.value.getId()}" == "${id}" ) {
              log.debug "FOUND $it.value!"
              Switch = it.value
            }
        }
      }
      catch(e) {
        //log.error "$it.value -->> $e"
      }
    }
  return Switch
} 

def StopTimerCallback(data) {
//initialize()
log.debug “StopTimerCallback: Begin”
//log.debug “Settings: ${settings}”
log.debug “Relay is $data”
log.debug “Relay is $data.Zone”
log.debug “Relay state is ${getSwitchById(data.Zone).currentSwitch}” // Still results in null

log.debug "StopTimerCallback: End"    

}

Please avoid cross posting to multiple Topics. (This has been considered improper forum etiquette for literally decades.)

I responded here on your original Topic:

1 Like

No… Forum etiquette is not posting essentially the same discussion or post (nearly a cut and paste) to more than one Topic (and/or Category, depending on the Forum format).

1 Like