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.
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-%}
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.
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.