Two input_numbers in relation to each other

Hi,

I have a question to input_numbers.

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.

Best Regards,
Johannes

Short answer: you cant.

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.

trigger:
  platform: state
  entity_id: input_number.first
condition:
  condition: template
  value_template: "{{ states('input_number.first')|int > ( states('input_number.second')|int + 2 ) }}"
action:
  service: input_number.set_value
  data_template:
    entity_id: input_number.first
    value: "{{ states('input_number.second')|int + 2 }}"
trigger:
  platform: state
  entity_id: input_number.second
condition:
  condition: template
  value_template: "{{ states('input_number.second')|int < ( states('input_number.first')|int - 2 ) }}"
action:
  service: input_number.set_value
  data_template:
    entity_id: input_number.second
    value: "{{ states('input_number.first')|int - 2 }}"

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?

But that’s not what he’s after. e.g. the value of the first can be any value up to 2 below the other. Not just always 2 below the other.

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.

1 Like

This is really a good idea, sometimes the solution could be so easy… :slight_smile:

You’re right, I misspoke. I should’ve said ‘Maintaining a minimum separation of 2 degrees …’

… still would like to know what the intended application is for this ‘offset temperature’ system.