Logging MIN and MAX temperature without using recorder/history component?

Hi, I’m trying to log Min and Max temperature from a sensor and put that value to the input_text component with an automation.
I’ve got Max temperature working as expected but somehow it doesn’t work when negative numbers is involved.

This is how my automation looks like, any ideas how this can be solved? Or is there some other solution?

- alias: MIN temp
  trigger:
    - platform: state
      entity_id: sensor.norra_stranden_temperature
  condition:
     - condition: template
       value_template: '{{ states.input_text.text2.state > states.sensor.norra_stranden_temperature.state }}'  
  action:
    - service: input_text.set_value
      data_template:
        entity_id: input_text.text2
        value: '{{ states.sensor.norra_stranden_temperature.state }}'

compare the temperatures in kelvin for minimum temp. May even want to do it for max as well.

EDIT: example (if your units are ºC):

- alias: MIN temp
  trigger:
    - platform: state
      entity_id: sensor.norra_stranden_temperature
  condition:
     - condition: template
       value_template: >
        {% set T1 = states.input_text.text2.state + 273.15 %}
        {% set T2 = states.sensor.norra_stranden_temperature.state + 273.15 %}
        {{ T1 > T2 }}
  action:
    - service: input_text.set_value
      data_template:
        entity_id: input_text.text2
        value: '{{ states.sensor.norra_stranden_temperature.state }}'

EDIT 2: Kelvin is temperature based on the absolute lowest possible temperature. Temperature literally cannot go below 0 kelvin. So, you’ll never have to worry about negative numbers. Also, I don’t think it’s physically possible to get even close to 0 kelvin on earth (outside a lab).

Thanks for your answer, petro! I’ve tested it but can’t get it to run, and there’s no error messages in the logs.

is your input_text.text2.state an integer or float? Or is it a string?

May need to convert it using the float filter:

{% set T1 = states.input_text.text2.state | float + 273.15 %}

I tried it but it doesn’t trigger anyway. :face_with_raised_eyebrow:

well its only going to trigger when sensor.norra_stranden_temperature changes state and the condition is met. Type the value template lines into the template editor and see what it returns.

Wow, it actually works now, petro! I don’t know what the issue was but it could’ve been that my input.text had a max value of 100 by default. Anyway, thanks alot! :smiley:

I’m almost positive my bedroom goes below 0 degrees Kelvin in the winter when there is a North wind. :wink:

1 Like