I have created two input_numbers to set a temperature and shwoing them on the frontend. How can I achive the following:
First input_number can only be decreased to the value of the second input_number + 2.
Second input_number can only be increased to the value of the first input_number - 2.
Long answer: you sort of can but there will be momentary excursions beyond the allowed ranges.
You can use automations to check the values as soon as they are changed and if outside the acceptable range, set the value to the nearest allowed. Doing it this way will give very short glitches outside the allowed ranges. If that’s acceptable, this is how you would do it:
I’ll assume your input numbers are integers. If they have fractions, replace all occurrences of |int with |float.
Maintaining a separation of 2 degrees between the two input_numbers is straightforward. However the range of an input_number has max/min limits. Therefore the algorithm has to take them into account otherwise it will calculate a value exceeding the range’s limits. This makes the required template a bit more complex.
What is the intended application of these two temperature-tracking input_numbers? The temperature in one room must always be 2 degrees different from another?
i’d just build a single slider that can be any temperature. Then the second slider would be 0, 1 or 2. Just need to use the template card to update the UI to display the value from the first slider added to the second.