Automation: Trying to limit input_number min/max

I have these 2 input_numbers

I am trying to make sure the MIN can not be set above the MAX.

With the automation below, it works … the MIN value is set to 20

alias: Range Limit Automation - min
description: ""
triggers:
  - trigger: numeric_state
    entity_id: input_number.lht52_a840414e4f5cae3d_alarm_temp_min
    above: input_number.lht52_a840414e4f5cae3d_alarm_temp_max
actions:
  - action: input_number.set_value
    target:
      entity_id: input_number.lht52_a840414e4f5cae3d_alarm_temp_min
    data:
      value: 20
mode: restart

So far - so good.

But I want to set MIN to the current value of MAX

I tried the automation below

alias: Range Limit Automation - min
description: ""
triggers:
  - trigger: numeric_state
    entity_id: input_number.lht52_a840414e4f5cae3d_alarm_temp_min
    above: input_number.lht52_a840414e4f5cae3d_alarm_temp_max
actions:
  - action: input_number.set_value
    target:
      entity_id: input_number.lht52_a840414e4f5cae3d_alarm_temp_min
    data_template:
      value: "{{ input_number.lht52_a840414e4f5cae3d_alarm_temp_max.state | float }}"
mode: restart

But get this error: ... Error rendering data template: UndefinedError: 'input_number' is undefined

What am I doing wrong?

You perhaps could try a dual thermostat?
GitHub - swingerman/ha-dual-smart-thermostat: The dual_smart_thermostat is an enhaced verion of generic thermostat implemented in Home Assistant. It uses several sensors and dedicated switches connected to a heater and air conditioning under the hood.

For data template, use this

{{ states(“input_number.name_goes_here”) }}

Bingo! That is the fix I needed.

Now - I just need to have it work ‘continuously’

When I first move the MIN slider above the MAX, it gets limited.

But not the next time

Trigger off any change to the sliders, and add a condition block to check if MIN is above MAX.

The set_value action should use value instead of the legacy data_template (docs).

Still having problems

alias: New automation
description: ""
triggers:
  - trigger: numeric_state
    entity_id:
      - input_number.lht52_alarm_temp_min
    above: input_number.lht52_alarm_temp_max
conditions: []
actions:
  - action: number.set_value
    metadata: {}
    data:
      value: "{{ states('input_number.lht52_alarm_temp_max') | int - 1}}"
    target:
      entity_id: input_number.lht52_alarm_temp_min
mode: restart

To me this says

If 
 MIN > MAX
then
 MIN = (MAX -1 )

But it is not working that way. I can see the automation is being triggered, and no errors reported. But the MIN value ends up saying above MAX.

:frowning:

You’ve changed it from input_number.set_value to number.set_value. Why did you do that? That action won’t update an Input Number, which is a different type of entity to a Number.

See my post above for advice on getting around the issue that a numeric state trigger only fires when the threshold is crossed, and it also doesn’t fire if the comparator entity changes.

Untested and typed on a phone:

alias: New automation
description: ""
triggers:
  - trigger: state
    entity_id:
      - input_number.lht52_alarm_temp_min
      - input_number.lht52_alarm_temp_max
conditions:
  - condition: numeric_state
    entity_id: input_number.lht52_alarm_temp_min
    above: input_number.lht52_alarm_temp_max
actions:
  - action: input_number.set_value
    data:
      value: "{{ states('input_number.lht52_alarm_temp_max') | int - 1 }}"
    target:
      entity_id: input_number.lht52_alarm_temp_min

Thanks that helped … but it still only ‘works once’. I can see the automation triggering every time I move the MAX slider … but it only performs that action once per crossing the MIN threshold.
TEST 1 = Good
Min=10
Max=20
Move Max to 0
=> Max gets set to 11

TEST 2 = BAD
Continue from Test 1
Min=10
Max=11
Move Max to 0
Automation triggers
But - Max stays at 0

My understanding of the automation below is:

every time MAX changes AND MAX < MIN
then MAX = MIN + 1
alias: Limit Temp Max
description: Limit Temp Max
triggers:
  - trigger: state
    entity_id:
      - input_number.lht52_alarm_temp_max
conditions:
  - condition: numeric_state
    entity_id: input_number.lht52_alarm_temp_max
    below: input_number.lht52_alarm_temp_min
actions:
  - action: input_number.set_value
    metadata: {}
    data:
      value: "{{ states('input_number.lht52_alarm_temp_min') | int + 1}}"
    target:
      entity_id: input_number.lht52_alarm_temp_max
mode: restart

:frowning:

Download the trace file for test 2 and paste it here.

What are the configured minimum and maximum values for your input numbers?

Also try with mode: single.

I gave up.

Moved to Plan B. Simple. Works