Retreiving Enum Preference Value Not Working

I am trying to evaluate a ENUM preference to do a Celcius to Fahrenheit conversion and for some reason, all I get is “null”. Here is the preference code. Does anyone know how to retrieve the proper value of an ENUM preference option? I verified it’s being stored in the Device properly int he IDE. I also tried settings.tempscale and that didn’t work either.

	input("tempscale","enum", title: "Temperature Scale", options: ["Celcius","Fahrenheit"], required: true, displayDuringSetup: true)

Whether I select C or F in the preferences of my device handler, with this code:

log.debug “Current Preferences: Temp Scale - ${tempscale}”

I get this in the debug logs:

Current Preferences: Temp Scale - null

Where on the code are you trying to get the pref values? In a command method?

In a “def” further down below int he code. If I change the preference to text, it reads it perfect. It’s just when it’s a “enum”, does it return “null”.

I think this has been identified as a bug, try the more explicit version of Input…
name : “dimDark”
,title : “When it’s Dark out…”
,multiple : false
,required : true
,type : “enum”
,options : [[“10”:“10%”],[“20”:“20%”],[“30”:“30%”],[“40”:“40%”],[“50”:“50%”],[“60”:“60%”]]

1 Like

Unfortunately, that didn’t do it:

input(“tempscale”,“enum”, title: “Temperature Scale”, options: [[“Celcius”:“Celcius%”],[“Fahrenheit”:“Farhenheit%”]],required: true, displayDuringSetup: true)

Output from log.debug “Current Preferences: Temp Scale - ${settings.tempscale}”:

Current Preferences: Temp Scale - null

Is this in an href page or something?, can you put up a link to the entire sa?

I thought enum inputs only supported strings.

Have you always been able to use them like this?

Yes for over two years anyway, though it’s not well documented, nor frequently implemented…

1 Like

So in your example, the user will see “10%”, but settings.tempscale will return “10”?

correct!, nice eh?

I’ve even gotten craftier in my quest to reduce personal keyboard input…

//within a dynamic page:
	name			: "maxVo"
	,title			: "Maximum vent opening"
	,multiple		: false
	,required		: true
	,type			: "enum"
	,options		: maxVoptions()
	,defaultValue	: "100"
	,submitOnChange	: true
//later in the SA body					
def maxVoptions(){
	def opts = []
    def start = minVo.toInteger() + 5
    start.step 95, 5, {
    opts.push(["100":"Fully open"])
    return opts
1 Like

My issue is that the ENUM options, settings.tempScale are not being retrieved throughout the entire portion of my code. When I reference it from certain areas of my code, the value shows null, but in other areas it’s showing up with the proper value. I assume it’s some sort of lack of defining it globally somewhere, but I am unclear how to make it globally available.

Anyone have any idea?

settings.whatever by definition are global, so no idea what the issue is here…

This is what I can’t wrap my head around. It’s extremely frustrating! I’ve seen other working code all over GH and this forum and I am literally doing the same thing and it’s returning null! If I reference it in my refresh method, it reads properly. If I call it from another method in my code, it will return null.

Here is the preference:

	input("tempScale", "enum", title: "Temperature Unit:", options: ["Celcius", "Fahrenheit"], defaultValue: "Celcius", required: true, displayDuringSetup: true)

I will reference it as settings.tempScale. i.e: log.debug settings.tempScale

It can be frustrating! Device Handler preferences are only available to command methods (which is why it works inside refresh()) as documented here.

Sorry for the confusion, that is why I asked earlier about where in the code you were referencing the preferences, but I should have been more explicit/direct :disappointed:

Thanks @Jim. Makes sense. So how do get that value to be used in another method? I tried storing it in another variable, and that didn’t work either. Is there any option? I am basically trying to determine temperature scale of the end user and doing the necessary calculations based on preference.

What about using the Location temperatureScale and then using unit option when sending the temp event? You can see an example of this in this commit.

(More theoretical, but it’s possible you could store the preference variable in state and reference it later, but that would be pretty gross because you’d have to do that inside a command method to begin with, and might have other downsides)

It turns out, Tesla (this is for a DH I am currently working on) allows you to poll the Temp Units from the car itself and I can pull that into my DH. That probably makes more sense since the owner of the car is going to want the temperature in the DH to match without explicitly stating so. You would think an American car company would default to Fahrenheit for units, huh?