Skip to content

Instantly share code, notes, and snippets.

@JannickBlmndl
Last active May 3, 2021 23:49
Show Gist options
  • Save JannickBlmndl/90563d47a3f8a2823e76a99aeefa7820 to your computer and use it in GitHub Desktop.
Save JannickBlmndl/90563d47a3f8a2823e76a99aeefa7820 to your computer and use it in GitHub Desktop.
Smart home solver template_conditions
# Front doorbell motion template condition
# Template condition which only passes if it has been more than 1 minute (60 seconds) that the automation.front_doorbell_motion ran.
- condition: template
value_template: >
{% if state_attr('automation.front_doorbell_motion', 'last_triggered') %}
{{ as_timestamp(now()) | int -
as_timestamp(state_attr('automation.front_doorbell_motion', 'last_triggered')) | int > 60 }}
{% else %}
false
{% endif %}
# Smart Shades template condition
# Template condition which only passes if the automation has been triggerd last more than 12 hours ago (43200 seconds).
- condition: template
value_template: >
{% if state_attr('automation.office_shades_up', 'last_triggered') %}
{{ as_timestamp(now()) | int -
as_timestamp(state_attr('automation.office_shades_up', 'last_triggered')) | int > 43200 }}
{% else %}
false
{% endif %}
@JannickBlmndl
Copy link
Author

For more information on templating: https://www.home-assistant.io/docs/configuration/templating
More information on the state string specifically. https://www.home-assistant.io/docs/configuration/templating/#states

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment