Hi all,
I’m presently trying to set up an automation that will fire under two conditions:
- The automation has not been run yet today
- The automation has not yet been run at all (i.e. when it is new, or resetting the HA database)
I am using the templating tool to set this up, however the issue I am facing is that when the automation has never been fired before (i.e. states.automation.test.attributes.last_triggered == null
) the template is returning the following message in big orange letters:
This template listens for all state changed events.
I think it is because attempting to use .strftime('%d')
on a null
value causes problems.
How would I adjust this code to work without raising this warning? I have tried wrapping it in it’s own if
block without the strftime
call in it, however adding the strftime
further in the template just raises the same warning.
This is the code I have thus far:
- alias: TEST
initial_state: 'on'
# specify a bunch of times for the check to be done (more than once gives redundancy in the case of server restart/power outage).
trigger:
- platform: time
at:
- "05:00:00" # Military time format
- "07:00:00" # Military time format
- "14:00:00" # Military time format
- "18:00:00" # Military time format
# only trigger the automation if it hasn't been triggered already today (or has never been triggered)
condition:
- condition: template
value_template: >-
{% set dayAutomation = states.automation.test.attributes.last_triggered.strftime('%d') %}
{% set dayToday = now().strftime('%d') %}
{% if dayToday != dayAutomation %}
true
{% else %}
false
{% endif %}
action:
- service: notify.mobile_app
data_template:
title: "TEST"
message: "THIS IS A TEST AUTOMATION"
Thank you in advance!