I'm writing a thermostat driver that has an option in the preference menu to set Fahrenheit or Celsius based temperature. Based on that information, I would like to set a specific range of temperatures for minimum and maximum set points also in the preference menu (5 to 30 Celsius or 41 to 86 Fahrenheit). How could I do that as a dynamic option?
What's the reason for wanting / needing to set the scale (Fahrenheit or Celsius)? Is it to account for potential differences in the setup of the thermostat being integrated, or the different scale on the HE hub? Depending on why you want to do it may offer up different alternatives...
I'm trying to mimic all the options the thermostat provides in its website for setting it up to make it local and supporting all the features on the webpage.
Yeah, the thermostat provides a feature where you can predefined a minimum and maximum temperatures that the manual control on the thermostat itself can be set to.
I'm thinking I might leave it for others to offer suggestions, but if you get stuck you could set the scale up as an attribute and have a command to change, then you can do the conversion inside the command / method (the temperature settings could still be preferences, state variables or attributes). Not ideal and I only offer that up because I'm not sure what method is called when preferences are changed, if any.
That and the fact my internet decided to drop out mid-conversation....
You can use all the dynamic capabilities of Groovy when writing the preferences { ... } in your driver. The biggest catch is that, unlike dynamic pages in apps, drivers do not have similar functionality to allow things like submitOnChange: true (if you're familiar with that). So, the user has to save preferences after switching units before the other preferences will be able to correctly read this value and adjust accordingly.
It should also be noted that, for this particular use case, it is common for apps and drivers to respect the temperature scale set at the location level so users don't have to choose in the app/driver.
Thanks, your solution worked. The only minor problem now is when I try to set a default value based on the scale. When changing from Celsius to Fahrenheit (or vice-versa) the default value value is not taken into account and the interface show as if nothing was set requiring to update the value before saving when the save button is pressed. I guess I can live with that if there is no solution.