Conditional preferences

Hi,

I have 2 types of bulbs in my home, ones that support color change and others that only support temperature change. I want to do a single app that allows me to configure some actions for both cases, but in one case I’ll be changing color and in the other the temperature.

So far, I am stuck at the preferences because I can’ t make preferences to appear conditionally depending on a capability. So far I have the following (that compiles) but that gives me a blank page after selecting the bulb:

preferences {
  page(name: "examplePage")
}
def examplePage() {
  dynamicPage(name: "examplePage", title: "", install: true, uninstall: true) {
    section {
      input name: "theBulb", type: "capability.switch", required: true, submitOnChange: true
    }
    if(theBulb) {
    if(theBulb.hasCapability("colorControl")) {
	input "color", "number", required: true
      } else {
      input "temperature", "number", required: true
      }
      }
  }
}

Any idea how to proceed? Is there another way to implement this?

Thanks!

This is embarrassing (and I cannot delete the post :sweat:), in my defense I really tried before asking.

I forgot the “section()” for the conditional attributes. The “hasCapability” didn’t worked for my LIFX bulbs, but the hasAttribute(“color”) worked perfectly. I left you my code if any interested:

preferences {
  page(name: "examplePage")
}
def examplePage() {
  dynamicPage(name: "examplePage", title: "", install: true, uninstall: true) {
    section {
      input name: "theBulb", type: "capability.switch", required: true, submitOnChange: true
    }
    if(theBulb) {
    if(theBulb.hasAttribute("color")) {
        section() {
	  input "color", "number", required: true
        }
      } else {
        section() {
        input "temperature", "number", required: true
        }
      }
      }
  }
}
2 Likes

Not embarassing at all, happens to all programmers. And some of us write code for airplanes…