Last Alexa Sensor using Keaton Taylor Alexa Media Player custom component

Shouldn’t have to change anything, just remove the list.

I’m using the recommended template sensor, but the state updates for the sensor are varying in response time from 3 seconds to over 1 minute. Is that variance to be expected? I was under the impression that running alexa_media.update_last_called would “instantly” update this sensor’s state to the current echo device, but after a few days of testing these delays are killing me.

  • Alexa Routine: “alexa, foobar”
    • Run HA script that calls alexa_media.update_last_called
    • Alexa says: “Wait a moment while I check home assistant”
    • Run HA script that:
      • Wait for trigger: sensor.last_alexa state change (any change)
      • If/else statement that does different things depending on the last used alexa media_player entity

My sensor code:

sensor
  - platform: template
    sensors:
      last_alexa:
        friendly_name: 'Last Alexa'
        value_template: >
          {{ states.media_player | selectattr('attributes.last_called','eq',True) | map(attribute='entity_id') | first }}

Solved – keeping post above for others in this situation. You really do need to group the echos in groups.yaml as the component Wiki says. What was happening without this group setup was the devices were all updating immediately, but the template sensor was updating lazily because it didn’t have specific entities registered.

3 Likes

hi there i have tried each one of the codes below and when testing the config it just et a spinning circle.
what am i missing?

- platform: template
  sensors:
     lalexa:
     friendly_name: 'Last Alexa'
     entity_id: Last Alexa
     value_template: >-
       {% if is_state_attr('media_player.back_room_echo_dot','last_called', true) %}
         back_room_echo_dot
       {% elif is_state_attr('media_player.computer_room_echo_dot','last_called', true) %}
         computer_room_echo_dot
       {% elif is_state_attr('media_player.jeremy_s_echo_dot','last_called', true) %}
         jeremy_s_echo_dot
       {% elif is_state_attr('media_player.loung_echo_dot','last_called', true) %}
         loung_echo_dot
       {% elif is_state_attr('media_player.main_bedroom_echo_dot','last_called', true) %}
         main_bedroom_echo_dot
       {% else %}
         none
       {% endif %}

same with this
- platform: template
  sensors:
    last_alexa:
      entity_id: Last Alexa
        - media_player.back_room_echo_dot
        - media_player.computer_room_echo_dot
        - media_player.jeremy_s_echo_dot
        - media_player.loung_echo_dot
        - media_player.main_bedroom_echo_dot
    value_template: "{{ states.media_player | selectattr('attributes.last_called','eq',True) | map(attribute='entity_id') | first }}"
  1. Please read the AMP docs and Template Sensor docs.

  2. You should be using the current state-based template sensor format, not the legacy format.

  3. entity_id is not a valid configuration variable in the legacy format or the current format.

  4. In your second “sensor” you are using a state object… There has been an explicit warning against using this method for nearly 18 months. In the post immediately above yours:

If you do not want to create a group as suggested in the example on the AMP docs, you can simply list your entities as follows:

###configuration.yaml

template:
  - sensor:
      - name: last_alexa
        state: >
          {{ expand('media_player.back_room_echo_dot', 'media_player.computer_room_echo_dot', 'media_player.jeremy_s_echo_dot', 'media_player.loung_echo_dot', 'media_player.main_bedroom_echo_dot') 
          | selectattr('attributes.last_called','eq',True) | map(attribute='entity_id') | first }}

However, be aware that there have been reliability issues with the last_called function for the past few months. These issues are coming from the Amazon servers websocket connection and are currently not fixable by the AMP devs. The last_alexa sensor sometimes works flawlessly, occasionally it takes from 2 seconds to 2 minutes to update, and rarely it doesn’t update at all.

Thanks for that no more spinning

what i’m trying to do is when someone asks to turn a light off or on. which ever alexa they talk to she will then response with light blah blah is on or off.

trying to find examples of it but i cant really find anything like that

and tried to do it in a automation with last_call no success.

is anyone able to give me a hand in this area?
regards
jeremy

You should start a new topic