Changing input_number value as a result of other input_number change

i am using the following:

  input_number:
    ac1_auto_min:
      name: 'AC1 Min'
      min: 10
      max: 30
      step: 0.1
    ac1_auto_max:
      name: 'AC1 Max'
      min: 10
      max: 30
      step: 0.1

i want that the difference between the two will be a minimum of 2 and that if the max is always higher than the min
so for example if min = 20 and max=25 and i change max to 20, min will be automatically changed to 18.

trying this doesn’t change as expected:

  -  id: ac1_max_changed
     trigger:
       platform: state
       entity_id: input_number.ac1_auto_max
     condition:
       condition: template
       value_template: "{{ (float(trigger.payload) - 2) < float(states('input_number.ac1_auto_min')) }}"
     action:
     - service: input_number.set_value
       data_template:
         entity_id: input_number.ac1_auto_min
         value : {"entity_id": "input_number.ac1_auto_min","value": {{ float(trigger.payload) - 2 }}}

it is valid, but not sure what is wrong - what am i missing?

Try this condition template

value_template: "{{ (trigger.to_state.state | float - 2) < states('input_number.ac1_auto_min') | float }}"

And this action:

     - service: input_number.set_value
       data_template:
         entity_id: input_number.ac1_auto_min
         value: "{{ trigger.to_state.state | float - 2 }}"
1 Like

Works great - thx.
i didn’t know about this “to_state” method being an option - is there an API reference for trigger/etc. somewhere i can use?

Yep:

1 Like

Thanks! :slight_smile:

No problem, there’s also the general templating doc:

if I leave out the initial: value when defining input_number, will the last stored numbers be restored after HA restarts?

Yes it will.