SmartThings Community

How to use range option?


(Dale C) #1

I wrote a smartapp that I want to restrict valid entries from 0.5 through 9.9 in the preferences section for user input. I am using the optional setting of range to do this. I am trying to only allow the user to input an updated value between 0.5 though 9.9

If I use this range: “1…99” it allows me to use any of those valid inputs between 0.5 though 9.9 however also the ones outside of 9.9 like 10 and up to 99. This is what one would expect.

How am I supposed to write the line of code with range to limit the user between 0.5 and 9.9?

If I change it to range: “1…9” I can only use whole integers or else it causes an error and the preference will not be updated.

So the question is did I find a bug or how do I define the range correctly to restrict valid entries to be only within say 0.5 through 9.9

Here is the line of code below that isn’t working right.

section(“Enter the desired differential temp between fan speeds (default=1.0)…”){
input “fanDiffTemp”, “decimal”, title: “Fan Differential Temp”, range: “1…99”, required: false
{


(Jody) #2

This is not all the way to 9.9, but it will get you started as it contains .5-9.5

​(1..19)*.div(2)​

Further adjustments can get you to 10ths or more.


(Dale C) #3

thanks for the reply! Interesting, so I am not sure how I implement this? I put your fix in the parameters and it gives errors

section("Enter the desired differential temp between fan speeds (default=1.0)..."){
	input "fanDiffTemp", "decimal", title: "Fan Differential Temp", range: "(1..19)*.div(2)" required: false
}

(Mike Maxwell) #4

maybe use an enum, you don’t have that many choices, particularly if you do them in .5 degree increments


(Dale C) #5

That is a great idea since the range: “x…y” is buggy. Thanks Mike !!

I was hoping to make my ceiling fan thermostat smartapp more user friendly for those outside the US that use °C instead of °F and the default of 1°C for those using Centigrade is going to be more than most would want since every degree Centigrade converts to almost 2 degrees Fahrenheit


(Mike Maxwell) #6

you could use something like this to auto generate the enum options based on the users location temp units.
This is from an SA of mine, it may work in a DTH, don’t know.

def zoneFixedOptions(){
	def opts = []
    def start
    if (!state.tempScale) state.tempScale = location.temperatureScale
	if (state.tempScale == "F"){
    	start = 60
        start.step 81, 1, {
   			opts.push(["${it}":"${it}°F"])
		}
    } else {
    	start = 15
        start.step 27, 1, {
   			opts.push(["${it}":"${it}°C"])
		}
    }
	return opts
}

then: in the input, options : zoneFixedOptions()


(Dale C) #7

That is awesome! I definitely want to make the enum change and will look at your code to make it smarter :relaxed: BTW, which smartapp of yours uses this?


(Mike Maxwell) #8

that snippet is from keenectZone…


(Dale C) #9

Well it sure looks great when I set it up as enum but it totally breaks the smartapp. I am wondering if the enum returns only text versus number values which is causing the problem when I try to use it’s value?

Is there a trick to converting enum values from text to number value that anyone knows of?


(Mike Maxwell) #10

yea, enums return text, depending on the numeric data type
use myInput.toInteger() or myInput.toBigDecimal()


(Dale C) #11

Got it! I will give it a try. :slight_smile: