Skip to content

Instantly share code, notes, and snippets.

@Didgeridrew
Last active August 2, 2023 17:36
Show Gist options
  • Select an option

  • Save Didgeridrew/6627b5f88f5ed8f9a380fb245d5fe67a to your computer and use it in GitHub Desktop.

Select an option

Save Didgeridrew/6627b5f88f5ed8f9a380fb245d5fe67a to your computer and use it in GitHub Desktop.
HA - Max Temp trigger-based template sensor
# Option 1:
template:
- trigger:
- platform: state
entity_id: sensor.temp
not_to:
- unavailable
- unknown
- platform: time
at: "00:00:00"
sensor:
- name: Temperature Daily Max
unit_of_measurement: "°F"
state: >
{% set current = this.state | float(0) %}
{% set source = states('sensor.temp') | float(0) %}
{% if trigger.platform == 'time' %}
{{ source }}
{% else %}
{{ [source, current] | max }}
{% endif %}
# Option 2: possibly less accurate, but fewer triggers
template:
- trigger:
- platform: time_pattern
minutes: "/5"
sensor:
- name: Temperature Daily 5m Max
unit_of_measurement: "°F"
state: >
{% set current = this.state | float(0) %}
{% set source = states('sensor.temp') | float(0) %}
{% if ((now().hour == 0) and (now().minute < 5)) %}
{{ source }}
{% else %}
{{ [source, current] | max }}
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment