There seems to be something very weird going on with the time templates in scripts and automations. I’ve tried 6 different variations… all the templates render properly in the Template editor, but at least one part always fails in scripts or automations.
I was able to get it working 2 ways…
by compacting it into a single variable:
alias: Query-Alexa-Door Last Opened
sequence:
- variables:
message: |
{% set dogtime = states('input_datetime.dog_time') %}
{% if now() > ( today_at( dogtime ) + timedelta(hours=2)) %}
It's been more than 2 hours since the dog was taken out.
{% else %}
The door was last opened at {{ dogtime }}
{% endif %}
- service: notify.alexa_media_quiet
data:
message: "{{ message }}"
data:
type: tts
mode: single
Or by getting rid of the variable:
alias: Query-Alexa-Door Last Opened
sequence:
- choose:
conditions:
- alias: If door not opened in more than 2 hours
condition: template
value_template: |
{{ now() > (today_at(states('input_datetime.dog_time'))
+ timedelta(hours=2)) }}
sequence:
- service: notify.alexa_media_quiet
data:
data:
type: tts
message: |
It's been more than 2 hours since the dog was taken out.
default:
- service: notify.alexa_media_quiet
data:
message: |
The door was last opened at {{ states('input_datetime.dog_time') }}
data:
type: tts
mode: single