Files
alexei.dolgolyov 97c1784ad4 feat(client): v0.3.0 server compat — WS subprotocol auth, 429 retry, HTTPS, X-Request-ID
Aligns the integration with the four wire-level changes shipped in
media-server v0.3.0/0.3.1 without breaking back-compat with older
server versions or pre-existing config entries.

- WebSocket auth via Sec-WebSocket-Protocol: media-server.token.<T>
  (preferred by server v0.3.0+). The ?token= query is still sent so
  older servers and unauthenticated mode both keep working — aiohttp
  completes the handshake even when the server doesn't echo the
  subprotocol back.
- 429 Too Many Requests surfaced as MediaServerRateLimitError with
  Retry-After parsed; execute_script() sleeps min(retry_after, 30)
  and retries once before falling through to the caller.
- Optional HTTPS/WSS (CONF_USE_SSL) + optional certificate verification
  toggle (CONF_VERIFY_SSL) wired through the config flow, client, and
  WebSocket. Defaults preserve http+verified behaviour, so existing
  config entries are unchanged.
- X-Request-ID header (uuid4 hex) on every HTTP call so HA-side issues
  can be cross-referenced with the server's access/audit logs. The
  format matches the server's ^[A-Za-z0-9._-]{1,128}\$ allow-list so
  the id is preserved verbatim instead of being replaced server-side.

Bumps manifest version to 0.3.3.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-26 11:37:59 +03:00
..
2026-05-18 13:14:03 +03:00
2026-05-18 13:14:03 +03:00

Remote Media Player - Home Assistant Integration

A Home Assistant custom component that allows you to control a remote PC's media playback as a media player entity.

Features

  • Full media player controls (play, pause, stop, next, previous)
  • Volume control and mute
  • Seek support
  • Displays current track info (title, artist, album, artwork)
  • Script buttons - Execute pre-defined scripts (shutdown, restart, lock, sleep, etc.)
  • Configurable via Home Assistant UI
  • Polling with adjustable interval

Requirements

  • Home Assistant 2024.1.0 or newer
  • A running Media Server on your PC (see Media Server repository)

Installation

  1. Open HACS in Home Assistant
  2. Click the three dots menu > Custom repositories
  3. Add this repository URL and select "Integration"
  4. Search for "Remote Media Player" and install
  5. Restart Home Assistant

Manual Installation

  1. Copy the remote_media_player folder to your Home Assistant config/custom_components/ directory:

    config/
    └── custom_components/
        └── remote_media_player/
            ├── __init__.py
            ├── api_client.py
            ├── button.py
            ├── config_flow.py
            ├── const.py
            ├── manifest.json
            ├── media_player.py
            ├── services.yaml
            ├── strings.json
            └── translations/
                └── en.json
    
  2. Restart Home Assistant

Configuration

  1. Go to Settings > Devices & Services
  2. Click + Add Integration
  3. Search for "Remote Media Player"
  4. Enter the connection details:
    • Host: IP address or hostname of your PC running Media Server
    • Port: Server port (default: 8765)
    • API Token: The authentication token from your server
    • Name: Display name for this media player (optional)
    • Poll Interval: How often to update status (default: 5 seconds)

Finding Your API Token

On the PC running Media Server:

python -m media_server.main --show-token

Or check the config file:

  • Windows: %APPDATA%\media-server\config.yaml
  • Linux/macOS: ~/.config/media-server/config.yaml

Usage

Once configured, the integration creates a media player entity that you can:

Control via UI

  • Use the media player card in Lovelace
  • Control from the entity's detail page

Control via Services

# Play
service: media_player.media_play
target:
  entity_id: media_player.remote_media_player

# Pause
service: media_player.media_pause
target:
  entity_id: media_player.remote_media_player

# Set volume (0.0 - 1.0)
service: media_player.volume_set
target:
  entity_id: media_player.remote_media_player
data:
  volume_level: 0.5

# Mute
service: media_player.volume_mute
target:
  entity_id: media_player.remote_media_player
data:
  is_volume_muted: true

# Next/Previous track
service: media_player.media_next_track
target:
  entity_id: media_player.remote_media_player

# Seek to position (seconds)
service: media_player.media_seek
target:
  entity_id: media_player.remote_media_player
data:
  seek_position: 60

Automations

Example: Pause PC media when leaving home

automation:
  - alias: "Pause PC media when leaving"
    trigger:
      - platform: state
        entity_id: person.your_name
        from: "home"
    action:
      - service: media_player.media_pause
        target:
          entity_id: media_player.remote_media_player

Example: Lower PC volume during quiet hours

automation:
  - alias: "Lower PC volume at night"
    trigger:
      - platform: time
        at: "22:00:00"
    action:
      - service: media_player.volume_set
        target:
          entity_id: media_player.remote_media_player
        data:
          volume_level: 0.3

Script Buttons

The integration automatically creates button entities for each script defined on your Media Server. These buttons allow you to:

  • Lock/unlock the workstation
  • Shutdown, restart, or put the PC to sleep
  • Hibernate the PC
  • Execute custom commands

Available Buttons

After setup, you'll see button entities like:

  • button.remote_media_player_lock_screen
  • button.remote_media_player_shutdown
  • button.remote_media_player_restart
  • button.remote_media_player_sleep
  • button.remote_media_player_hibernate

Adding Scripts

Scripts are configured on the Media Server in config.yaml:

scripts:
  lock_screen:
    command: "rundll32.exe user32.dll,LockWorkStation"
    label: "Lock Screen"
    description: "Lock the workstation"
    timeout: 5
    shell: true

After adding scripts, restart the Media Server and reload the integration in Home Assistant.

Using Script Buttons

Via UI

Add button entities to your dashboard using a button card or entities card.

Via Automation

automation:
  - alias: "Lock PC when leaving home"
    trigger:
      - platform: state
        entity_id: person.your_name
        from: "home"
    action:
      - service: button.press
        target:
          entity_id: button.remote_media_player_lock_screen

Execute Script Service

Run a pre-defined server script. Use the target: block to scope the call to a specific hub (or area / entity); omit it to fan out to all configured hubs.

# Run on a single hub
service: remote_media_player.execute_script
target:
  device_id: <device id of the hub>
data:
  script_name: "echo_test"
  params:
    message: "hello"

# Run on all hubs (legacy fan-out)
service: remote_media_player.execute_script
data:
  script_name: "shutdown"

Without a target, the service runs on every configured Remote Media Player. For destructive scripts (shutdown, reboot, lock) always pin a target.

Lovelace Card Examples

Basic Media Control Card

type: media-control
entity: media_player.remote_media_player

Mini Media Player (requires custom card)

type: custom:mini-media-player
entity: media_player.remote_media_player
artwork: cover
source: icon

Entities Card

type: entities
entities:
  - entity: media_player.remote_media_player
    type: custom:slider-entity-row
    full_row: true

Entity Attributes

The media player entity exposes these attributes:

Attribute Description
media_title Current track title
media_artist Current artist
media_album_name Current album
media_duration Track duration in seconds
media_position Current position in seconds
volume_level Volume (0.0 - 1.0)
is_volume_muted Mute state
source Media source/player name

Options

After initial setup, you can adjust options:

  1. Go to Settings > Devices & Services
  2. Find "Remote Media Player" and click Configure
  3. Adjust the poll interval as needed

Lower poll intervals = more responsive but more network traffic.

Troubleshooting

Integration not found

  • Restart Home Assistant after installing
  • Check that all files are in the correct location
  • Check Home Assistant logs for errors

Cannot connect to server

  • Verify the server is running: curl http://YOUR_PC_IP:8765/api/health
  • Check firewall settings on the PC
  • Ensure the IP address is correct

Invalid token error

  • Double-check the token matches exactly
  • Regenerate token if needed: python -m media_server.main --generate-config

Entity shows unavailable

  • Check server is running
  • Check network connectivity
  • Review Home Assistant logs for connection errors

Media controls don't work

  • Ensure media is playing on the PC
  • Check server logs for errors
  • Verify the media player supports the requested action

Multiple PCs

You can add multiple Media Server instances:

  1. Run Media Server on each PC (use different tokens)
  2. Add the integration multiple times in Home Assistant
  3. Give each a unique name

Supported Features

Feature Supported
Play Yes
Pause Yes
Stop Yes
Next Track Yes
Previous Track Yes
Volume Set Yes
Volume Mute Yes
Seek Yes
Script Buttons Yes
Browse Media No
Play Media No
Shuffle/Repeat No

License

MIT License