Confused about SmartApp sections

Hi - have a quick question that should be easy for an experienced dev here.

I have defined 2 sections as follows:

section (“Which switch(es) control the heating?”) {
input(“heatingSwitches”, “capability.switch”, title: “Which switches?”, multiple: true, required: true)
}
section (“Which switch(es) control the hot water?”) {
input(“hotwaterSwitches”, “capability.switch”, title: “Which switches?”, multiple: true, required: true)
}

What I am finding now is that the switch group [heatingSwitches] is an array of all switches selected regardless of which section they were selected under.
So when I switch ‘on’ the heatingSwitches, those switches PLUS all the hotwaterSwitches are switched on.

Have I misunderstood something here?

Thanks and regards,
Sean

no. This should give you two separate lists of switches. (Of course you could add the same switches to both)

Thanks for the response and that was my understanding too - but with this code later in the app:

def toggleSwitches(){
    
    def switches = null
    def switchtype = params.switchtype
    def state = params.state

	switch(switchtype){
	    case "heating":
    	        log.debug "Toggling Heating:"
    	        switches = heatingSwitches
                break;
            case "hotwater":
    		log.debug "Toggling HotWater:"
    		switches = hotwaterSwitches
                break;
    }...

I get the following output (and affects those switches):

62fdbea3-530c-4eba-b9c0-3164430e23f8 12:00:31 AM: debug [Heating, HotWater]
62fdbea3-530c-4eba-b9c0-3164430e23f8 12:00:31 AM: debug Toggling Heating: 

Not sure why both switches are in the one group as I’ve definitely only selected one per section in the app.

Does the above look like the correct way to do this?

Without seeing the full code, it is difficult to debug, but a few suggestions:

  1. In the web ! ide, you can view details of the smart app by going to locations -> installed smartapps, to see what is stored in state and preferences.
  2. I would recommend different names for Local variables in methods that don’t overlap with ST defined globals

Thanks a million for that pointer Tony. I didn’t realise that existed and once I hovered over the update link I could see that it was obviously still tethered to an older version of my code.

I cleaned it up and reinstalled the app and all is now working as expected.

EDIT: your point about variable naming is also very valid - it escaped me that ‘switches’ is probably a reserved word. I didn’t change that for it to work but will do so now as best practice.