Puzzling script error with media player

Has anyone any clues on how I diagnose the following error? The script appears valid in both the visual editor and YAML and I’ve checked that the correct devices/entities are referenced, and reselected the radio station requested from the HA Radio Browser. The script only seems to run as far as the initial attempt to set the volume.

Thanks.

alias: Radio 4 on soundbar (script)
description: Play on soundbar at 28% volume
sequence:
  - service: media_player.volume_set
    data:
      volume_level: 0.28
    target:
      area_id: living_room
      entity_id: media_player.soundbar_2
  - service: media_player.play_media
    target:
      entity_id: media_player.googlehome4201
    data:
      media_content_id: ""
      media_content_type: ""
    metadata: {}
  - service: media_player.play_media
    target:
      entity_id: media_player.soundbar_2
    data:
      media_content_id: media-source://radio_browser/d470fda1-753b-4037-973f-6f1bd27eb42f
      media_content_type: audio/aac
    metadata:
      title: BBC Radio 4
      thumbnail: https://i.imgur.com/OCqneDN.png
      media_class: music
      children_media_class: null
      navigateIds:
        - {}
        - media_content_type: app
          media_content_id: media-source://radio_browser
        - media_content_type: music
          media_content_id: media-source://radio_browser/country/GB
mode: single
icon: mdi:audio-video

Trace reads:

Play media on Corner

(script.1708445821467) turned off

Stopped because an error was encountered at 21 February 2024 at 12:05:14 (runtime: 0.06 seconds)

string index out of range

Do you mean it stops at this service call, immediately following the volume control, that attempts to play nothing?

  - service: media_player.play_media
    target:
      entity_id: media_player.googlehome4201
    data:
      media_content_id: ""
      media_content_type: ""
    metadata: {}

Either remove that service call or supply it with some content to play.

If that fails to fix the error, post the automation’s entire trace file (click Traces, then click the overflow menu, that’s the three vertical dots, then select Download Trace).

Thanks for your input, Taras. I should have noticed my scripting error - but I definitely remember adding the content to play, so HA must have removed it. It seems that, even with the visual editor, writing a script that works is far from simple, as I’ve now added text to speech there (which plays) again and on the next run got an error at the end of the script. Although I have only one physical device called Soundbar, HA for some reason thinks I have two and I was only able to clear the error by selecting the one with the speaker icon that initially had a diagonal line through it, suggesting it was disabled…

In your previous post (the one you deleted) you had posted the trace file. I could see that the error message was definitely due to what I described in my first post, namely it’s the media_player.play_media service call with no content (i.e. empty media_content_id and media_content_type).

The solution is what I had suggested, either remove the service call or supply it with content.

I can’t comment on how or why there’s no content, just the fact that its absence is the source of the error message.

I would need to see the trace file for that run.

Do media_player.soundbar and media_player.soundbar_2 use the same integration? Which one?

Are they part of the same device (in the Devices list) or separate ones?

1 Like

Thanks for replying again. I now have the script working but haven’t got to the bottom of the issue with the two devices. One shows as Google Cast and the other as DNLA Media Renderer, and I’m still unclear on which one works because neither of the icons that appear in the devices list is the (working) speaker one that I saw in the scripts visual editor.

The physical device (Bose Soundbar) supports two ways of rendering media, via Google Cast or DLNA.

1 Like