Resetting a template sensor annually

A few years ago this community helped me refine the following template to capture the daily outdoor high and low temperatures:

Working daily hi/low template
template:
  - trigger:
    - platform: time
      at: '00:00:00'
    - platform: state
      entity_id: sensor.outdoor_temp
    sensor:
      - name: "Outdoor Daily High Temperature"
        unit_of_measurement: '°F'
        device_class: temperature
        state: >
          {% set t_high = states('sensor.outdoor_temp') | float(-99) %}
          {{ [t_high, this.state | float(-99)] | max if trigger.platform != 'time' else t_high }}
        attributes:
          temperature_updated: "{{ now() | as_local }}"
        icon: mdi:arrow-up-circle-outline

      - name: "Outdoor Daily Low Temperature"
        unit_of_measurement: '°F'
        device_class: temperature
        state: >
          {% set t_low = states('sensor.outdoor_temp') | float(120) %}
          {{ [t_low, this.state | float(120)] | min if trigger.platform != 'time' else t_low }}
        attributes:
          temperature_updated: "{{ now() | as_local }}"
        icon: mdi:arrow-down-circle-outline

I’m trying to modify this format to reset annually (Jan 1st at midnight). I have been looking at the documentation for templates, automatons, and triggers for the last couple days. I’m not seeing an obvious solution to this.

I have tried:

- trigger:
  - platform: time
    at:
      month: 01
      day: 01
      hour: 00
      day: 00

This results in the error message Expected HH:MM, HH:MM:SS, an Entity ID with domain 'input_datetime' or 'sensor', a combination of a timestamp sensor entity and an offset, or Limited Template

After further reviewing the documentation, that does make sense. This format does not match any of those expected formats.

The only method I can come up with to accomplish this is to use a local calendar event set to reoccur on Jan 1st of every year and use that event to trigger the reset. I have not tried to set this up yet.

I appreciate any suggestions

Trigger on hour 0.
Condition template:

{{ now().timestamp() | timestamp_custom("%m%d") =="0101" }}

That looks like it would give me the timestamp format expected. This would be used after the at: keyword?

at: {{ now().timestamp() | timestamp_custom("%m%d") =="0101" }}

The two sensors already “reset” at the start (00:00) of every day of the year.

What do you want them to do differently at the start of January 1st?

This would be a new set of sensors that will reset Jan 1st instead of daily.

If you want to record the highest/lowest yearly temperatures, use the Utility Meter integration (if you want, you can also use it to record weekly and monthly highs/lows).

Refer to the examples in this post

For your application:

Summary
utility_meter:
  outdoor_yearly_high_temp:
    source: sensor.outdoor_daily_high_temperature
    name: Outdoor Yearly High Temperature
    cycle: yearly
  outdoor_yearly_low_temp:
    source: sensor.outdoor_daily_low_temperature
    name: Outdoor Yearly Low Temperature
    cycle: yearly

I had looked at the Utility Meter integration but didn’t quite understand how to apply it. Those examples add a lot more clarity.

Also, thank you for the custom recommendation!

The documentation for the cycle variable doesn’t have much detail on the Utility Meter page.
image

Is it a safe assumption that the yearly cycle will reset on the calendar year?

Yes.

I have been using the Utility Meter integration for about 3 years and “yearly” corresponds to a calendar year.

Something is not working correctly here.


Our lowest temperature over the last three days has been 15.4 and the high temperature has only been 71.3. I’ve been over the docs for the Utility Meter several times and I can’t see what I’m missing.

I’m looking at other posts in the community for this topic now.

@123 , do you have any thoughts?

YAML:

utility_meter:
  outdoor_annual_high_temp:
    source: sensor.outdoor_daily_high_temperature
    name: Outdoor Annual High Temperature
    unique_id: dfa7cb51
    cycle: yearly

  outdoor_annual_low_temp:
    source: sensor.outdoor_daily_low_temperature
    name: Outdoor Annual Low Temperature
    unique_id: fb02547c
    cycle: yearly

Check the History graph for sensor.outdoor_daily_high_temperature. Set the graph’s scale to “This year” and check the highest recorded value.

Repeat the process for sensor.outdoor_daily_low_temperature’s lowest temperature.

Post screenshots of the two graphs.

Here are the two graphs. Blue lines are the annual sensor, orange lines are the daily sensor.

My apologies; looks like my suggestion was wrong. :man_facepalming: It’s reporting a running sum of the temperature values (which is not what you want).

I suggest you consider doing what this person did:

The user provides several examples for resetting at various time intervals (except for yearly). Here’s my suggestion for resetting on January 1st at 00:00.

value_template: "{{ now().month == 1 and now().day == 1 and now().hour == 0 and now().minute == 0 }}"

That’s the same conclusion I came to on the Utility Meter. It was worth the experiment to learn about the sensor though.

Thank you for taking the time to reply.