Random Alexa Song from amazon_music not working

Seeing the weather is too hot and i’m waiting for it to rain soon, i thought this would be an appropriate automation:

- id: '1658135979353'
  alias: It has rained! Praise the gods..
  description: Play riders on the storm or have you ever seen the rain if no rain
    for 5 days
  trigger:
  - platform: state
    entity_id:
    - input_boolean.raining
    to: 'on'
  condition:
  - condition: and
    conditions:
    - condition: template
      value_template: int - (now() -  states( 'input_boolean.raining.last_changed')  |
        as_datetime | as_local ).days > 5 }}
  action:
  - service: notify.alexa_media_everywhere
    data:
      message: test
  mode: single

I thought this might work:

service: media_player.play_media
data:
  media_content_id:  "riders on the storm", "play have you ever seen the rain" | random
  media_content_type: AMAZON_MUSIC
target:
  entity_id: media_player.everywhere

But it doesn’t like it :frowning:

You haven’t set up your templates properly…

- id: '1658135979353'
  alias: It has rained! Praise the gods..
  description: Play riders on the storm or have you ever seen the rain if no rain
    for 5 days
  trigger:
  - platform: state
    entity_id:
      - input_boolean.raining
    to: 'on'
  condition:
    - condition: template
      value_template: >
        {{ ( now() - states.input_boolean.raining.last_changed ) 
        > timedelta(hours=5) }}
  action:
    - service: notify.alexa_media_everywhere
      data:
        message: test
        data:
          type: announce
  mode: single
service: media_player.play_media
data:
  media_content_id:  >
    {{ [ "riders on the storm", "have you ever seen the rain"] | random}}
  media_content_type: AMAZON_MUSIC
target:
  entity_id: media_player.everywhere

@Didgeridrew Thank you very much. I need to learn a bit more about value_templates i see, or maybe yaml in general. It’s weird though, that even though the action bit works fine once i test it, but no music starts playing.

Maybe random array of strings are not supported in alexa media player…

Alexa never sees the array, it is rendered before the service call is sent to Alexa. But, it’s been a while since I did anything with speaker groups… apparently I forgot this important “hack”

service: media_player.play_media
data:
  media_content_id: >
    {{ [ "riders on the storm", "have you ever seen the rain"] | random}} in everywhere group
  media_content_type: AMAZON_MUSIC
target:
  entity_id: media_player.AN_ACTUAL_ECHO_DEVICE

Hmm good points, i’ll try and add them, don’t think i had to add them in other automations i had. I’ll check and revert, thanks for your help so far!

PS this worked, i forgot i had to use the ‘hack’ to enable it, e.g. use a entity of a real speaker and then refer to the everywhere group in the string.