Home Assistant

Random playlist on grouped speakers at one volume

A script picks one item from a list, joins extra speakers to a main player when the platform allows it, sets one volume, and plays with the shuffle and repeat you chose.

Difficulty · BeginnerSetup · 20–40 minutesHA · 2024.10 or newer
Get the pack · from $19Have us set it up

A morning routine that always plays the same playlist gets skipped. This pack is a script that keeps a list of content ids, picks one at random, and plays it on a main speaker. Extra players are asked to join that speaker first. Volume is set on every player in the group. Shuffle and repeat are set on the main player. If join, shuffle, or repeat is not supported, that step is skipped and playback still runs.

An automation in the pack calls the script at a clock time, from a button, or both.

A plug that should follow playback, instead of a script that starts it, is speaker plug follows playback. Dropping the volume while a voice satellite is listening is voice satellite media duck. A ramp toward a target volume across the day is restart-proof volume ramp.

What problem it solves

You want one button, or one time, to start a different item from a short list, on more than one speaker, at a volume you picked ahead of time.

How it works

  1. The list. One item per line: content type, a pipe, then the content id. music|media-source://media_source/local/example.mp3 is the placeholder. Blank lines are ignored. A line with no pipe is ignored. The script picks one of the remaining lines with random.
  2. The group. If you selected extra players, the script calls media_player.join on the main player with those extras as group_members. Players that cannot group (or a platform that has no join) fail that step only. Playback continues on the main player. Do not put the main player in the extra list.
  3. Volume. media_player.volume_set runs on the main player plus the extras, at the level you set (0 to 1, default 0.3). This happens even when join failed, so a speaker that did not group still gets the volume.
  4. Shuffle and repeat. Both are set on the main player. Shuffle is a boolean. Repeat is off, all, or one. A player that rejects either call does not stop the script.
  5. Play. media_player.play_media uses the content type and content id from the chosen line, on the main player. This step is not ignored on failure. If the id is wrong, the script stops there and the trace shows it.
  6. The caller. The automation turns that script on. Enable the clock, the button, or both. The clock defaults to 07:00. The button defaults to off, so a missing input_button.morning_music does not start music. The button can be an input button, a button entity, or a binary sensor that turns on for the press.

The script is queued (up to 5). A second press waits, then picks again. It does not pass a different list per call. Edit the script inputs to change the list, the players, or the volume.

Snippet

The list and the join are the inputs that matter first. Volume, shuffle, and repeat are separate inputs.

sequence:
  - variables:
      lines: >-
        {{ raw.split('\n') | map('trim') | select('search', '\\|') | list }}
      pick: "{{ lines | random }}"
  - action: media_player.join
    continue_on_error: true
    target:
      entity_id: !input main_player
    data:
      group_members: !input extra_players
  - action: media_player.play_media
    target:
      entity_id: !input main_player
    data:
      media_content_type: "{{ pick.split('|', 1)[0] | trim }}"
      media_content_id: "{{ pick.split('|', 1)[1] | trim }}"

The pack skips join when the extra list is empty, and it sets volume before play.

Setup outline

  1. Copy blueprints/script/random_media_multiroom.yaml into config/blueprints/script/edotdev/ and blueprints/automation/random_media_morning.yaml into config/blueprints/automation/edotdev/. Reload blueprints.
  2. Create a script from the random media blueprint. Pick the main player. Add extras only if they can join that player. Replace the placeholder line with your own type|id lines.
  3. Set the volume. Leave shuffle off and repeat at off until the first play works.
  4. Run the script from Developer tools → Actions, script.turn_on. You should hear one item. Run it again. You should get a random line (with one line, it will be the same item).
  5. Create the automation. Pick the script. Leave the clock on and set the time, or turn the clock off and enable the button. Press the button or wait for the time. The same script should run.

Troubleshooting

  • Nothing plays. The list has no pipe character, the content id is not one this player accepts, or the player is unavailable. Open the script trace. The play step is the one that should be red. Join and shuffle can be red and still be fine. Those steps are marked to continue.
  • Only the main speaker plays. Join failed or the extras were empty. Some casts and some local players cannot group. The volume action still runs on the extras, so they should show the new level even when they do not play the stream.
  • The volume is 100% or silent. The slider is 0 to 1, not 0 to 100. 0.3 is 30%. A player that uses its own 0–100 scale inside a template is the wrong entity. Use the media_player that accepts volume_level.
  • Shuffle or repeat errors every time. That player does not support the call. Leave them at off and false, or ignore the trace line. Playback does not depend on them.
  • The morning run plays at the wrong hour. The time input is Home Assistant’s local time. A wrong time zone on the server shifts it. The button path does not use the clock.
  • The button plays twice. The binary sensor turns on for press and the automation also sees a second event. Trigger on the input button, or on one state, not on both edges. The script will queue a second pick if you send it twice.
  • Every morning is the same track. The list has one valid line. Add another line. random is per run, not a shuffle of a playlist the player already had loaded. The player’s own shuffle flag is separate, and only applies if that player honors it for the content type you sent.

Credits

Playing a random media id, with join, volume, shuffle, and repeat, is the idea in Play random media script.

Changelog

v1.0 · Nov 1, 2026: First publish.