You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This can be used in automations/scripts to wait for that event before continuing. I've implemented a timeout in the wait_for_trigger of 30 seconds but that might be excessive. You just want to avoid too short of a timeout in which the update last_called can succeed. This wait_for_trigger avoids manually calling alexa_media.update_last_called and then delaying a fixed period of time before proceeding and also can ensure that last_called was truly updated. It can also avoid the case where the integration is not working and your scripts/automations fail to execute as the Alexa service/entity does not exist.
The event_data: summary: good night is the last thing in the history records that was said to Alexa and is included in the event so you can include that to ensure the last_called is truly correct for this script, or you can elect to not include that check and just proceed.
Another nifty thing I figured out was to create a new Home Assistant user that is only used by the Alexa Skill to integrate HA with Alexa. The Alexa skill then authenticates with HA using that username and you can use that to watch for state_changed events that were triggered by that user to automatically update last_called when Alexa has been asked to do something in HA like turn this or that on|off or when you say something that turns on an Alexa scene (which is an HA script which then waits for the new AMP event to fire).
alias: Alexa - Triggered by Smart Home Skill user account
description: >-
Perform action `Alexa Media Player: Update Last Called Sensor` when entity
states are changed by Alexa Smart Home Skill user account
trigger:
- platform: event
event_type: state_changed
context:
user_id: 0df463c1efc4490f900b09b143cae9c4
condition: []
action:
- action: alexa_media.update_last_called
data: {}
- delay:
hours: 0
minutes: 0
seconds: 6
milliseconds: 0
trace:
stored_traces: 30
mode: single
max_exceeded: silent
System details
Home Assistant version: 2024.9.2
alexa_media version (from const.py or HA startup log): 4.13.1
alexapy version (from pip show alexapy in homeasssistant container or HA startup log): 1.29.2
Is Amazon 2FA/2SV enabled <!---We will not debug login issues if unanswered---> (y/n): Y
Amazon Domain: amazon.ca
Debug Logs (alexa_media & alexapy)
2024-09-17 04:20:13.397 DEBUG (MainThread) [custom_components.alexa_media.services] Service update_last_called for: []
2024-09-17 04:20:13.827 DEBUG (MainThread) [alexapy.alexaapi] d****l@b******a: static GET: https://www.amazon.ca/alexa-privacy/apd/rvh/customer-history-records?startTime=1726485613397&endTime=1726658413397&recordType=VOICE_HISTORY&maxRecordSize=10 returned 200:OK:application/json
2024-09-17 04:20:13.828 DEBUG (MainThread) [custom_components.alexa_media] d****l@b******a: Updated last_called: {'serialNumber': 'G************S0N', 'timestamp': 1726572010837, 'summary': 'turn on kitchen light'}
2024-09-17 04:20:13.828 DEBUG (MainThread) [custom_components.alexa_media] d****l@b******a: last_called changed: {'serialNumber': 'G************6SA', 'timestamp': 1726567732307, 'summary': ','} to {'serialNumber': 'G************S0N', 'timestamp': 1726572010837, 'summary': 'turn on kitchen light'}
2024-09-17 04:20:13.830 DEBUG (MainThread) [custom_components.alexa_media.media_player] d****l@b******a: <entity media_player.office_echo_dot_right=standby> is last_called: G************S0N
2024-09-17 04:20:13.831 DEBUG (MainThread) [custom_components.alexa_media.media_player] d****l@b******a: Refreshing notify targets
2024-09-17 04:20:13.831 DEBUG (MainThread) [custom_components.alexa_media.notify] d****l@b******a: Found last_called <entity media_player.office_echo_dot_right=standby> called at 1726572010837
2024-09-17 04:20:13.831 DEBUG (MainThread) [custom_components.alexa_media.notify] d****l@b******a: Creating last_called target last_called using <entity media_player.office_echo_dot_right=standby> called at 1726572010837
2024-09-17 04:20:13.831 DEBUG (MainThread) [custom_components.alexa_media.notify] d****l@b******a: Found last_called <entity media_player.office_echo_dot_right=standby> called at 1726572010837
2024-09-17 04:20:13.831 DEBUG (MainThread) [custom_components.alexa_media.notify] d****l@b******a: Creating last_called target last_called using <entity media_player.office_echo_dot_right=standby> called at 1726572010837
The text was updated successfully, but these errors were encountered:
danielbrunt57
changed the title
How to utilize the new alexa_media_last_called_event in AMP 4.13.1
How to utilize the new alexa_media_last_called_event in AMP 4.13.x
Sep 17, 2024
Describe the implementation
AMP 4.13.x will now fire an event when last_called is updated.
This can be used in automations/scripts to wait for that event before continuing. I've implemented a timeout in the wait_for_trigger of 30 seconds but that might be excessive. You just want to avoid too short of a timeout in which the update last_called can succeed. This wait_for_trigger avoids manually calling alexa_media.update_last_called and then delaying a fixed period of time before proceeding and also can ensure that last_called was truly updated. It can also avoid the case where the integration is not working and your scripts/automations fail to execute as the Alexa service/entity does not exist.
The
event_data: summary: good night
is the last thing in the history records that was said to Alexa and is included in the event so you can include that to ensure the last_called is truly correct for this script, or you can elect to not include that check and just proceed.Following that, I have:
which is then used in if-then's to conditionally call actionable notifications or
notify.alexa_media_last_called
or...or
Another nifty thing I figured out was to create a new Home Assistant user that is only used by the Alexa Skill to integrate HA with Alexa. The Alexa skill then authenticates with HA using that username and you can use that to watch for state_changed events that were triggered by that user to automatically update last_called when Alexa has been asked to do something in HA like turn this or that on|off or when you say something that turns on an Alexa scene (which is an HA script which then waits for the new AMP event to fire).
System details
const.py
or HA startup log): 4.13.1pip show alexapy
in homeasssistant container or HA startup log): 1.29.2Debug Logs (alexa_media & alexapy)
The text was updated successfully, but these errors were encountered: