Hey there.
I got this automation that I need to run only once per person.
The automation checks if someone arrives (“anlände”) and the state of this is set to 10minutes and then via sonos welcomes the person home.
I got two persons in the automation so I want it to run if someone else arrives.
Using Phils presence detection: https://philhawthorne.com/making-home-assistants-presence-detection-not-so-binary/
Plz help.
automation:
- alias: 'Välkommen Hem'
trigger:
platform: state
entity_id: sensor.ytterdorr_status
to: 'Öppen'
condition:
condition: and
conditions:
- condition: time
after: '09:00:00'
before: '18:00:00'
- condition: or
conditions:
- condition: state
entity_id: sensor.niclas_status
state: 'Anlände'
- condition: state
entity_id: sensor.sara_status
state: 'Anlände'
action:
- service: script.welcome_home
data_template:
speech_message: >
{% if is_state('sensor.niclas_status', 'Anlände') and is_state('sensor.sara_status', 'Anlände') %}
{{ [
"Välkommen hem Sara och Niclas" ,
"Kungen och Drottningen är hemma"
] | random }}
{% elif is_state('sensor.niclas_status', 'Anlände') %}
{{ [
"Välkommen hem Niclas" ,
"Kungen Niclas är hemma"
] | random }}
{% else %}
{{ [
"Välkommen hem Sara" ,
"Drottningen är hemma. Välkommen hem Sara" ,
"Husets sötnos Sara är hemma"
] | random }}
{% endif %}
script:
welcome_home:
alias: "Välkomst meddelande"
sequence:
- service_template: script.sonos_{{'playing' if states.media_player.kok.state == 'playing' else 'notplaying'}}
data_template:
sonos_entity: media_player.kok
volume: 0.45
message: "{{ speech_message }}"
sonos_playing:
alias: "Sonos Playing"
sequence:
- service: sonos.snapshot
data_template:
entity_id: "{{ sonos_entity }}"
- service: sonos.unjoin
data_template:
entity_id: "{{ sonos_entity }}"
- service: media_player.volume_set
data_template:
entity_id: "{{ sonos_entity }}"
volume_level: "{{ volume }}"
- delay: '00:00:05'
- service: tts.google_translate_say
data_template:
entity_id: "{{ sonos_entity }}"
message: "{{ message }}"
- delay: '00:00:03'
- service: sonos.restore
data_template:
entity_id: "{{ sonos_entity }}"
sonos_notplaying:
alias: "Sonos Not PLaying"
sequence:
- service: media_player.volume_set
data_template:
entity_id: "{{ sonos_entity }}"
volume_level: "{{ volume }}"
- delay: '00:00:05'
- service: tts.google_translate_say
data_template:
entity_id: "{{ sonos_entity }}"
message: "{{ message }}"
- delay: '00:00:03'
- service: media_player.volume_set
data_template:
entity_id: media_player.kok
volume_level: 0.25
- service: media_player.select_source
data_template:
entity_id: media_player.kok
source: >
{% if is_state('sensor.niclas_status', 'Anlände') and is_state('sensor.sara_status', 'Anlände') %}
STAR FM 96.3 (60-tal)
{% elif is_state('sensor.niclas_status', 'Anlände') %}
Raubtier
{% elif is_state('sensor.sara_status', 'Anlände') %}
NRJ Sverige 105.1 (Populärmusik)
{% else %}
{% endif %}