Input menu issue with default value

I have a profile page in the app with a temp selector for each profile. I would like to add a unit selector switch but something is wrong and dont know what! When I select LO or HI, everything is ok but as soon as I select a temp and switch units, the menu get empty and if I switch again it comes back to LO as default. I try to get the actual value, check the index value in array, then takes the right array with this index to get the right corresponding temp and make it default in the menue. In the log, those value are returned, its like the menu wont takes it...

here the code and the print of the profile page

def profilesPage()
{
    dynamicPage(name: "profilesPage", title: "<strong>Review/Edit Vehicle Start Options</strong>", install: false, uninstall: false) {
        section(getFormat("header-blue-grad","Settings: Set units")) {
                input(name: "unit", type: "bool", title: "Use °C ?", defaultValue: true, submitOnChange: true)
        }
        
         def tempOptions =""
            def tempOptions2 =""
            def position =""
        
        for (int i = 0; i < 3; i++) {
            String profileName = "Summer"
            switch(i)
            {
                case 0: profileName = "Summer"
                    break
                case 1: profileName = "Winter"
                    break
                case 2: profileName = "Profile3"
            }
            
           
            if(unit != true) {
                  tempOptions = ["LO", "62", "63", "64", "65", "66", "67","68", "69", "70", "71", "72", "73", "74", "75", "76","77", "78", "79", "80","81","82", "HI"]
                  tempOptions2 =["LO","17", "17.5", "18", "18.5", "19", "19.5", "20", "20.5", "21", "21.5", "22", "22.5", "23", "23.5", "24", "24.5", "25", "25.5", "26", "26.5", "27","HI"]
            }else{
                 tempOptions = ["LO","17", "17.5", "18", "18.5", "19", "19.5", "20", "20.5", "21", "21.5", "22", "22.5", "23", "23.5", "24", "24.5", "25", "25.5", "26", "26.5", "27","HI"]
                 tempOptions2 = ["LO", "62", "63", "64", "65", "66", "67","68", "69", "70", "71", "72", "73", "74", "75", "76","77", "78", "79", "80","81","82", "HI"]
            }
            if(tempOptions.findIndexOf{it==settings["${profileName}_temp"]}>-1){
                position = tempOptions.findIndexOf{it==settings["${profileName}_temp"]}
            }
            if(tempOptions2.findIndexOf{it==settings["${profileName}_temp"]}>-1){
                position = tempOptions2.findIndexOf{it==settings["${profileName}_temp"]}
            }
            log("position  ${profileName} is "+position,"trace")
            log("value  ${profileName} is "+tempOptions.get(position),"trace")
            log("temp  ${profileName} is "+tempOptions,"trace")
            log("temp2  ${profileName} is "+tempOptions2,"trace")

            section(getFormat("header-blue-grad","Profile: ${profileName}")) {

                input(name: "${profileName}_climate", type: "bool", title: "Turn on climate control when starting", defaultValue: true, submitOnChange: true)
                input(name: "${profileName}_temp", type: "enum", title: "Climate temperature to set", options: tempOptions, defaultValue: tempOptions.get(position), required: true)
                input(name: "${profileName}_defrost", type: "bool", title: "Turn on defrost when starting", defaultValue: false, submitOnChange: true)
                input(name: "${profileName}_heatAcc", type: "bool", title: "Turn on heated accessories when starting", defaultValue: false, submitOnChange: true)
                input(name: "${profileName}_ignitionDur", type: "number", title: "Minutes run engine? (1-10)", defaultValue: 10, range: "1..10", required: true, submitOnChange: true)
            }
        }
    }
}

Can you put a log message within these If statements to verify the findindexof function is working each time through the for loop?

I just add it to be sure and it return the right thing, also, this log before the input value : log("value ${profileName} is "+tempOptions.get(position),"trace")
also return the right value but the input default just not keep it... I try with manual value like : "62" and works but only if the value is in the array which is normal I think...

As I said, the LO & HI values are in both array so those are working great... Dont know why it wont takes the array changes...

Can you try changing all the number values to a text string to see if it works that way? Maybe its in issue with the number values being an integer.

Same result! But if I have the same value in both array its working. Its like it keeps the first array before the modif and try to switch at the end of code (after the default value) so the .get value is not found... But the .get value is correct in the log... Its like the input is completly rebuilt like it was 2 different object (before modif & after). I tried to move the if block somewhere else but no success! Even if I try with a fix value like "62", it works only if I invert the array because the value is part of that array...but its the old one...

Ok, I tried to built a mixed array with both values and if odd, do position +1 else position -1 and still not working. So it really looks like it wont takes any of the numbers... But I tried with toString() but still nothing! Do you know how I could solve this?
thanks!

** I also tried to change one of the value for a letter at the same index and its not working, except if its the same letter... So its not just the string its the fact its looking for the same digit in the array... But the log gives the right value... I think that the input() is getting updated after the changes... or something like that... **

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.