I have the following trigger-based sensor defined in YAML. It uses two triggers, one is state-based the other template-based. This defines two sensors, one for daily high and one for daily low.
(I used details found in this post to create this sensor: Statistic sensor reset/clear at midnight for daily min & max temperature - #29 by droidgren)
The state-based trigger works as expected. I cannot get the template-based trigger to fire.
NOTE: the YAML in my configuration is slightly different from the example based on what I read in the current documents for the template integration.
YAML Configuration
template:
- trigger:
- trigger: template
value_template: "{{ now().hour == 0 }}"
- trigger: state
not_to:
- unknown
- unavailable
entity_id: sensor.outdoor_temp
action:
- variables:
source: "{{ states('sensor.outdoor_temp') | float }}"
now: "{{ now() }}"
sensor:
- name: "Outdoor Daily High Temperature"
unique_id: outdoor-daily-high
unit_of_measurement: "°F"
device_class: temperature
state_class: measurement
icon: mdi:arrow-up-circle-outline
state: |
{% set current = (this.state or trigger.to_state.state) | float(source) %}
{{ source if trigger.trigger == 'template' else [source, current] | max }}
attributes:
temperature_updated: |
{% set current = (this.state or trigger.to_state.state) | float(source) %}
{{ now if (trigger.trigger == 'template' or source > current) else this.attributes.temperature_updated | default(now) }}
sensor_last_reset: |
{{ now if trigger.trigger == 'template' else this.attributes.sensor_last_reset | default(now) }}
- name: "Outdoor Daily Low Temperature"
unique_id: outdoor-daily-low
unit_of_measurement: "°F"
device_class: temperature
state_class: measurement
icon: mdi:arrow-down-circle-outline
state: |
{% set current = (this.state or trigger.to_state.state) | float(source) %}
{{ source if trigger.trigger == 'template' else [source, current] | min }}
attributes:
temperature_updated: |
{% set current = (this.state or trigger.to_state.state) | float(source) %}
{{ now if (trigger.trigger == 'template' or source < current) else this.attributes.temperature_updated | default(now) }}
sensor_last_reset: |
{{ now if trigger.trigger == 'template' else this.attributes.sensor_last_reset | default(now) }}
I have tried changing the value_template:
several times today trying to catch an error message of some sort when the time passes and have seen nothing. I have even tried being more precise with the template adding both hour and minute definitions to the template.
According to the documents for the template trigger, the template simply needs to evaluate to true
to fire the trigger. I have tested my templates in the developer tools and when the time matches the template does evaluate to true.
Any suggestions on what I’m missing here?
Thanks in advance for your assistance!