Issue calling media_player.play_media from a script

In developer tools I call media_player.play_media with this JSON and it turns on my media player:

{
  "entity_id": "media_player.office",
  "media_content_type":"radio",
  "media_content_id":"BBC Radio 6 Music"
}

However, I’ve set up a script to do the same:

good_morning:
  sequence:
    - service: media_player.play_media
      data:
        entity_id: media_player.office
        media_content_type: radio, 
        media_content_id: BBC Radio 6 Music
    - service: switch.turn_on
      data: 
        entity_id: switch.lampy
    - service: notify.notify
      data:
        message: Good morning!

I receive the notification and the lamp switches on, but there nothing happens with the media player. There are also no errors in the log (and in Logbook it just says that the script was called and the lamp was turned on).

Apologies if I’m missing something obvious here… but does anyone have any ideas?

Thanks in advance.

Edit: I’m not sure if it’s relevant (especially as the other bits are working) but I’m just calling the script from an entity button in Lovelace:

- type: entity-button
  name: Good morning
  icon: mdi:weather-sunny
  icon_height: 56
  entity: script.good_morning
  tap_action:
    action: call-service
    service: script.good_morning

remove “,” (comma) that’s for sure

also please attach logs…

Hi @radinsky, thanks for your feedback.

Oops sorry I must have copied/pasted that in when I was just messing around

2019-09-02 15:44:20 WARNING (MainThread) [homeassistant.loader] You are using a custom integration for roon which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you do experience issues with Home Assistant.
2019-09-02 15:44:30 ERROR (SyncWorker_16) [homeassistant.components.uvc.camera] NVR refuses to talk to me: Failed to contact NVR
2019-09-02 15:44:30 WARNING (MainThread) [homeassistant.components.camera] Platform uvc not ready yet. Retrying in 30 seconds.

This is all that is in my logs after I restart. The UVC relate to some cameras that I haven’t finished setting up yet.

The warning about Roon is because it’s not in the official repo yet, I think.

I’m not sure if it makes any difference but it’s roon-hass that I’m using - it exposes your Roon endpoints as media players. I’m not sure if this means that it should function any differently to a “normal” media player but, either way, it’s working as it should be in the developer tools so I’m a bit stuck :slight_smile:

try adding to your logger:
homeassistant.components.media_player: debug
restart
and then retry and check you log.

After much trial and error I’ve solved it - I had to wrap the radio station name in double quotes.

But that’s a great tip for debugging, I’ll add that to my notes.

Thanks, @radinsky , for your help.

1 Like