Send a TTS greetings to whom opened the door after arriving home

Yes, that’s a use for the condition attribute.

That’s perfect. Now I’m wondering if I can have two conditions? The Quiet Time and the example from above, media player idle? Do I separate those with a comma?

You can do something like this:

{{ is_state('mediaplayer.mymedia','idle') and is_state('binary_sensor.quiet_time','off') }}
1 Like

Alright! thanks

Change the service google tts to this

- service: notify.alexa_media
  data:
    data:
      type: tts
    target:
      - !input 'target'
    message: "{%- set single_lst = single_msg.split('\\n') -%}\n{%- set multiple_lst\
      \ = multiple_msg.split('\\n') -%}\n{%- if persons_count|length > 1 -%}\n  {{\
      \ multiple_lst | random | replace('<persons>', persons_names) }}\n{%- elif persons_count|length\
      \ > 0 -%}\n  {{ single_lst | random | replace('<person>', persons_names) }}\n\
      {%- endif -%}\n"

How can i add a delay ?

Do you want to add a delay before the greetings?

Yes, but set a break time with Amazon Polly :+1:

Tried this but Alexa doesn’t talk. What could I be doing wrong?

Where do you paste the code?
Post image or code

Yes, I would like to know that too. How to add a delay before the greeting? TKS

Can you explain in more detail what “Minutes between person at home and door trigged” means? If I set the time to 10 min for example.

Is it also possible to add so that it is not activated between 19:00 and 08:00?

Got this error:

What to do?

Hey i saw this blueprint and wanted to test it.

I edited a little bit and added a delay and mine works with alexa.

Here is the code:

blueprint:
  name: TTS on door opening with persons at home with Alexa
  description: Sends TTS message to a media_player when door is oppened with the person
    at home
  domain: automation
  input:
    door_sensor:
      name: Door sensor
      selector:
        entity:
          domain: binary_sensor
          device_class: door
    persons:
      name: Persons
      selector:
        entity:
          domain: person
    minutes:
      name: Minutes
      description: Minutes between person at home and door trigged
      default: 5
      selector:
        number:
          min: 1.0
          max: 30.0
          step: 1.0
          unit_of_measurement: min
          mode: slider
    message-single:
      name: Message single person
      description: 'Message to salute single person. One possible message per line.
        Use <person> tag to be replaced by person name.

        '
      selector:
        text:
          multiline: true
    message-multiple:
      name: Message multiple persons
      description: 'Message multiple persons. One possible message per line. Use <persons>
        tag to be replaced by person name.

        '
      selector:
        text:
          multiline: true
    persons-concat:
      name: Text to concatenate the persons name
      description: String to be used as concatenate between names
      default: ' and '
      selector:
        text:
          multiline: false
    delay:
      name: delay of TTS
      description: Delay between door opening and TTS  
      default: 3
      selector:
        number:
          min: 0.0
          max: 30.0
          step: 1.0
          unit_of_measurement: sec
          mode: slider
    target:
      name: Target devices
      description: Target devices to play the TTS message
      selector:
        entity:
          domain: media_player
    condition:
      name: Condition to run
      description: Add a value_template value for major condition to execute the automation
      default: 'True'
      selector:
        text: {}
    actions:
      name: Additional actions
      description: After the execution of the automation, run those actions.
      default: []
      selector:
        action: {}
  source_url: https://gist.github.com/rokam/22fd6e497fbe61478fda4d0fc8215abf
variables:
  persons_str: !input 'persons'
  persons_list: '{{ persons_str.split('','') | map(''trim'') | list }}'
  timeout: !input 'minutes'
  concat_str: !input 'persons-concat'
  addactions: !input 'actions'
  persons_count: "{%- set first = true -%} {%- set data = namespace(nomes=[]) -%}\
    \ {%- for person in persons_list -%}\n  {%- if is_state(person, 'home') and (now()\
    \ - states[person].last_changed).total_seconds() < timeout*60 -%}\n    {%- set\
    \ data.nomes = data.nomes + [states[person].name] -%}\n  {%- endif -%}\n{%- endfor\
    \ -%} {{ data.nomes }}\n"
  persons_names: '{%- set finalstr = '', ''.join(persons_count) -%} {{ concat_str.join(finalstr.rsplit('',
    '',1)) }}

    '
  single_msg: !input 'message-single'
  multiple_msg: !input 'message-multiple'
trigger:
- platform: state
  entity_id: !input 'door_sensor'
  to: 'on'
action:
- condition: template
  value_template: !input 'condition'
- condition: template
  value_template: '{{ persons_count|length > 0 }}'
- delay: !input 'delay'  
- service: notify.alexa_media
  data_template:
    target: !input 'target'
    data:
      type: tts
    message: "{%- set single_lst = single_msg.split('\\n') -%}\n{%- set multiple_lst\
      \ = multiple_msg.split('\\n') -%}\n{%- if persons_count|length > 1 -%}\n  {{\
      \ multiple_lst | random | replace('<persons>', persons_names) }}\n{%- elif persons_count|length\
      \ > 0 -%}\n  {{ single_lst | random | replace('<person>', persons_names) }}\n\
      {%- endif -%}\n"  
- condition: template
  value_template: '{{ addactions|length > 0 }}'
- choose: []
  default: !input 'actions'
mode: single

1 Like

The timeout shoud end when the door Open, if you Open the door again say hello again.

wait_for_trigger ?? Can this be done?

Why is it splitting the lines this way?

 multiple_msg.split('\\n')

Can’t it be done with just the \n ? My list does not work properly, I have to add double line separations for this to work.

This looks really cool. One suggestion @rokam , would it be possible for the greeting to include a list of the people that were already home before?

"Welcome back <person>, <other_person_1> and <other_person_2> are currently at home."

2 Likes

Can you explain in more detail what “Minutes between person at home and door trigged” means?

That means that people that have the state changed in the last 10 minutes will be greeted.

Is it also possible to add so that it is not activated between 19:00 and 08:00?

Yes, you can use the condition_to_run. I do have an input_boolean that corresponds to my night_mode and I set it with another automation. I use the following condition value.

{{ is_state('input_boolean.night_mode','off') }}

danielo515, just use the multiline like this, one phrase per line:

Where is that? The GUI for the automation? I already tried that, but homeassistant doesn’t seem to like it and does nasty things when it saves the automation.