Problems calling service (media player) in automation

I have a problem calling the service “media_player.play_media” in an automation. I always get that error message if I choose to run the automation

running the the service call with the exact same settings from developer tools works fine.

Here are the logs for running the media player from automation

somehow ite player is turned off

here the logs from running from developer tools

I dont know what I am missing here? Anyy suggestions? Is this a bug?

Please post the automation and its debug trace.

Community Guidlines: Asking a Good Question #9

here is the code

alias: Alarm Sirene Test
description: ""
trigger:
  - platform: state
    entity_id:
      - alarm_control_panel.alarmo
    to: triggered
condition: []
action:
  - repeat:
      until:
        - condition: state
          entity_id: alarm_control_panel.alarmo
          state: disarmed
      sequence:
        - service: media_player.volume_set
          data:
            volume_level: 1
          target:
            entity_id: media_player.the_van
        - service: media_player.play_media
          target:
            entity_id: media_player.the_van
          data:
            media_content_id: >-
              https://xxxxxxxxxxxxxxxxxxxx.ui.nabu.casa/local/alarm.mp3
            media_content_type: music
          alias: Play Alarm
mode: single

by debug traces do you mean this?

Edit: sometimes it seems to work, sometimes it plays only distorted sound and the set_volume command is ignored always

Yes (although the full json is more useful than screenshots).

You probably need to include delay(s) in your repeat loop, otherwise you will be calling the service on-top of itself. Start with a delay at least as long as your mp3’s length, then you can experiment with shortening the delay.

You can also use an If/then so the volume change is only performed on the first loop, which might help too.

alias: Alarm Sirene Test
description: ""
trigger:
  - platform: state
    entity_id:
      - alarm_control_panel.alarmo
    to: triggered
condition: []
action:
  - repeat:
      until:
        - condition: state
          entity_id: alarm_control_panel.alarmo
          state: disarmed
      sequence:
        - if: 
            - condition: template
              value_template: "{{ repeat.first }}"
          then:
            - service: media_player.volume_set
              data:
                volume_level: 1
              target:
                entity_id: media_player.the_van
            - delay:
                milliseconds: 500
        - service: media_player.play_media
          target:
            entity_id: media_player.the_van
          data:
            media_content_id: >-
              https://xxxxxxxxxxxxxxxxxxxx.ui.nabu.casa/local/alarm.mp3
            media_content_type: music
          alias: Play Alarm
        - delay: 3
mode: single