How to make preferences and settings require dimmer value when a selected switch happens to have that capability?

Does anyone know how have preferences and settings ask for dimmer value when a selected switch happens to have that capability?
I know this is possible because the routines always ask for the desired dimmer values when there’s at least one dimming capable device in a list of selected switches.

here is how it looks like in my desperate attempts…

 input (name: "controlEDSwitch", type: "capability.switch", title: "control these swithces ", multiple: true, required: true, submitOnChange: true)
           if(controlEDSwitch) {
                if(device?.typeName?.equalsIgnoreCase("Dimmer")){

                    input (name: "SetLevel", type: "number", range: "1..100", title: "Set $controlEDSwitch level to this value", required: true, default: 50)
                }
            }
        }

I’m fairly new to this myself, but here’s some pointers:

(1) that input needs to be part of a dynamicPage() so that the if statement
gets executed when you go to that preferences page
(2) to figure out whether the switch supports setLevel, you probably should use capabilities: Something like
if (controlEDswitch.capabilities.contains(capability.switchLevel) ... (haven’t tried this, though)
(3) You probably want the SetLevel option to appear right away after you select a dimmer as the controlEDSwitch, you should be able to achieve this using “submitOnChange: true” on the switch input line

1 Like

Thanks a lot @KG72.

It seems that it doesn’t work (and yes, it’s all in a dynamic page). But it looks like I’m getting closer. Let me know if you can make this work.

Elfège.

This works for me:

            input (name: "controlEDSwitch", type: "capability.switch", title: "control these swithces ",
            	required: true, submitOnChange: true)
//           	if (controlEDSwitch &&
//            	controlEDSwitch.capabilities*.name.contains("Switch Level")) {
           	if (controlEDSwitch?.hasCommand("setLevel")) {
	        	input (name: "controlEDSwitchLevel", type: "number", range: "1..100",
            		title: "Set $controlEDSwitch.displayName level to this value",
               		required: true, default: 50)
            }

The commented out version of the if statement works, too, but I think using hasCommand() is nicer.

It works indeed! Should have gone to bed before trying! :blush:

Thanks a lot!

And... if I may... :) Would you happen to also know how to get an app to check if the location is in one of multiple modes set as conditions in the settings? In other words, can you save my a... again? :) Thanks!

UPDATE : found it...

if(location.currentMode in LimitedMode) { }

Elfège.

Hi!

Would you know how to get a setLevel command to apply only to the devices which have this capability within a multiple selection of switches?

Thank you.

Untested, but something like the following should work:

switches.each {
    if (it.hasCommand("setLevel")) {
        it.setLevel(...)
    }
}

That was fast! :smile: Thank you so much!

And since you do miracles… would you happen to have figured out how to send tcp packets through hubaction by any chance? :stuck_out_tongue: