usernein / tv-card

📺 TV Remote Card (with touchpad and haptic feedback)
Apache License 2.0
109 stars 28 forks source link

Failed to call service media_player/play_media. URL is relative, but does not start with a / #29

Open Wh1t3Rose opened 1 year ago

Wh1t3Rose commented 1 year ago

Checklist:

Release with the issue: Latest Last working release (if known): N/A Browser and Operating System: Brave Version 1.48.158 Chromium: 110.0.5481.77 Windows 11 Version 22H2 (22621.1105)

Description of problem: When pressing any of the buttons on the remote I get error: Failed to call service media_player/play_media. URL is relative, but does not start with a /

Javascript errors shown in the web inspector (if applicable):

Uncaught (in promise) 
{code: 'unknown_error', message: 'URL is relative, but does not start with a /'}](styles.ts:372 Uncaught (in promise) {code: 'unknown_error', message: 'URL is relative, but does not start with a /'})

Additional information:

Card Configuration:

type: custom:tv-card
entity: media_player.shield
title: Example 1
power_row:
  - power
source_row:
  - return
  - home
  - source
  - netflix
apps_row:
  - youtube
  - spotify
  - netflix
navigation_row: touchpad
volume_row: slider
channel_row:
  - channel_up
  - channel_down
  - info
media_control_row:
  - rewind
  - play
  - spotify
  - pause
  - fast_forward
davidn commented 1 year ago

Also seeing this. I'm trying to use the remote with a chromecast. Server-side log:

Logger: homeassistant.components.websocket_api.http.connection
Source: components/media_player/browse_media.py:47
Integration: Home Assistant WebSocket API ([documentation](https://www.home-assistant.io/integrations/websocket_api), [issues](https://github.com/home-assistant/home-assistant/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+websocket_api%22))
First occurred: 11:22:16 AM (7 occurrences)
Last logged: 11:55:57 AM

    [139689813687648] URL is relative, but does not start with a /
    [139689551147696] URL is relative, but does not start with a /
    [139689551137232] URL is relative, but does not start with a /

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 200, in handle_call_service
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1787, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1824, in _execute_service
    await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)(
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 213, in handle_service
    await service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 680, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 968, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 720, in _handle_entity_call
    await result
  File "/usr/src/homeassistant/homeassistant/components/cast/media_player.py", line 693, in async_play_media
    media_id = async_process_play_media_url(self.hass, media_id)
  File "/usr/src/homeassistant/homeassistant/components/media_player/browse_media.py", line 47, in async_process_play_media_url
    raise ValueError("URL is relative, but does not start with a /")
ValueError: URL is relative, but does not start with a /
davidn commented 1 year ago

As noted in the README:

This card uses media_player.play_media to send keys to the TV. This is the way ollo69's SamsungTV Smart Component (which i based this card on) works, but don't worry: if your TV is from another brand or simply the TV integration does not use media_player.play_media for sending keys, you can still use this card by setting custom buttons with services to send keys to your TV (or do whatever you want) in your way (just like the original tv-card).

I believe this error is happening for TVs that don't use media_player.play_media for sending keys. It works for me if I set custom buttons as this paragraph suggests. E.g.

type: custom:tv-card
entity: media_player.basement_tv
title: Basement TV
custom_keys:
  power_on:
    icon: mdi:power-on
    service: media_player.turn_on
    service_data:
      entity_id: media_player.basement_tv
  power_off:
    icon: mdi:power-off
    service: media_player.turn_off
    service_data:
      entity_id: media_player.basement_tv
  play:
    icon: mdi:play
    service: media_player.media_play
    service_data:
      entity_id: media_player.basement_tv
  pause:
    icon: mdi:pause
    service: media_player.media_pause
    service_data:
      entity_id: media_player.basement_tv
  volume_up:
    icon: mdi:volume-plus
    service: media_player.volume_up
    service_data:
      entity_id: media_player.basement_tv
  volume_down:
    icon: mdi:volume-minus
    service: media_player.volume_down
    service_data:
      entity_id: media_player.basement_tv
  volume_mute:
    icon: mdi:volume-mute
    service: media_player.volume_mute
    service_data:
      entity_id: media_player.basement_tv
      is_volume_muted: true
power_row:
  - power_on
  - power_off
volume_row: buttons
media_control_row:
  - play
  - pause
xlyralycanx commented 1 year ago

To the other commenters: Unfortunately it is an error with the script, inside includes "('media_player','play_media')" which translates with a '/' instead of a '.' - Instead I recommend doing as @davidn did, using custom_keys with the following template:

"- custom_keys: play_pause: icon: mdi:play_pause service: media_player.media_play_pause service_data: entity_id: media_player.tv_speaker"