Trying to evaluate and store a value from a temperature sensor using an Autoamation

Hi,

I am trying to record min and max values for my temperature sensor across all time, rather than increase the data storage period I think the best way to do this is to create an input_value that an automation checks the current temp against and then replaces the value of if it exceeds it in the appropriate direction. (Open to alternative methods though if this is too cumbersome, I am relatively new to HASS though!)

Here is the code I am trying to use;

alias: Garden Min Temp
description: ''
mode: single
trigger:
  - type: temperature
    platform: device
    device_id: xxxXXXxxx
    entity_id: sensor.netatmo_3wp_indoor_garden_temperature
    domain: sensor
condition:
  - condition: template
    value_template: >-
      value_template: '{{
      (states('sensor.netatmo_3wp_indoor_garden_temperature') | float >
      states('input_number.garden_min_temp') | float) }}'
action:
  - service: input_number.set_value
    data_template:
      entity_id: input_number.garden_min_temp
      value: '{{ states('sensor.netatmo_3wp_indoor_garden_temperature') }}'

However it is throwing up an error about ‘Message malformed: Integration ‘’ not found’ and before that it had another error code that I didn’t capture. Can anyone eyeball the code above and let me know if I’m making an obvious error please? Cheers…

should be:

    value_template: >-
      {{ (states('sensor.netatmo_3wp_indoor_garden_temperature') | float > states('input_number.garden_min_temp') | float) }}

You can make the automation to be triggered based on numeric_state by referencing other entity. This automation will only be triggered when (1) sensor.netatmo_3wp_indoor_garden_temperature is lower than input_number.garden_min_temp OR (2) sensor.netatmo_3wp_indoor_garden_temperature is higher than input_number.garden_max_temp

trigger:
  - platform: numeric_state
    entity_id: sensor.netatmo_3wp_indoor_garden_temperature
    below: input_number.garden_min_temp
    id: Min
  - platform: numeric_state
    entity_id: sensor.netatmo_3wp_indoor_garden_temperature
    above: input_number.garden_max_temp
    id: Max
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: Min
        sequence:
          - service: input_number.set_value
            target:
              entity_id: input_number.garden_min_temp
            data:
              value: >-
                {{ states('sensor.netatmo_3wp_indoor_garden_temperature') }}
    default:
      - service: input_number.set_value
        target:
          entity_id: input_number.garden_max_temp
        data:
          value: >-
            {{ states('sensor.netatmo_3wp_indoor_garden_temperature') }}

Edit: combining min/max into 1 automation just like Taras’ beautiful solution.

This automation records both min and max values.

alias: Garden Min Max Temp
description: 'Record lowest and highest reported garden temperature'
mode: single
trigger:
  - platform: state
    entity_id: sensor.netatmo_3wp_indoor_garden_temperature
condition: "{{ trigger.to_state.state | float < states('input_number.garden_min_temp') | float or trigger.to_state.state | float > states('input_number.garden_max_temp') | float }}"
action:
  - service: input_number.set_value
    target:
      entity_id: "input_number.garden_{{ 'min' if trigger.to_state.state | float < states('input_number.garden_min_temp') | float else 'max' }}_temp"
    data:
      value: "{{ trigger.to_state.state | float }}"