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.5k stars 287 forks source link

custom Alexa command #2630

Open mikeaumiller opened 5 days ago

mikeaumiller commented 5 days ago

NOTE: For a feature to be created it has to be doable in the Amazon app because we are basically replicating the app for HA. If you can't find it in the app, we probably can't create it here.

Is your feature request related to a problem? Please describe. Possibly? Send a custom Alexa command that has the value of a sensor

Describe the solution you'd like Within the media_content_id field I would like to use the value of a sensor as part of the command within media_player.play_media Action. Before sending the command the sensor value would be translated.

Describe alternatives you've considered None

Additional context Example: Alexa, move music to echo’
would result in sending: Alexa, move music to family room echo

danielbrunt57 commented 2 days ago

I just tried this and it worked fine:

action: media_player.play_media
data: 
  media_content_type: custom
  media_content_id: "move music to {{ state_attr('sensor.last_alexa', 'actual_friendly_name') }}"
target:
  entity_id: media_player.kitchen_echo_dot

My sensor.last_alexa is currently derived from node-red-contrib-alexa-remote2-applestrudel that I'm playing with but you should be able to template your as needed.

image

mikeaumiller commented 2 days ago

I haven’t tried using the friendly name from last_alexa. What’s interesting, is in Developer Tools or manually it translates fine, but not in an automation — When enabled my Alexa errors and says that it doesn’t recognize an echo with that name to move music to.

Automation example shown below:

The automation checks to see if the office echo is playing. Then based on the current room location of my phone which it gets from — sensor.galaxy_s24_ultra_ble (via ESPresence BLE tracker), it completes ‘move music to’ sentence.

The purpose of the script is to have music follow me from room to room.


alias: Auto Music
description: Music follows from room to room
triggers:
  - trigger: state
    entity_id:
      - input_select.room_select
    to: Auto
conditions:
  - condition: template
    value_template: {{ state_translated(‘media_player.office_echo’) == ‘Playing’ }}
actions:
  - action: media_player.play_media
    metadata: {}
    data:
      media_content_type: custom
      media_content_id: move music to {{ states('sensor.galaxy_s24_ultra_ble') }} echo
mode: single
danielbrunt57 commented 2 days ago

Your automation action is missing a target entity_id:

  - action: media_player.play_media
    metadata: {}
    data:
      media_content_type: custom
      media_content_id: move music to {{ states('sensor.galaxy_s24_ultra_ble') }} echo

image

danielbrunt57 commented 2 days ago

Another issue, your quotes are wrong:

{{ state_translated(‘media_player.office_echo’) == ‘Playing’ }} should be: {{ state_translated('media_player.office_echo') == 'Playing' }}