If you want to use a Template Sensor as the source for a Time Trigger, its device_class
must be timestamp
and its state
value should be a datetime object or a timestamp in ISO 8601 format.
sensor:
- platform: template
sensors:
next_fire:
friendly_name: "Today’s time to fire"
device_class: timestamp
value_template: >
{% if is_state('binary_sensor.holiday_sensor', 'on') %}
{% set entity = 'input_datetime.fire_time_holiday' %}
{% elif now().weekday() in [5, 6] %}
{% set entity = 'input_datetime.fire_time_weekend' %}
{% else %}
{% set entity = 'input_datetime.fire_time_weekdays' %}
{% endif %}
{{ today_at(states(entity)).isoformat() }}
The following version of the template reduces some of the redundancy present in the previous version.
sensor:
- platform: template
sensors:
next_fire:
friendly_name: "Today’s time to fire"
device_class: timestamp
value_template: >
{% if is_state('binary_sensor.holiday_sensor', 'on') %}
{% set entity = 'holiday' %}
{% elif now().weekday() in [5, 6] %}
{% set entity = 'weekend' %}
{% else %}
{% set entity = 'weekdays' %}
{% endif %}
{{ today_at(states('input_datetime.fire_time_' ~ entity)).isoformat() }}
EDIT
If this Template Sensor will be used by just one automation then you may as well just create a Template Trigger and eliminate the Template Sensor.
alias: example
trigger:
- platform: template
value_template: >
{% set entity = 'holiday' if is_state('binary_sensor.holiday_sensor', 'on')
else 'weekend' if now().weekday() in [5, 6]
else 'weekdays' %}
{{ now().strftime('%H:%M:00') == states('input_datetime.fire_time_' ~ entity) }}
condition: []
action:
... your actions ...