Get maximum value between two sensor values

Hi I’m currently coding an automation which sets the target temperature of an ac.

If the temperature is too cold I set the setpoint ac temperature to rise by one degree, but I don’t want this set point temperature to rise indefinitely. Let say that I want it to be at maximum Equal to t_max, like below:

T_new=max(T_old+1;T_max)

How do I code this into a script?

Currently I can increase the sepoint temperature by one degree :

heat_up:

alias: heat_up
sequence:

  • data_template:
    entity_id: climate.ac_corridoio
    temperature: “{{ state_attr(‘climate.ac_corridoio’ , ‘temperature’)|int + 1 }}”
    service: climate.set_temperature

You may be able to get what you want with this sensor without you needing math. Then you just make an automation that increase the temperature whenever it turns on.

Hi, thanks for the reply.
Although I don’t understand the link between my problem and the Baye algebra, can you explain yourself?
My need actually is just to perform the maximum value between two sensor values.
I saw that is possible to perform “if” statement, but since i am new ho ha I don’t know very well the sintax

I miss understood your question.

If you need to compare…

{% set t = state_attr('climate.ac_corridoio' , 'temperature')|int %}
{{ t + 1 if t + 1 <= max else t }}

But what you should really do is just add a condition to check the current temperature against the max before firing the sequence. Then you wouldn’t need to update the sequence/script.

you are absolutely right,
it’s super simpler to just add another condition!

thanks

1 Like

Another possible approach to this is

{{ [ t+1 , t_max ] | min }}

This will take the smaller value between t+1 and t_max

1 Like