Alexa to announce person coming home

I have this code that will greet the person coming home. I would like to have alexa announce the person’s name.

## Welcome Home Greeting
- alias: welcome home alexa greeting
  trigger:
     - platform: state
       entity_id: binary_sensor.motion_genkan_occupancy
       to: 'on'
       
  condition:
  - condition: and
    conditions:
    - condition: time
      weekday:
      - mon
      - tue
      - wed
      - thu
      - fri
    - condition: or
      conditions:
       - condition: state
         entity_id: input_boolean.eri_home
         state: 'on'
       - condition: state
         entity_id: input_boolean.duc_home
         state: 'on'

  action:
    - service: notify.alexa_media
      data_template:
        data:
          type: tts
        target:
         - media_player.ai_2
        message: 'Welcome home {name of person whose state is 'on'}. Hope you had a wonderful day today.'
    - condition: state
      entity_id: light.h_1
      state: 'off'
    - service: light.turn_on
      entity_id: light.h_1
      data:
        brightness: 200
1 Like

Untested, but it’s something like…

message: >
  {% set name = 'Eri' if states('input_boolean.eri_home' , 'on') else 'Duc' %} 
  Welcome home {{ name }}. Hope you had a wonderful day today. 

Getting this error.

welcome home alexa greeting: Error executing script. Unexpected error for call_service at pos 1: __call__() takes 2 positional arguments but 3 were given

Sorry, try changing states to is_state…

message: >
  {% set name = 'Eri' if is_state('input_boolean.eri_home' , 'on') else 'Duc' %} 
  Welcome home {{ name }}. Hope you had a wonderful day today.

Thanks for correcting the code. While I was testing the code, my motion sensor crapped out. It took me awhile to figure out if it was the code that was the issue the sensor.

1 Like

@anon43302295
I have fixed the motion sensor issue rather figured out why it wasn’t working. It wasn’t a malfunction of the sensor, but a pairing issue.
I’ve gotten a little fancy with the automation and enhanced the script. Announcement will run between 5-8pm. Lights turn on regardless. Randomize some welcome messages. Tested and it works.

There is one little issue I have that I cannot figure out. The announcement happens between 5-8pm. If I am home that day or have came home and decide to leave between those hours, Alexa will make the announcement which will sound strange.

automations.yaml

## Welcome Home Alexa Greeting
- alias: 'motion genkan light on'
  trigger:
    platform: state
    entity_id: binary_sensor.motion_genkan_occupancy
    to: 'on'
  condition:
  - condition: or
    conditions:
      - condition: state
        entity_id: input_boolean.eri_home
        state: 'on'
      - condition: state
        entity_id: input_boolean.duc_home
        state: 'on'
  action:
    - service: script.welcome_notify
    - condition: state
      entity_id: light.h_1
      state: 'off'
    - service: light.turn_on
      entity_id: light.h_1
      data:
        brightness: 200
# Turn off light if no motion after 30 sec
- alias: 'motion genkan light off'
  trigger:
  - entity_id: binary_sensor.motion_genkan_occupancy
    for: 00:00:30
    from: 'on'
    platform: state
    to: 'off'
  action:  
  - service: light.turn_off
    data:
      entity_id: light.h_1

scripts.yaml

# Welcome Home Announcement
  welcome_notify:
    alias: Welcome Home Notify
    sequence:
      - service: notify.alexa_media
        data_template:
          data:
            type: tts
          target:
          - media_player.ai_2
          message: >
           {% if now().hour > 16 and now().hour < 20 %}
            {% set name = 'Eddie' if is_state('input_boolean.eri_home' , 'on') else 'Duck' %} 
             Welcome home {{ name }}. 
             {{ (
             'Hope you had a wonderful day today.',
             'How was your day?',
             'I am glad to see you home.'
             )|random }}
           {% endif %}

I don’t understand your problem?

The code is working as it should. I want to figure out a way to not have it announce the message if I am leaving the house between the set time.

You need to improve your logic for whether you’re entering or leaving. Your current trigger is a motion sensor.

Maybe use a device tracker coming home as the trigger and a wait_template to delay the announcement until the motion sensor is triggered.

Wouldn’t it be the same? Upon leaving the house, the device tracker state is home or on, it will still announce the message.

No, because it would trigger when it goes FROM not_home TO home, if you’re already home it won’t trigger.