Input range question

Valid values are 1 through 60 and 255. Is it possible to structure this in an input field with range as a restriction?

For example, this is what I want to do but doesn't work.

input "parameterEighteen", "number", title: "Motion Timeout Duration (1 to 60 minutes or 255 = 5 seconds) Default: 4 minutes",  defaultValue: 4, required: false, range: "1..60,255"

Hmm, interesting use case.. im curious if something like this is possible as well.

for now, what about using 0..60, where 0 = 5 seconds.

That's the simple fix. I have to make life hard on myself though. Trying to keep the inputs consistent with manufacturer documentation.

I wasn't able to find a way to make this work, but perhaps someone more creative can think of something. Normally something like 1..60 would give you a collection like an IntRange, but Hubitat wants that as a string and not an actual range. If it didn't , (1..60).add(255) would give you what you wanted.

This works:

def myRange = 1..60
input /* ... */ range: myRange.toString()

but this fails:

def myRange = (1..60).add(255)
input /* ... */ range: myRange.toString()

So, I don't know. Maybe staff who know more about how that works on the inside can comment. Otherwise, just thought I'd throw out what I know...or don't, apparently. :slight_smile:

Yea, I tried all kinds of goofy tricks but this one is a tough cookie. Using 0 is probably the best option just me being stubborn.

Making it an enum instead would work with whatever values you want, but for 61 options, that's a big dropdown. :smiley:

1 Like

The only way for this to work is to do the range check separately from the input. RM has to do this where it allows the use of a variable reference in what would otherwise be a number input. This needs to be on a dynamic page to work, and it needs someway to give UI feedback for a bad value. Unlike range: "0..60", it won't stop a bad input, just catches it.

2 Likes

I have the catch before it sets the param but no user feedback. I was trying to add the range so the user gets the feedback without me jumping through hoops. That didn't work out though lol.

if (param18 < 1 || param18 >255 || (param18 > 60 && param18 != 255)) {

What RM does is use a text input (so it can use %varName%). Then it tests the input, and if bad changes the setting to **Bad Value. Since it's a dynamic page, the user sees this displayed. That display is caused by a forced page refresh.

1 Like

Going to go with 0 since it's the easiest. Thanks for chiming in and confirming my suspicions.

1 Like

Anyone know how to guarantee an input is an integer for a driver. I tried type input of "integer"

This let me put in 45.5 and worse i need it for minutes and the range restriction ie range:1..59

Is not enforced. Changing it to "number" at least the range is enforced but i still can put in 5.5

For now i have a very ineloquent approach.

Ie

// make sure inputs are integers note cannot do this directly inline in the update statements as they come out as 2.0 instead.

   def runTimeInt = runTime.toDouble().trunc().toInteger()
   def runTimeOnBatteryInt = runTimeOnBattery.toDouble().trunc().toInteger() 
      
   device.updateSetting("runTime", [value: runTimeInt , type:"number"])
   device.updateSetting("runTimeOnBattery", [value: runTimeOnBatteryInt , type:"number"])

@kahn-hubitat You could use an enumerated list. That would force the user to select a pre-determined value that is a whole number.

Here's an example from one of my drivers.

input "parameterThirteen", "enum", title: "Motion Sensitivity (Default: 'High')", options: [1:"Low", 2:"Medium", 3:"High"], defaultValue: 3, required: false

You could reference a static field in the options section to fit a long list.

@Field static List<Map<String,String>> eventNotificationOptions = [
["0": "Bolt/frame strike protection Triggered"],
["1": "Lock Physical"],
["2": "Unlock Physical"],
["3": "Lock Digital"],
["4": "Unlock Digital"],
["5": "Fire/Medical Panic Triggered"],
["6": "Presence Arrival Unlock"],
["7": "Presence Departure Lock"],
["8": "Switch Triggered Lock"],
["9": "Switch Triggered Unlock"]

Ya thanks. Knew that..but not creating a list that long. Integer should enforce the range option and also that the number is an integer in my opinion anyway.

I agree.

1 Like