Is It Possible to Get the Last Alexa Voice Command?

Hi, I would like to get the last command that was requested to an Alexa. e.g. If I say “Alexa, set a 2 minute timer”, I want to be able to capture the wording of that command.
My goal is to be able to display timers in large text on a dashboard so that we can see the timer clearly.
I was thinking of doing this:

Capture Command
Check if text contains ‘timer’
Get the value from it e.g. “2 minute”
Create my own version of a timer in a Sharptools dashboard.
Change the current dashboard to the timer dashboard.

Possible?

I don’t know if what you want is possible or not but in case it isn’t there may be another way.

The alexa media player custom integration creates an entity for the next timer for each echo device.

you can use that data to create the display for your timer.

If you are using the Alexa Media Player integration, the last_called_summary attribute of the media player entity holds a summary of the most recent spoken command. But you can also get the timer data directly from the next timer sensors. The state of the next timer sensor will be the most next timer, but all activer timers are available in the sorted_active attribute. I use the following in a markdown card to list all active timers:

      {%- for echo in expand('media_player.kitchen_dot',
      'media_player.basement_bedroom_dot', 'media_player.master_bedroom_dot', 
      'media_player.basement_dot', 'media_player.living_room_dot' ) -%}

      {%- set id = (echo.entity_id|string + "_next_timer").replace("media_player", "sensor") %}
      {%- set name = echo.name -%}
      {%- if state_attr(id, 'sorted_active') is defined -%}
        {%- if state_attr(id, 'sorted_active') == '[]' -%}
          {{""}}
        {%- else -%}
          {%- set active = state_attr(id, 'sorted_active')| from_json -%}   
              {%- for item in active %}
                {%- if loop.first%}
                {%- set remaining = (item[1].triggerTime / 1000)|int%}
                {%- set remaining_minutes = ((as_timestamp(now())|int - (remaining))|abs /60 )|round()|int %}
      {%- set label = ( item[1].timerLabel if (item[1].timerLabel != None ) else
      "Timer " + loop.index|string) %}
                {%- if remaining_minutes > 1 -%}
                  {{ '{} \n {}' ': \f \f \f \f' '{}'.format(name, label, remaining_minutes) }} minutes
                {%- elif remaining_minutes > 0 %}
                  {{ '{} \n {}' ': \f \f \f \f'.format(name, label) }} Less than one minute
                {%- endif -%}
                {% else %}
                {%- set remaining = (item[1].triggerTime / 1000)|int%}
                {%- set remaining_minutes = ((as_timestamp(now())|int - (remaining))|abs /60 )|round()|int %}
      {%- set label = ( item[1].timerLabel if (item[1].timerLabel != None ) else
      "Timer " + loop.index|string) %}
                {%- if remaining_minutes > 1 -%}
                  {{- '{}' ': \f \f \f \f' '{}'.format(label, remaining_minutes) }} minutes
                {%- elif remaining_minutes > 0 %}
                  {{ '{} \n {}' ': \f \f \f \f'.format(name, label) }} Less than one minute
                {%- endif -%}{%- endif -%}
              {%- endfor -%}
        {%- endif -%}
      {%- endif -%} 
      {%- endfor-%}
1 Like

Thanks guys. Thats very helpful.

Where do I find this? (sorry for the potentially rookie question)
I know where to find attributes on entities, but there is none on the media.player:


or here:
image

There is nothing like here:
image

You can find all the attributes of a given entity, including the last_called_summary of an Alexa device, using the Developers Tools > State tool.


FYI, every once in a while this will return an empty string ""… There doesn’t seem to be a pattern to it, just keep that in mind before basing any critical automations on this method.

interestingly none of my Alexa devices show anything at all in that attribute.

it’s either empty (blank) or “null”.

When does that get populated? And do you know if it survives a restart?

When it’s working, it seems to populate immediately… but sometimes it seems to skip the first call if it’s blank, “null”, or “”.

I don’t think it survives restart.

1 Like

Then that likely explains it.

Thanks.

I’ve never noticed that attribute before. It could be interesting to see how accurate it is.

That sounds familiar.
from my former times with openhab I remember that the „lastVoiceCommand“ was always reset to an empty string.
However, I don’t know if this was caused by the binding (integration) or the Amazon service.
To cope with this I ignored all changes to an empty sting in my automations.

Anyone who’s fighting with issues on this alexa feature / attribute?
It seems unreliable:
Alexa: last_called_summary unreliable - Home Assistant Community (home-assistant.io)

1 Like