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)
}
}
}
}
