Find out which Alexa received voice command

Hi all,

I have 2 Amazon Echo Dot at home and using Nabu Casa. Is there a way to find out which Alexa received the voice command? I would like to send a voice command from Alexa to Home Assistant and send a personalized response to Alexa depending on the status of some sensors.

Example: When I’m about to leave, I would say “Alexa, I’m leaving”, it will check all door and window sensors and say something like “Ok, have a great day” or “Wait! Please check windows before leaving”.

Many thanks

Alexa routines have an option for you to choose which device replies when you give a command, and one possibility is “the device you speak to”. Could you do something with that - call a HA script from a routine, perhaps?

Hi!
Thanks for your answer.
I have seen this option but my script is the responsible to evaluate the condition (window open or close) and prepare the voice response, so this does not work for me.

If you haven’t already, you may want to look into the custom component Alexa Media Player.
It has a way for you to check which device was “last called”.

using the templated sensor.last_alexa from the docs, I found it necessary to wait for last_called_timestamp to update

alias: Alexa wait for last called update
sequence:
  - service: alexa_media.update_last_called
    data: {}
  - wait_template: >-
      {{ now()|as_timestamp() -
      (state_attr('sensor.last_alexa','last_called_timestamp')|default(0,true) /
      1000) < 5 }}
    continue_on_timeout: true
    timeout: "00:00:20"
mode: single
icon: mdi:update

prior to sending a speech response back

alias: Alexa speak
sequence:
  - if:
      - condition: template
        value_template: "{{ target is not defined }}"
    then:
      - service: script.alexa_wait_for_last_called_update
        data: {}
  - service: notify.alexa_media
    data:
      message: |
        <voice name='{{ voice | default('') }}'>{{ message }}</voice>
      data:
        type: tts
      target: "{{ target if target is defined else states('sensor.last_alexa') }}"
mode: queued
fields:
  message:
    name: Message
    required: true
  voice:
    name: Voice
    example: Matthew
  target:
    name: Target
    description: >-
      Alexa media_player or group entity_id. The last called alexa will be used
      if omitted
    example: media_player.kitchen
icon: mdi:account-voice
max: 10

e.g.

- sensor:
    - name: Last Alexa
      state: >
        {% set last_alexa = expand('group.alexa') |selectattr('attributes.last_called','eq',True) |map(attribute='entity_id') |list  %}
        {{ last_alexa[0] if last_alexa|length else none }}
      availability: >
        {% set last_alexa = expand('group.alexa') |selectattr('attributes.last_called','eq',True) |map(attribute='entity_id') |list  %}
        {{ last_alexa|length > 0 }}
      attributes:
        last_called_timestamp: >
          {% set last_alexa = expand('group.alexa') |selectattr('attributes.last_called','eq',True) |map(attribute='entity_id') |list  %}
          {{ state_attr(last_alexa[0],'last_called_timestamp') if last_alexa|length else none }}
        last_called_summary: >
          {% set last_alexa = expand('group.alexa') |selectattr('attributes.last_called','eq',True) |map(attribute='entity_id') |list  %}
          {{ state_attr(last_alexa[0],'last_called_summary') if last_alexa|length else none }}

@wmaker,
I am hoping you can help or direct me to anyone that can help.
Using Alex “Last Called” works perfect; however, the group only contains and recognizes physical devices… Does any one know how to add an Alexa’s Device name if it is called from the Alexa IOS App? I can easily trigger the Alexa routine, but it will not link back to the HA Scene to complete the routine.
My personal background… I am an advanced diabetic. I use several Alexa Routines and HA Scenes that essentially eliminates sticky notes and guessing logged entries. Essentially I can tell Alexa How much insulin and time injected. Everything is stored in a separate log as well as HA Helpers that provide how long ago and what time the last injection was. This works perfectly at home, but, when I am away, Alex’s “Last Called” returns Unavailable; thus disconnecting this life saving database while I am out or on travel.

Any ideas?

“soft Echo” devices such as the iOS App as you and I have noticed don’t behave the same way as “hard” Echo devices, so I don’t know either. However since you can still run a routine, you could probably have the routine send a HA notification with the same text string rather than having Alexa run a text2speech.

Thanks for the response; unfortunately, the routines are very interactive. I will have to find another method to retrieve and update my critical interactive data. Meanwhile, I need to order a case of sticky notes… LOL
image