alandtse / alexa_media_player

This is a custom component to allow control of Amazon Alexa devices in Home Assistant using the unofficial Alexa API.
Apache License 2.0
1.51k stars 289 forks source link

Last Alexa unavailable no matter what I do #2509

Closed simondrake closed 1 month ago

simondrake commented 1 month ago

Describe the bug

For some reason, my last_alexa template has been in an unavailable state for the last few weeks and I'm at a loss for why.

To Reproduce

Add the following to configuration.yaml:

template:
  - sensor:
      - name: Last Alexa
        state: |-
          {{ expand(integration_entities('alexa_media') | select('search', 'media_player'))
          | selectattr('attributes.last_called', 'eq', True) | map(attribute='entity_id') | first }}
        availability: |-
          {{ expand(integration_entities('alexa_media') | select('search', 'media_player'))
          | selectattr('attributes.last_called','eq',True) | first is defined }}

Go to the entities page and see that is in unavailable, despite trying the alexa_media.update_last_called action multiple times. Adding the template in state and availability to Developer tools > Template outputs the following:

media_player.office_speaker

True

So I'm unsure why HA thinks it's unavailable, as it is reporting the correct values.

Expected behavior

Last alexa is not unavailable

System details

danielbrunt57 commented 1 month ago

First thing I found with what you posted above is you have a four space indentation after - sensor: when it should be two spaces.

Try adding mine in addition to yours...

    - name: My Last Alexa
      unique_id: my_last_alexa
      state: |-
       {{ expand(integration_entities('alexa_media') | select('search', 'media_player'))
       | selectattr('attributes.last_called', 'eq', True) | map(attribute='entity_id') | first }}
      availability: |-
       {{ expand(integration_entities('alexa_media') | select('search', 'media_player'))
       | selectattr('attributes.last_called','eq',True) | first is defined }}
simondrake commented 1 month ago

@danielbrunt57 I'll give it a go, but I'd be surprised if it was an indentation issue as yaml doesn't have strict rules around number of spaces.

Thanks! I'll report back

simondrake commented 1 month ago

Just tried it - same problem, showing as unavailable.

danielbrunt57 commented 1 month ago

So you now have two last_alexa sensors? Your original and the new one?

And Dev Tools -> STATES shows media_players. with last_called attributes as either true or false?

image

If so, there is seriously something not right with your HA templated entities and their failure to update and that's not really an AMP problem. I'd be having a serious look at any other templated entities you have. No idea what the issue might be...

danielbrunt57 commented 1 month ago

Do you have only one instance of template: in configuration.yaml?

template:
  - binary_sensor:
    - name:
    - name:

  - select:
    - name:
    - name:

  - sensor:
    - name:
    - name:

  - trigger:
    - name
    - name
simondrake commented 1 month ago

So you now have two last_alexa sensors? Your original and the new one?

Yeah, I did. But then I removed the my_last_alexa as both were showing as unavailable.

And Dev Tools -> STATES shows media_players. with last_called attributes as either true or false?

Yep! Here's the living room echo, showing last_called: true, but the last Alexa is still unavailable

image

image

If so, there is seriously something not right with your HA templated entities and their failure to update and that's not really an AMP problem. I'd be having a serious look at any other templated entities you have. No idea what the issue might be...

It's weird, this is the only template entity I have that is defined in the configuration file.

Do you have only one instance of template: in configuration.yaml?

No this is literally the only template sensor I have.

Thanks for the help. I can keep looking around to see if I can figure out where things have gone wrong.

danielbrunt57 commented 1 month ago

Can you post your full configuration.yaml file (minus any sensitive info)?

simondrake commented 1 month ago

I backed up my configuration.yaml and made it as bare bones as possible (I've kept the !include statements). So the following is exhibiting the problem:


# Loads default set of integrations. Do not remove.
default_config:

# Load frontend themes from the themes folder
frontend:
  themes: !include_dir_merge_named themes

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

template:
  - sensor:
      - name: Last Alexa
        unique_id: last_alexa
        state: |-
          {{ expand(integration_entities('alexa_media') | select('search', 'media_player'))
          | selectattr('attributes.last_called', 'eq', True) | map(attribute='entity_id') | first }}
        availability: |-
          {{ expand(integration_entities('alexa_media') | select('search', 'media_player'))
          | selectattr('attributes.last_called','eq',True) | first is defined }}

Which gives me a last_alexa identity that is Unavailable, but weirdly the history shows that it had state (which the previous didn't) -

image

I tried talking to the Alexa in my office and running alexa_media.update_last_called, in case it would kick it into life but that it still didn't update. Even though it definitely does have the right attribute:

image

And the template editor shows the values correctly:

image

simondrake commented 1 month ago

And, as if by magic, putting back my configuration.yaml has kicked it into life and now it's working....

image

danielbrunt57 commented 1 month ago

Bizarre! Glad it's finally resolved though.

simondrake commented 1 month ago

Thank you for the help :)