Hi everyone, I’d like to create an automation that plays a greeting when my wife or I come home using Alexa. The idea was to use the door sensor and the presence sensor. I also added a control that prevents the greeting if I enter and leave in less than an hour. But I’m having trouble starting the automation.
alias: welcome
description: Alexa Welcome
triggers:
- entity_id:
- binary_sensor.aqara_door_1_contact
to: "on"
trigger: state
from: "off"
conditions:
- condition: template
value_template: "{{ not too_soon}}"
- condition: template
value_template: >
{{ p1_home or p2_home }}
actions:
- target:
entity_id: notify.echo_dot_di_p1_annuncio
data:
volume_level: 0.6
action: media_player.volume_set
- target:
entity_id: notify.echo_dot_di_p1_annuncio
data:
message: "{{ messaggio }}"
action: media_player.play_media
- target:
entity_id: input_datetime.last_bentornato
data:
timestamp: "{{ now_ts }}"
action: input_datetime.set_datetime
variables:
last_marco: "{{ state_attr('automation.bentornato_a_casa', 'last_triggered') }}"
now_ts: "{{ as_timestamp(now()) }}"
p1_home: "{{ is_state('person.p1', 'home') }}"
p2_home: "{{ is_state('person.p2', 'home') }}"
too_soon: >
{% set last = state_attr('input_datetime.last_bentornato', 'timestamp') |
default(0) %} {{ (now_ts - last) < 3600 }}
messaggio: |
{% if p1_home and p2_home %}
Bentornati ragazzi!
{% elif rp1_home %}
Bentornato Marco!
{% elif p2_home %}
Bentornata Paola!
{% else %}
Bentornato a casa!
{% endif %}
mode: single