All time min/max temp on a card for the whole year - how?

How do I create a card showing:

  • min/max temperatures from each of my sensors
  • on which day/time the above extremums were hit

with the condition that min/max is shown regardless of how much time the data is kept by the recorder?

For example - today is Nov 3rd, max temp in this year was on Jul 20th, min temp - Jan 14th. Recorder is configured to keep 2 weeks of data.

Thanks

1 Like

I use the following toi get daily and then weekly min and max temperatures.

I use the custom hass-variables integration as the storage medium for the data.

variable:
  lowest_temp_so_far:
    value: '100.0'
    restore: true
    attributes:
      icon: 'mdi:thermometer'
      unit_of_measurement: '°F'
      time: '00:00:00'
      friendly_name: 'Todays Lowest Temperature So Far'
  highest_temp_so_far:
    value: '0.0'
    restore: true
    attributes:
      icon: 'mdi:thermometer'
      unit_of_measurement: '°F'
      time: '00:00:00'
      friendly_name: 'Todays Highest Temperature So Far'
      
  lowest_temp_history:
    value: '55.0'
    restore: true
    attributes:
      icon: 'mdi:thermometer'
      unit_of_measurement: '°F'
      date: '1971-01-01'
      friendly_name: 'Actual Lowest Temperature History'
  highest_temp_history:
    value: '85.0'
    restore: true
    attributes:
      icon: 'mdi:thermometer'
      unit_of_measurement: '°F'
      date: '1971-01-01'
      friendly_name: 'Actual Highest Temperature History'

automation:
  - alias: Env Set Lowest Temp So Far
    trigger:
      - platform: state
        entity_id: sensor.dark_sky_temperature
      - platform: time
        at: '00:00:00'
    action:
      - choose:
          - conditions:
              condition: template
              value_template: "{{ trigger.platform == 'time' }}"
            sequence:
              service: variable.set_variable
              data:
                variable: lowest_temp_so_far
                value: "{{ states('sensor.dark_sky_temperature') | float }}"
                attributes:
                  time: "{{ states('sensor.time') }}"
        default:
          service: variable.set_variable
          data:
            variable: lowest_temp_so_far
            value: >
              {% if states('sensor.dark_sky_temperature') not in ['unavailable', 'unknown'] and (states('sensor.dark_sky_temperature') | float < states('variable.lowest_temp_so_far') | float) %}
                {{ states('sensor.dark_sky_temperature') | float }}
              {% else %}
                {{ states('variable.lowest_temp_so_far') }}
              {% endif %}
            attributes:
              time: >
                {% if states('sensor.dark_sky_temperature') not in ['unavailable', 'unknown'] and (states('sensor.dark_sky_temperature') | float < states('variable.lowest_temp_so_far') | float) %}
                  {{ states('sensor.time') }}
                {% else %}
                  {{ state_attr('variable.lowest_temp_so_far', 'time') }}
                {% endif %}
                                
  - alias: Env Set Highest Temp So Far
    trigger:
      - platform: state
        entity_id: sensor.dark_sky_temperature
      - platform: time
        at: '00:00:00'
    action:
      - choose:
          - conditions:
              condition: template
              value_template: "{{ trigger.platform == 'time' }}"
            sequence:
              service: variable.set_variable
              data:
                variable: highest_temp_so_far
                value: "{{ states('sensor.dark_sky_temperature') | float }}"
                attributes:
                  time: "{{ states('sensor.time') }}"
        default:
          service: variable.set_variable
          data:
            variable: highest_temp_so_far
            value: >
              {% if states('sensor.dark_sky_temperature') not in ['unavailable', 'unknown'] and (states('sensor.dark_sky_temperature') | float > states('variable.highest_temp_so_far') | float) %}
                {{ states('sensor.dark_sky_temperature') | float }}
              {% else %}
                {{ states('variable.highest_temp_so_far') }}
              {% endif %}
            attributes:
              time: >
                {% if states('sensor.dark_sky_temperature') not in ['unavailable', 'unknown'] and (states('sensor.dark_sky_temperature') | float > states('variable.highest_temp_so_far') | float) %}
                  {{ states('sensor.time') }}
                {% else %}
                  {{ state_attr('variable.highest_temp_so_far', 'time') }}
                {% endif %}
                
  - alias: Env Set Actual Daily Lowest Temp
    trigger:
      - platform: time
        at: '23:59:00'
    action:
      - service: variable.set_variable
        data:
          variable: lowest_temp_history
          value: "{{ states('variable.lowest_temp_so_far') }}"
          attributes:
            date: "{{ states('sensor.date') }}"
                              
  - alias: Env Set Actual Daily Highest Temp
    trigger:
      - platform: time
        at: '23:59:00'
    action:
      - service: variable.set_variable
        data:
          variable: highest_temp_history
          value: "{{ states('variable.highest_temp_so_far') }}"
          attributes:
            date: "{{ states('sensor.date') }}"

Basically what it does is register the highest an lowest temp for each day (resetting at midnight) and then each day transfers that data to another variable that gives me a history of highs and lows for the past week (or longer if you want).

Since you don’t want it to reset every day (which it sounds like you don’t) you can reset it on january 1st at midnight.

then you can simplify that even more by just setting the highest/lowest temp to the current value if that value is higher/lower than the previous value.

if you need help rejiggering it for your use then I can help.

But hopefully you can use what I did as a guide and get it working.

as far as the card that’s the easy part. Once you store the data then just use the entity in a card like any other entity.

If this helps, I use next code to obtain min and max temperatures and date of the records.

Features:

  • min/max records over time.
  • max step allowed in sensor to avoid false measurements.
  • reset records to start over at any time.
  • last update and last valid value as attributes of the sensors.

Yaml code is this (you can copy and paste in a yaml file in your config/packages folder):

input_number:
  max_temp_step:
    name: Max temp step
    min: 0
    max: 20
    initial: 5

input_boolean:
  reset_max_min:
    name: Reset max min
    initial: False
    icon: mdi:alert

automation:
  - id: toggle_reset_min_max
    alias: "Toggle reset_min_max"
    description: "When input_boolean.reset_max_min is set to on, automatically set it to off after 2 seconds"
    trigger:
      - platform: state
        entity_id: input_boolean.reset_max_min
        from: "off"
        to: "on"
    condition: []
    action:
      - delay: '00:00:01'
      - service: input_boolean.turn_off
        target:
          entity_id: input_boolean.reset_max_min
    mode: single

template:
  - trigger:
    - platform: state
      entity_id: sensor.whatever_temp
    - platform: state
      entity_id: input_number.max_temp_step
    - platform: state
      entity_id: input_boolean.reset_max_min
      from: "off"
      to: "on"
      id: reset
    sensor:
      - name: "Max temp"
        state: >-
          {% if trigger.id == 'reset' %}
            {{ states('sensor.pws_vallad_temp') }}
          {% elif ((state_attr('sensor.max_temp','last_valid_sensor_value')|float(states('sensor.whatever_temp'))|float 
            - states('sensor.whatever_temp')|float(-10))|abs < states('input_number.max_temp_step')|float) 
            and (states('sensor.whatever_temp')|float > states('sensor.max_temp')|float(-10)) %}
            {{ states('sensor.whatever_temp') }}
          {% else %}
            {{ states('sensor.max_temp') }}
          {% endif %}
        unit_of_measurement: "ºC"
        icon: mdi:thermometer-chevron-up
        attributes:
          last_update: >-
            {% if trigger.id == 'reset' %}
              {{ now() }}
            {% elif ((state_attr('sensor.max_temp','last_valid_sensor_value')|float(states('sensor.whatever_temp'))|float 
              - states('sensor.whatever_temp')|float(-10))|abs < states('input_number.max_temp_step')|float)
              and (states('sensor.whatever_temp')|float > states('sensor.max_temp')|float(-10)) %}
              {{ now() }}
            {% else %}
              {{ state_attr('sensor.max_temp','last_update') }}
            {% endif %}
          last_valid_sensor_value: >-
            {% if trigger.id == 'reset' %}
              {{ states('sensor.whatever_temp') }}
            {% elif ((state_attr('sensor.max_temp','last_valid_sensor_value')|float(states('sensor.whatever_temp'))|float 
              - states('sensor.whatever_temp')|float(-10))|abs < states('input_number.max_temp_step')|float) %}
              {{ states('sensor.whatever_temp') }}
            {% else %}
              {{ state_attr('sensor.max_temp','last_valid_sensor_value') }}
            {% endif %}
  - trigger:
    - platform: state
      entity_id: sensor.whatever_temp
    - platform: state
      entity_id: input_number.max_temp_step
    - platform: state
      entity_id: input_boolean.reset_max_min
      from: "off"
      to: "on"
      id: reset
    sensor:
      - name: "Min temp"
        state: >-
          {% if trigger.id == 'reset' %}
            {{ states('sensor.pws_vallad_temp') }}
          {% elif ((state_attr('sensor.sensor.min_temp','last_valid_sensor_value')|float(states('sensor.whatever_temp'))|float 
            - states('sensor.whatever_temp')|float(45))|abs < states('input_number.max_temp_step')|float) 
            and (states('sensor.whatever_temp')|float < states('sensor.sensor.min_temp')|float(45)) %}
            {{ states('sensor.whatever_temp') }}
          {% else %}
            {{ states('sensor.sensor.min_temp') }}
          {% endif %}
        unit_of_measurement: "ºC"
        icon: mdi:thermometer-chevron-down
        attributes:
          last_update: >-
            {% if trigger.id == 'reset' %}
              {{ now() }}
            {% elif ((state_attr('sensor.sensor.min_temp','last_valid_sensor_value')|float(states('sensor.whatever_temp'))|float 
              - states('sensor.whatever_temp')|float(45))|abs < states('input_number.max_temp_step')|float)
              and (states('sensor.whatever_temp')|float < states('sensor.sensor.min_temp')|float(45)) %}
              {{ now() }}
            {% else %}
              {{ state_attr('sensor.sensor.min_temp','last_update') }}
            {% endif %}
          last_valid_sensor_value: >-
            {% if trigger.id == 'reset' %}
              {{ states('sensor.whatever_temp') }}
            {% elif ((state_attr('sensor.sensor.min_temp','last_valid_sensor_value')|float(states('sensor.whatever_temp'))|float 
              - states('sensor.whatever_temp')|float(45))|abs < states('input_number.max_temp_step')|float) %}
              {{ states('sensor.whatever_temp') }}
            {% else %}
              {{ state_attr('sensor.sensor.min_temp','last_valid_sensor_value') }}
            {% endif %}