Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

last_called state attributes showing as null; api/activities returned 404:Not Found:text/html #2089

Closed
oneseventhree opened this issue Oct 25, 2023 · 131 comments · Fixed by #2105
Labels
alexapy Issue relates to the API amazonissue Issue needs to have a change made by Amazon bug Something isn't working good first issue Good for newcomers

Comments

@oneseventhree
Copy link

oneseventhree commented Oct 25, 2023

IMPORTANT: Please search the issues, including closed issues, and the FAQ before opening a new issue. The template is mandatory; failure to use it will result in issue closure.

Describe the bug

As the subject says:
image

To Reproduce

  1. Say "alexa"
  2. last_called used to change
  3. Now stays blank

Expected behavior

Screenshots
Happens on all devices:
image

System details

  • Home-assistant (version): 2023.10.5
  • alexa_media (version from const.py or HA startup): 4.7.7
  • alexapy (version from pip show alexapy or HA startup):
  • Amazon 2FA is enabled (y/n). <!---We will not debug login issues if unanswered--->: yes

Logs
Please provide logs.

home-assistant_2023-10-25T09-39-31.640Z.log

Additional context

@oneseventhree oneseventhree changed the title last_called entities showing as null last_called state attributes showing as null Oct 25, 2023
@Pirol62
Copy link

Pirol62 commented Oct 25, 2023

related to this thread: #2090

@danielbrunt57
Copy link

image

I'm fearing the worst may have happened..

@alandtse alandtse added bug Something isn't working help wanted Extra attention is needed good first issue Good for newcomers alexapy Issue relates to the API amazonissue Issue needs to have a change made by Amazon labels Oct 26, 2023
@alandtse
Copy link
Owner

alandtse commented Oct 26, 2023

Cause is due to activities API being down. We'll need a new API endpoint as found by #2090 (comment)

https://www.amazon.com/alexa-privacy/apd/rvh may be a workaround url but will require webscraping. Preference is still an actual API as webscraping is incredibly brittle.

@alandtse alandtse changed the title last_called state attributes showing as null last_called state attributes showing as null; api/activities returned 404:Not Found:text/html Oct 26, 2023
@Fredo70
Copy link

Fredo70 commented Oct 26, 2023

https://www.amazon.com/alexa-privacy/apd/rvh may be a workaround url but will require webscraping. Preference is still an actual API as webscraping is incredibly brittle.

Are you sure it would work? But the URL depends on where the user is. For example, the .com shows me no activity at all. The .de does.

@alandtse
Copy link
Owner

The current code chooses the domain. Again, these are notes for whoever wants to fix it. They will need to figure out the proper way to handle.

@Daverover66
Copy link

Cause is due to activities API being down. We'll need a new API endpoint as found by #2090 (comment)

https://www.amazon.com/alexa-privacy/apd/rvh may be a workaround url but will require webscraping. Preference is still an actual API as webscraping is incredibly brittle.

This won't work for me as the activity history for my account seems to shows nothing.

@Tloram
Copy link

Tloram commented Oct 26, 2023

Cause is due to activities API being down. We'll need a new API endpoint as found by #2090 (comment)

https://www.amazon.com/alexa-privacy/apd/rvh may be a workaround url but will require webscraping. Preference is still an actual API as webscraping is incredibly brittle.

If you check the network xhr requests made from that URL, there is a direct api request URL (different from the above) that returns JSON with most recent used alexa device as the first entry in an array of objects.

It seems to be:

https://[amazon domain for your region]/alexa-privacy/apd/rvh/customer-history-records-v2?startTime=1698274800000&endTime=1698308483234&disableGlobalNav=false

Of course, it will only work if passed the correct headers, cookies, tokens etc. so it might be hard to access it from outside of a logged in Amazon account.

One other thing to note, I tested the latency between issuing a command to an alexa device and this api returning the latest data, there is currently about a 10 second delay/cache mechanism... so this probably makes it almost worthless/pointless to be used for automations that require an immediate response.

@alandtse
Copy link
Owner

You can try replacing the url in alexapy and perhaps the component will have the right auth.

The delay was always there since it has to round trip up to Amazon and then back. It's possible this api is slower. I forgot if we rely on the http2 push stream for the data before the url returns but it seems like something I would've done before.

@danielbrunt57
Copy link

danielbrunt57 commented Oct 26, 2023

The delay was always there since it has to round trip up to Amazon and then back. It's possible this api is slower. I forgot if we rely on the http2 push stream for the data before the url returns but it seems like something I would've done before.

Alan,
Is HTTP2 rather new?
About a week or two ago, I had instant updating of my media players' last_called(_xxx) attributes for about a day or so. I tested it over and over and it was virtually instantaneous (< 1s). It surprised me greatly and I thought it might have been related to HTTP2...

@Fredo70
Copy link

Fredo70 commented Oct 26, 2023

I used to have openHAB. But I no longer have openHAB. So I can't test it.
The URL "/api/activities" is also called up in the original binding.
However, there is a fork and there a request is made for "https://" + getAmazonSite() + "/alexa-privacy/apd/rvh/customer-history-records". Maybe this can help? The language is Java.
https://github.com/smarthomej/addons/blob/bc8a20aa95e764c3008e1351ec075b6d8bc9764f/bundles/org.smarthomej.binding.amazonechocontrol/src/main/java/org/smarthomej/binding/amazonechocontrol/internal/connection/Connection.java#L938

Pull request: smarthomej/addons#235

@sdholden28
Copy link

Seems to be an intentional change on Amazon's part. This went out to ifttt users today.

We’re writing to let you know that on October 31st, 2023 the Amazon Alexa service will no longer be available on IFTTT.

Amazon has made the decision to no longer support their integration on IFTTT. Like you, many of us here on the IFTTT team use the Alexa IFTTT integration daily for things ranging from controlling lights and music in our homes to integrating with task management apps to boost productivity. We were disappointed to hear about this change, we understand it is always difficult to see an existing service removed from IFTTT.

We encourage you to update your Alexa Applets to use alternative triggers prior to October 31st. You can find more information on how to update your Applets, as well as suggested alternative triggers [here].

Starting November 1st, Applets that use the Say a specific phrase trigger will be migrated to instead use the IFTTT Button Widget. Applets that use any Amazon Alexa trigger other than Say a specific phrase or any Amazon Alexa query will be archived on October 31st if they are not updated to use a different trigger and/or query prior to that date.

IFTTT Community team

@Cpd5899
Copy link

Cpd5899 commented Oct 26, 2023

Seems to be an intentional change on Amazon's part. This went out to ifttt users today.

We’re writing to let you know that on October 31st, 2023 the Amazon Alexa service will no longer be available on IFTTT.

Amazon has made the decision to no longer support their integration on IFTTT. Like you, many of us here on the IFTTT team use the Alexa IFTTT integration daily for things ranging from controlling lights and music in our homes to integrating with task management apps to boost productivity. We were disappointed to hear about this change, we understand it is always difficult to see an existing service removed from IFTTT.

We encourage you to update your Alexa Applets to use alternative triggers prior to October 31st. You can find more information on how to update your Applets, as well as suggested alternative triggers [here].

Starting November 1st, Applets that use the Say a specific phrase trigger will be migrated to instead use the IFTTT Button Widget. Applets that use any Amazon Alexa trigger other than Say a specific phrase or any Amazon Alexa query will be archived on October 31st if they are not updated to use a different trigger and/or query prior to that date.

IFTTT Community team

Thats great.... (sarcasm) It would be really great, if someone from HA would tell us something. I posted in the forum, but apparently I am the only one who uses it, since there is no response. LOL

@vinimeca
Copy link

I use the "last alexa" for a lot of automations and it is very important in HA. All of this is useless now. Please someone help.

@master-kenobi
Copy link

I use the "last alexa" for a lot of automations and it is very important in HA. All of this is useless now. Please someone help.

me too

@github-actions github-actions bot removed the help wanted Extra attention is needed label Oct 27, 2023
@danielbrunt57
Copy link

danielbrunt57 commented Oct 27, 2023

Thats great.... (sarcasm) It would be really great, if someone from HA would tell us something. I posted in the forum, but apparently I am the only one who uses it, since there is no response.

You are not the only one using it as there are 1,200 "*" but it has nothing to do with anyone at Home Assistant per se since Alexa Media Player is a custom component by Alan Tse and contributed to by 35 other contributors over the years. Not to mention it's using an unofficial API to accomplish its miraculous feats! I applaude them for what they've been able to achieve and if it's to be be no more then so be it. You can blame Amazon but not HA. But, I've not given up hope yet!

I've edited my scripts/automations and fortunately, only good_night/good_morning were my biggest calls, which 99.99% of the time I make from bedroom so I have hard coded them to bedroom_echo_right (on my night stand). Car arrival script asking to close garage door was already hard coded to garage echo. The only other script/scene was "light" which I developed to turn on the lights in the area I'm in but will have to use Alexa, turn on the light and ensure Alexa's areas are properly set up. I'm sure for other users/implementations, it won't be so easy!

@alandtse alandtse added the help wanted Extra attention is needed label Oct 27, 2023
@acid115
Copy link

acid115 commented Oct 27, 2023

But maybe there is hope.
If you call https://alexa.amazon.de/api/activities
Then you see the following:
generic.png

So, maybe the Service is just temporarly unavailable and works again in a few days

@Fredo70
Copy link

Fredo70 commented Oct 27, 2023

As I wrote in #2089 (comment) above, it should be possible with this solution. But I don't know how reactive the contributors are.
I would like to try it myself, but I really need support from a contributor. Because... I've never contributed to HA before, I haven't set up a development environment for HA, I only have a basic knowledge of Python, I have no idea about the Alexa API and authentication. I really need an exchange so that I don't do anything wrong and more than once.
Besides, my free time is very tight, so it could take longer.

@danielbrunt57
Copy link

But maybe there is hope. If you call https://alexa.amazon.de/api/activities Then you see the following: ![generic.png]

So, maybe the Service is just temporarly unavailable and works again in a few days

O maybe not! There have been lots of layoffs recently in Amazon's Alexa dev workforce...

@Pirol62
Copy link

Pirol62 commented Oct 27, 2023

I may have a quite good work around for the meantime.
Here it solves 80% of the issues and works for all guys, who have motion sensors in at least most of all rooms.
Its not 100% accurate even when two or more persons moving around in the house but it can increase the situation

I had an automation whitch wrotes the location of the latest movement into a variable:

- service: variable.update_sensor
  data:
	value: "{{now().strftime('%H:%M:%S - %d-%m-%Y')}}"
	attributes:
	  location: "{{trigger.to_state.attributes.friendly_name}}"
  target:
	entity_id: sensor.last_general_motion_detected

I created an additional sensor around the location attribute in order to display that in a button_card

Now I already wrote a custom template which translates a given movement into an alexa media_player

{% macro last_movement_alexa_target(palexa) %}
{% if states('sensor.last_called_alexa') == 'media' %}
   {% set map = {
   "Wohnzimmer": "media_player.unten",
   "Gästezimmer": "media_player.gastezimmer",
   "Office": "media_player.office",
   "Office 2": "media_player.office",
   "Küche": "media_player.kuche",
   "Fitnessraum": "media_player.fitnessraum",
   "Schlafzimmer": "media_player.dachgeschoss",
   "Treppe oben": "media_player.dachgeschoss"}
   %}
   {{ map[palexa] if palexa in map else 'media_player.wohnzimmer' }} 
{% else %}
   {{states('sensor.last_called_alexa')}}
{% endif %}
{% endmacro %}````

and now I can build my own alexa last_called

command_announce_something:
  variables:
     vtarget: "init"
  sequence:
    - service: alexa_media.update_last_called
    - delay: 00:00:01
    - variables:
        vtarget: >
          {% from 'global_functions.jinja' import last_movement_alexa_target %}
          {{ last_movement_alexa_target() }}
    - service: notify.alexa_media
	  data:
		target: "{{vtarget}}"
		data:
		  type: tts
		message: "bla bla"

with a little more time it can shurely be defined a little more sophisticated,
but on the other hand we hope that its only for a short time

Edit 28.10: improved the macro a little
Edit: 30.10 make it so, that I either can modify update_last_called in an own script or wait until it works again

@sexelevatormusik
Copy link

@master-kenobi

Thanks @Fredo70. Everything works like it should now. The alexapy folder is now added to my config folder. I assume once it is merged into the official release, I can remove the folder?

you should absolutely remove the folder after it's in the official release. you won't get new updates if you don't.

Which folder needs to be removed?

@danielbrunt57
Copy link

danielbrunt57 commented Nov 6, 2023

@sexelevatormusik

Which folder needs to be removed?

The one which you manually created when you followed the procedure to implement @fredo's temporary solution!

The folder you should have created is /config/alexapy

image

@npa-homeassistant
Copy link

Yay! It's back!

Thanks for resolving this. It was like being back in the dark ages (two years ago).

@msolomos
Copy link

msolomos commented Nov 7, 2023

although the scripts works now, I have problem because each time the wrong alexa is selected

@garysargentpersonal
Copy link

although the scripts works now, I have problem because each time the wrong alexa is selected

Are you calling the HA service to refresh the last used Alexa before using the value?

@oneseventhree
Copy link
Author

although the scripts works now, I have problem because each time the wrong alexa is selected

Are you calling the HA service to refresh the last used Alexa before using the value?

How are you doing it? Do you have an example?

@formatBCE
Copy link

although the scripts works now, I have problem because each time the wrong alexa is selected

Are you calling the HA service to refresh the last used Alexa before using the value?

How are you doing it? Do you have an example?

Call service.update_last_called.

@msolomos
Copy link

msolomos commented Nov 7, 2023

although the scripts works now, I have problem because each time the wrong alexa is selected

Are you calling the HA service to refresh the last used Alexa before using the value?

thank you for your reply. Yes I am indeed. Here is the automation I'm using for years. Never had a problem before
https://pastebin.com/aefPSzeP

It doesn't work properly anymore. The sensor.last_alexa is not updated properly

@danielbrunt57
Copy link

danielbrunt57 commented Nov 7, 2023

Here is the automation I'm using for years. Never had a problem before
https://pastebin.com/aefPSzeP

That looks correct to me!

Had you installed @Fredo70's interim fix?
If so, and you had created /config/alexapy/, did you remove that folder?
Have you installed/updated Alexa Media Player to v4.7.9?
Have you tested service: media_player.update_last_alexa in Dev Tools while invoking a question like Alexa, what is the time? on different Echos?

My service: media_player.update_last_alexa is taking roughly 0.5s to update now and so far has succeeded 100% of the time.

Here is my sensor.last_alexa:

image

  - name: Last Alexa
    unique_id: last_alexa
    icon: phu:amazon-logo
    state: >
      {{ states.media_player | selectattr('attributes.last_called','eq',true) | map(attribute='entity_id') | first | default(none) }}
    availability: >
      {{ states.media_player | selectattr('attributes.last_called','eq',true) | map(attribute='attributes.last_called_timestamp') | first is defined }}
    attributes:
      last_called_timestamp: >
        {{ states.media_player | selectattr('attributes.last_called','eq',true) | map(attribute='attributes.last_called_timestamp') | first | default(none) }}
      actual_friendly_name: >
        {{ states.media_player | selectattr('attributes.last_called','eq',true) | map(attribute='attributes.friendly_name') | first | default(none) }}

I had also created a media_player.last_alexa via the Universal Media Player integration as something, somewhere, at one point required entity_id: media_player.xxx and did not accept templating:

media_player:
  - platform: universal
    name: "Last Alexa"
    unique_id: media_player.last_alexa
    state_template: "{{ states.media_player|selectattr('attributes.last_called','eq',true)|map(attribute='entity_id') | first | default(none) }}"

This is the script I invoke to update sensor.last_alexa. Note the wait_for_trigger based on the attribute last_called_timestamp.
I added that attribute to sensor.last_alexa as waiting for the entity state to change did not work when the from_state.state and the to_state.state (i.e. media_player.bedroom_echo_dot_right) were unchanged but the last_called_timestamp had changed.

image

alias: "Alexa: Update sensor.last_alexa - wait for tmestamp to update"
sequence:
  - parallel:
      - wait_for_trigger:
          - platform: state
            entity_id:
              - sensor.last_alexa
            attribute: last_called_timestamp
        timeout:
          hours: 0
          minutes: 0
          seconds: 5
          milliseconds: 0
      - service: alexa_media.update_last_called
        data: {}
    enabled: true
mode: single

(when I look at my traces, the time remaining in the wait_for_trigger has been around 4.5 seconds meaning it took roughly 1/2 second to update)

My other scripts always call the above script before doing anything else:

alias: Good Night
sequence:
  - service: script.update_last_alexa_and_wait
    data: {}
  - if:
      - condition: state
        entity_id: input_boolean.coffee_prepared
        state: "off"
    then:
      - service: script.activate_alexa_actionable_notification
        data:
          text: Did you prepare your coffee?
          event_id: actionable_notification_coffee_prepared
          alexa_device: "{{ states('media_player.last_alexa') }}"
  - if:
      - condition: state
        entity_id: input_boolean.garbage_is_out
        state: "off"
      - condition: or
        conditions:
          - condition: and
            conditions:
              - condition: state
                entity_id: sensor.garbage
                state: "0"
              - condition: time
                before: "09:00:00"
                weekday:
                  - wed
                after: "00:00:00"
          - condition: and
            conditions:
              - condition: state
                entity_id: sensor.garbage
                state: "1"
              - condition: time
                after: "12:00:00"
                weekday:
                  - tue
                before: "00:00:00"
    then:
      - service: script.activate_alexa_actionable_notification
        data:
          text: Did you put the garbage out?
          event_id: actionable_notification_garbage_pickup
          alexa_device: "{{ states('input_text.last_alexa') }}"
      - wait_for_trigger:
          - platform: event
            event_type: alexa_actionable_notification
            event_data:
              event_id: actionable_notification_garbage_pickup
        timeout:
          hours: 0
          minutes: 0
          seconds: 15
          milliseconds: 0
        enabled: false
  - if:
      - condition: state
        entity_id: input_boolean.recycling_is_out
        state: "off"
      - condition: or
        conditions:
          - condition: and
            conditions:
              - condition: state
                entity_id: sensor.recycling
                state: "0"
              - condition: time
                before: "09:00:00"
                weekday:
                  - thu
                  - fri
                after: "00:00:00"
          - condition: and
            conditions:
              - condition: state
                entity_id: sensor.recycling
                state: "1"
              - condition: time
                after: "12:01:00"
                weekday:
                  - wed
                  - thu
                before: "00:00:00"
    then:
      - service: script.activate_alexa_actionable_notification
        data:
          text: Did you put the recycling out?
          event_id: actionable_notification_recycling_pickup
          alexa_device: "{{ states('input_text.last_alexa') }}"
      - wait_for_trigger:
          - platform: event
            event_type: alexa_actionable_notification
            event_data:
              event_id: actionable_notification_recycling_pickup
        timeout:
          hours: 0
          minutes: 0
          seconds: 15
          milliseconds: 0
        enabled: false
  - parallel:
      - if:
          - condition: not
            conditions:
              - condition: state
                entity_id: climate.living_room
                attribute: preset_mode
                state: eco
                alias: Preset of Furnace
            alias: If Preset of Furnace is NOT  'eco'
          - condition: numeric_state
            entity_id: climate.living_room
            attribute: temperature
            above: 17
            alias: Furnace temperature is above 17
        then:
          - service: climate.set_temperature
            data:
              temperature: 17
            target:
              entity_id: climate.living_room
          - service: script.notify_alexa_media
            data:
              message: Heat is now set to 17
      - service: media_player.turn_off
        target:
          entity_id:
            - media_player.bedroom_tv
            - media_player.living_room_tv
        data: {}
      - if:
          - condition: state
            entity_id: lock.front_door_lock
            state: unlocked
        then:
          - service: lock.lock
            data: {}
            target:
              entity_id: lock.front_door_lock
          - service: script.notify_alexa_media
            data:
              message: The front door was unlocked but I locked it for you.
      - if:
          - condition: state
            entity_id: cover.garage_door
            state: open
        then:
          - if:
              - condition: state
                entity_id: sensor.season
                state: summer
            then:
              - service: script.notify_alexa_media
                data:
                  message: Hey. Did you know the garage door is open?
                  milliseconds: 0
            else:
              - service: cover.close_cover
                data:
                  entity_id: cover.garage_door
              - service: script.notify_alexa_media
                data:
                  message: I closed the garage door for you
                  milliseconds: 0
      - service: input_select.select_option
        data:
          option: Sleeping
        target:
          entity_id: input_select.sleep_status
      - service: input_boolean.turn_on
        data: {}
        target:
          entity_id:
            - input_boolean.sleep_mode
            - input_boolean.daniel_sleeping
      - service: input_number.set_value
        data:
          value: 0
        target:
          entity_id: input_number.bathroom_delay_off
      - service: light.turn_off
        data: {}
        target:
          area_id:
            - living_room
            - patio
      - if:
          - condition: numeric_state
            entity_id: sensor.fordpass_elveh
            below: 100
          - condition: state
            entity_id: sensor.wallbox_32a_charger
            state: "off"
        then:
          - service: script.notify_alexa_media
            data:
              message: >-
                Your Mach E battery range is only {{
                states("sensor.fordpass_elveh")|int(0) }} kilometers
  - delay:
      hours: 0
      minutes: 0
      seconds: 5
      milliseconds: 0
  - service: media_player.play_media
    continue_on_error: true
    data:
      media_content_id: Alexa.GoodNight.Play
      media_content_type: sequence
    target:
      entity_id: "{{ states('media_player.last_alexa') }}"
    alias: "Media Player: Say Goodnight"
  - wait_for_trigger:
      - platform: state
        entity_id:
          - sensor.last_alexa
        attribute: last_called_timestamp
    enabled: false
  - delay:
      hours: 0
      minutes: 0
      seconds: 3
      milliseconds: 0
  - service: light.turn_off
    target:
      entity_id:
        - light.bnl_l
        - light.bnl_r
        - light.bedroom_bedside_lamps
    data: {}
  - if:
      - condition: state
        entity_id: binary_sensor.bathroom_occupancy
        state: "off"
    then:
      - service: light.turn_off
        data: {}
        target:
          device_id: 93d77be359d4c8f809c2a09a581bea2e
mode: single
icon: hass:weather-night

I also issue all TTS via a single script which queues all utternaces with a variable delay based on the word count in the current message so they don't interrupt one another. My input_number.alexa_word_duration is currently set to 0.5:

alias: "Alexa: Notify Alexa Media"
description: Send notification to sensor.last_alexa
fields:
  message:
    description: The message content
    example: I am notifying you
sequence:
  - service: notify.alexa_media
    continue_on_error: true
    data:
      message: "{{ message }}"
      data:
        type: tts
      target: "{{ states('media_player.last_alexa') }}"
  - delay:
      seconds: >-
        {{ (message.split(' ') | count *
        states('input_number.alexa_word_duration')|float ) | round(0, 'floor',
        default) }}
mode: queued
icon: mdi:account-voice
max: 10

Any questions, fire away...

@ahahamyan
Copy link

My setup is working perfectly. I manually removed the interim solution config/alexapy folder, updated Alexa Media Player to 4.7.9 and restarted HA and for example in my script that responds with status of my garage doors initiated by alexa routine via voice I have the following two sequence steps - works 100 percent of the time from the right device :

service: alexa_media.update_last_called
data: {}

service: notify.alexa_media_last_called
data:
message: |
Garage one is

{% if is_state('binary_sensor.garage_1_sensor_sensor_state_any', 'on') %}
       open     
{% endif %}

{% if is_state('binary_sensor.garage_1_sensor_sensor_state_any', 'off') %}
       closed     
{% endif %}

and Garage two is

{% if is_state('binary_sensor.garage_2_sensor_sensor_state_any', 'on') %}
       open     
{% endif %}

{% if is_state('binary_sensor.garage_2_sensor_sensor_state_any', 'off') %}
       closed     
{% endif %}

title: Home Assistant
data:
type: announce

@danielbrunt57
Copy link

service: notify.alexa_media_last_called

This used to be problematic in the past (up until about 4-5 months ago) when service: alexa_media.update_last_called is called or when the integration happens to perform an update on its own as the integration has to remove the registered notify service and register a new one. If you happen to invoke it during the very small window of time when it's removing/re-registering, HA pukes with an unknown service call error. Once I ascertained that, and Alan Tse confirmed that's the only way it can be done, I stopped using notify.alexa_media_last_called since there was a minute chance it could fail.

@Krocko
Copy link

Krocko commented Nov 8, 2023


  - name: Last Alexa

    unique_id: last_alexa

    icon: phu:amazon-logo

    state: >

      {{ states.media_player | selectattr('attributes.last_called','eq',true) | map(attribute='entity_id') | first | default(none) }}

    availability: >

      {{ states.media_player | selectattr('attributes.last_called','eq',true) | map(attribute='attributes.last_called_timestamp') | first is defined }}

    attributes:

      last_called_timestamp: >

        {{ states.media_player | selectattr('attributes.last_called','eq',true) | map(attribute='attributes.last_called_timestamp') | first | default(none) }}

      actual_friendly_name: >

        {{ states.media_player | selectattr('attributes.last_called','eq',true) | map(attribute='attributes.friendly_name') | first | default(none) }}

Is it possible to convert this timestamp in date time?

@gary-sargent
Copy link

Agh annoying! This is still not working 100%! Damn you Amazon!

@Fredo70 I'm frequently seeing 429 responses to the history URL which is too many requests - but immediately recalling the URL more often than not just works! Seems to happen even with 10 second gap between calls. You can replicate by loading the history URL in a browser and hitting F5 (refresh).

Maybe we need a few retries when we get an 4xx error message :(

@Fredo70
Copy link

Fredo70 commented Nov 8, 2023

Agh annoying! This is still not working 100%! Damn you Amazon!

@Fredo70 I'm frequently seeing 429 responses to the history URL which is too many requests - but immediately recalling the URL more often than not just works! Seems to happen even with 10 second gap between calls. You can replicate by loading the history URL in a browser and hitting F5 (refresh).

Maybe we need a few retries when we get an 4xx error message :(

@gary-sargent
Ok. I also keep getting this error in the browser. Not really with the integration yet. I will see what I can do. But at the moment I'm very busy with other things. It will take some time. Sorry. If anyone else wants to try it out, please let me know so that we don't do the same job twice.

@gary-sargent
Copy link

@Fredo70 stand down as it looks like the integration does already handle this. I'm seeing this in the HA logs:

[alexapy.alexaapi] Backing off _static_request(...) for 0.6s (alexapy.errors.AlexapyTooManyRequestsError: Too Many Requests)

Looks like it tries 5 times then gives up, and I've just been unlucky and had five in a row. Maybe we should up the retries to 10, but apart from that not much we can do.

@danielbrunt57
Copy link

Is it possible to convert this timestamp in date time?

Of course it is but why would you want to???

@danielbrunt57
Copy link

danielbrunt57 commented Nov 8, 2023

Is it possible to convert this timestamp in date time?

Google is your best friend! Alas, currently not so true with Amazon/Alexa...

@Krocko
Copy link

Krocko commented Nov 9, 2023

Is it possible to convert this timestamp in date time?

Google is your best friend!

Yes, but the problem is the 13 digits from the Alexa timestamp. The Unix timestamp has 10 digits. How can I remove the last 3 digits?

@formatBCE
Copy link

Is it possible to convert this timestamp in date time?

Google is your best friend!

Yes, but the problem is the 13 digits from the Alexa timestamp. The Unix timestamp has 10 digits. How can I remove the last 3 digits?

Divide by 1000. It's milliseconds instead of seconds.

@alandtse
Copy link
Owner

Looks like it tries 5 times then gives up, and I've just been unlucky and had five in a row. Maybe we should up the retries to 10, but apart from that not much we can do.

429 means Amazon is literally telling you to stop. In truth we should probably not even have the retry behavior on 429s so increasing the retry count is probably not a good idea.

@garysargentpersonal
Copy link

@alandtse I know what you mean, but the times they send that response make no sense at all. You don't need to hammer if to cause it. Even their own website suffers from it. Maybe the flood protection they have is for all users not just you. You can literally connect once an hour and still hit it.

@lloydbayley
Copy link

I'm not being difficult here but I have had no trouble whatsoever with my installation since the first very kind fix by @Fredo70 and then the official update. Is there something I should look out for or just leave well-enough alone?

@garysargentpersonal
Copy link

garysargentpersonal commented Nov 10, 2023

The error you'd see in HA logs is:

Unexpected error for call_service at pos 1: Too Many Requests

I've only seen it once since installing the fix - so it isn't happening frequently.

However if you search your FULL logs for "AlexapyTooManyRequestsError" you'll probably see lots of them. I have nearly 300. Each time this happens four more attempts are tried, then you get the giving up error I posted at the top.

You will also notice that sometimes when you call the service to refresh last alexa it is very sluggish. This is because it is retrying a few times (with delays inbetween) before you finally get a result. This doesn't happen every time, but sometimes can be 5 to 10 seconds.

@garysargentpersonal
Copy link

garysargentpersonal commented Nov 10, 2023

Here is a series of logs where I get four fails, then the fifth worked - but you can see the delays cause the service call to take a while. From hitting the endpoint manually, I don't think the exponential back-off makes any difference to the response from the API, so personally I'd be up for making the delay 0.3s consistently, and retry up to 10 times.

2023-11-08 08:06:50.003 INFO (MainThread) [alexapy.alexaapi] Backing off _static_request(...) for 0.1s (alexapy.errors.AlexapyTooManyRequestsError: Too Many Requests)

2023-11-08 08:06:50.200 INFO (MainThread) [alexapy.alexaapi] Backing off _static_request(...) for 1.3s (alexapy.errors.AlexapyTooManyRequestsError: Too Many Requests)

2023-11-08 08:06:51.627 INFO (MainThread) [alexapy.alexaapi] Backing off _static_request(...) for 3.8s (alexapy.errors.AlexapyTooManyRequestsError: Too Many Requests)

2023-11-08 08:06:55.526 INFO (MainThread) [alexapy.alexaapi] Backing off _static_request(...) for 5.3s (alexapy.errors.AlexapyTooManyRequestsError: Too Many Requests)

@Daverover66
Copy link

Hey guys. My last_alexa_called was working just fine until I updated to 4.7.9 and now they're all showing "null". I've tried a couple of service calls to update but still nothing. There is nothing in the logs. What's going on?

@lloydbayley
Copy link

Thanks @garysargentpersonal, I don't have any of the 'Too Many Requests' error and I haven't noticed any sluggishness but I do have a few "A connection error occurred: An exception of type ClientConnectorError occurred."-type error for AlexaPy helpers etc but aside from that (without hunting), I seem to be ok. I suppose I should just be content but still be aware of what to look for if something goes on. It's just odd for me not to be affected when loads of others are but perhaps I shouldn't poke the bear! :)

@garysargentpersonal
Copy link

@lloydbayley what Amazon region are you in? I'm UK so it could be specific to my region.

@lloydbayley
Copy link

lloydbayley commented Nov 10, 2023

Good point....I'm in AUstralia so I use the amazon.com.au endpoint (well, it SAYS I do but I'm wondering if some of it is redirected as an afterthought somewhere in the process). Hey ho!

@lloydbayley
Copy link

@garysargentpersonal Actually, I think @ahahamyan 's comment about it working perfectly may lend a bit more credence to our theory that it may be endpoint (location)-based. It's interesting to watch and diagnose.

@asfasty
Copy link

asfasty commented Jan 21, 2024

Hello, I just got it back working today. Maybe this helps.
I am located in german but usually browse through amazon.com
I deleted all mfa in my amazon account and created a new one.
Configured the integration and before confirming my otp token successfully went back to the amazon account and found an option like this:

image

So I said no OTP for this app token.
Then took the otp shown in the integration setup.
Confimed the integration "successfully authenticated..."
Headed back over to the amazon page - put in the token from the integration.
(please don't beat me if I have the steps not in the right order)

My HA is available through duckdns.org

Then the integration wants to open the sign in page. Signed in with two-step only and said no otp for this browser.
Then the integration was successfully set up and found my device.

image

I just don't know if this information is really helpful. Since I cannot see devices I have set up in alexa. This horrible woox thing is not integrating in local tuya, so I thought I can go the other way round and tried the alexa media player add-on....

Please delete this comment if not helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
alexapy Issue relates to the API amazonissue Issue needs to have a change made by Amazon bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.