Unable to trigger media_player.play_media for a Plex client on Apple TV

I’m trying to create a script that will play a random episode of a specific show on the Plex client on my Apple TV.

I’ve tried every example from Plex Media Server - Home Assistant (after modifying values specific to my server) with no luck. Here’s one example:

service: media_player.play_media
data:
  media_content_type: EPISODE
  media_content_id: '{ "library_name": "TV Shows", "show_name": "30 Rock", "shuffle": 1 }'
target:
  entity_id:
    - media_player.plex_bedroom

Where media_player.plex_bedroom is the “Plex (Plex for Apple TV - Apple TV)” entity. I see the same behavior on another Plex for Apple TV client in my living room.

The same script does work with a Plex for iOS client. Both of the Apple TV clients correctly report in Home Assistant when something is playing on them, they just don’t seem to respond to being controlled.

I’ve also noticed that if something is already playing on those clients, running the script results in an error in Home Assistant that says Failed to call service media_player.play_media. Client is not currently accepting playback controls: Plex (Plex for Apple TV - Apple TV).

Does this service just not work on Apple TV Plex clients, or am I missing something else?

I’ve also just tried the script from Can't play media on Plex after opening with Apple TV source change - #3 by moralsnipe. It seems the Plex for Apple TV client is always Unavailable, even when it’s open and idle.

If I manually play something it will correctly show the status in Home Assistant, but as soon as playback stops it says Unavailable, and even activating the scan client button won’t change it.

Just seen this and (think) I have something. that works. However, was the AppleTV ‘on’ when you ran that script?

edit: just edited this script (with help searching this forum - so thanks to a bunch of people) which works for me:

  appletv_watch_random_30_rock:
    alias: "ATV - watch random 30 Rock"
    sequence:
      - service: media_player.select_source
        data:
          source: Plex
        target:
          entity_id: media_player.appletv
      - delay:
          seconds: 1
      - service: button.press
        target:
          entity_id: button.scan_clients_borg
      - wait_template: "{{ not is_state('media_player.plex_plex_for_apple_tv_apple_tv','unavailable') }}"
        timeout: '45'
      - service: media_player.play_media
        data:
          media_content_type: EPISODE
          media_content_id: >-
            { 
              "library_name" : "TV Shows",
              "show_name": "30 Rock",
              "shuffle": 1,
              "maxresults": 1
            }
          enqueue: replace
        target:
          entity_id: media_player.plex_plex_for_apple_tv_apple_tv
    mode: single

edit: note it has my appletv name, my Plex name (Borg) etc etc, but it assumes the TV is already on.

Has anyone been able to solve this issue?
I want to create a similar automation as @jchh to play a random TV show episode but I’m running into the same problem.

  • Play something on Plex for Apple TV → media_player entity becomes available almost instantly
  • Stop the playback by returning to the Plex homepage → media_player becomes unavailable, doesn’t respond to media_player.play_media calls.

I understand that the Plex entity becomes unavailable when the Apple TV is off or when Plex isn’t running. But I’m having this issue when the Apple TV is on, and Plex is on the homepage.

My setup:

  • Apple TV and Plex server are on the same network (UniFi)
  • No firewall restrictions within that network (only between IoT VLAN and main LAN)
  • In Plex:
    • Enabled “local network discovery (GDM)”
    • Added my Home Assistant instance IP address to “List of IP addresses and networks that are allowed without auth”
  • I tried connecting Plex to Home Assistant manually and via Plex.tv token. Both yield the same results.

I already tried:

  • Rebooting Apple TV
  • Updating & restarting Plex Media Server
  • Enabled debug logging. Can’t spot anything obvious…

Unsure how to solve this. Seems like this should just work.
Any help would greatly be appreciated!

Does triggering the button.scan_clients entity have an effect for you? The Plex integration doesn’t get immediately notified when a new client is available on the network, so it scans periodically. You can trigger that entity to force a scan, which is useful in automations after you power on a device & start the Plex app (perhaps after a short delay).

No, button.scan_clients doesn’t do anything for me.

The Apple TV is already there, it just stays unavailable when Plex is sitting on the home page. I’ve kept it in this state for 10 minutes, and the entity doesn’t come available.

However, when I play a movie on Plex, Home Assistant updates the entity almost instantly.

button.scan_clients will only work when your AppltTV and Plex are not unknown

Try turning on the appleTV (using a remote), selecting Plex and then play anything. Once Plex is playing, press button.scan_clients.

Thanks for the suggestion.

Unfortunately, nothing happens when I do that.

  • Turn on Apple TV, launch Plex (entity stays unavailable)
  • Launch a movie on Plex. Entity goes to “playing” almost instantly.
  • Press button.scan_clients → nothing seems to happen. The device & entity was already there.
  • Stopped the movie, return to Plex home page → entity becomes unavailable.

It’s really strange. There’s obviously some connection between the two, as Home Assistant will see the status of a movie when it’s playing.

sorry, I may have misunderstood. Do you mean the entity that something like media_player.plex_plex_for_apple_tv_apple_tv? It’s is always unavailable and doesn’t effect the script I am using above. What does effect it is remote.appletv media_player.appletv which must not be off or unavailable.

My dash therefore looks like this:

- type: conditional
  conditions:
    - condition: state
      entity: remote.appletv
      state: "off"
  card:
    type: vertical-stack
    title: Apple TV
    cards:
      - type: button
        icon: mdi:television-box
        show_icon: false
        name: "turn on"
        tap_action:
          action: call-service
          service: remote.turn_on
          service_data:
            entity_id: remote.appletv

- type: conditional
  conditions:
    - condition: state
      entity: media_player.appletv
      state_not: unavailable
    - condition: state
      entity: media_player.appletv
      state_not: "off"
  card:
    type: vertical-stack
    cards:
      <control buttons here>

It takes ~9 secs from pushing the ‘turn on’ button to media_player.appletv becoming idle.

A Plex client does not need to be playing anything for the scan to work.

Have you confirmed the Plex AppleTV app is advertising itself as a player? This setting must be enabled to control it remotely. Otherwise it will only report actively playing media and will become unavailable when idle.

1 Like

agh, OK, that must have just been a coincidence for me then :+1:

Yes, the entity media_player.plex_plex_for_apple_tv_apple_tv is always unavailable, unless I’m playing a movie.

Here’s the script that I’m using to test things:

alias: Test Plex
sequence:
  - service: media_player.turn_on
    data: {}
    target:
      entity_id: media_player.appletv_living
  - service: media_player.select_source
    data:
      source: Plex
    target:
      entity_id: media_player.appletv_living
  - delay:
      hours: 0
      minutes: 0
      seconds: 3
      milliseconds: 0
  - service: button.press
    data: {}
    target:
      entity_id: button.scan_clients_xd_media
  - wait_template: >-
      {{ not
      is_state('media_player.plex_plex_for_apple_tv_apple_tv','unavailable') }}
    continue_on_timeout: true
    timeout: "45"
  - service: media_player.play_media
    data:
      media_content_type: EPISODE
      media_content_id: >-
        { "library_nample e" : "TV shows", "show_name": "Bing", "shuffle": "1",
        "maxresults": 1 }
      enqueue: replace
    target:
      entity_id: media_player.plex_plex_for_apple_tv_apple_tv
mode: single

It works perfectly, until it gets to the wait_template. This just times out, as Plex is sitting on the home screen, but the entity remains unavailable.

If I manually trigger the last step, I get a new error message:

websocket_api script: Error executing script. Error for call_service at pos 1: Client is not currently accepting playback controls: Plex (Plex for Apple TV - Apple TV)

In the frontend I don’t see any controls on the Plex media_player either. Very strange!

It’s a vicious circle. Becuase media_player.plex_plex_for_apple_tv_apple_tv is always unavailable, it will always time-out.

I removed that part and split the 2 elements - “Apple TV on” and “do something” - (per my dash above) such that until the AppleTV is not off you cannot press any of the buttons that will timeout. Once the appleTV is idle there is not need to have that wait/timout section (so I removed it), and the command works immediately.

hope that makes sense.

Here is one to watch a random episode of “30 Rock”

- service: media_player.select_source
  data:
    source: "Plex"
  target:
    entity_id: media_player.appletv
- delay:
    seconds: 1
- service: media_player.play_media
  data:
    media_content_type: EPISODE
    media_content_id: >-
      { 
        "library_name" : "TV Shows",
        "show_name": "30 Rock",
        "shuffle": 1,
        "maxresults": 1
      }
    enqueue: replace
  target:
    entity_id: media_player.plex_plex_for_apple_tv_apple_tv

Note the 2 media_players appletv & plex_plex_for_apple_tv_apple_tv which are physically the same player.

That definitely explains why it times out, thanks! Removed it now.

I should have been more clear in my previous message. After the wait_template I have this step, which doesn’t work.

service: media_player.play_media
data:
  media_content_type: EPISODE
  media_content_id: >-
    { 
      "library_name" : "TV shows",
      "show_name": "Bing",
      "shuffle": 1,
      "maxresults": 1
    }
  enqueue: replace
target:
  entity_id: media_player.plex_plex_for_apple_tv_apple_tv

Plex doesn’t do anything. Just sits on the home page.

I do get this error in the logs:

[139662584965696] Client is not currently accepting playback controls: Plex (Plex for Apple TV - Apple TV)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 230, in handle_call_service
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 2035, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2072, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/script/__init__.py", line 605, in _service_handler
    response = await self._async_start_run(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/script/__init__.py", line 563, in _async_start_run
    script_result = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/script/__init__.py", line 594, in _async_run
    return await self.script.async_run(script_vars, context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1578, in async_run
    return await asyncio.shield(run.async_run())
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 420, in async_run
    await self._async_step(log_exceptions=False)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 470, in _async_step
    self._handle_exception(
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 493, in _handle_exception
    raise exception
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 468, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 704, in _async_call_service_step
    response_data = await self._async_run_long_action(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 666, in _async_run_long_action
    return long_task.result()
           ^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2035, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2072, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 235, in handle_service
    return await service.entity_service_call(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 876, in entity_service_call
    response_data = await _handle_entity_call(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 948, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/media_player/__init__.py", line 799, in async_play_media
    await self.hass.async_add_executor_job(
  File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/plex/media_player.py", line 487, in play_media
    raise HomeAssistantError(
homeassistant.exceptions.HomeAssistantError: Client is not currently accepting playback controls: Plex (Plex for Apple TV - Apple TV)

No idea why it will not accept playback controls. No firewall in place, both are on the same network/VLAN.

I tried setting up the Plex integration locally (via IP address) and via plex.tv. Both yield the same result.

I’m running the latest version of HA and tvOS.

What is the status of media_player.appletv?
Can you share the attributes here?
It needs to have a status that isn’t off (and therefore have) an attribute called source_list showing something like:

source_list: Absolute Radio, App Store, Arcade, BBC iPlayer, BitGym, Channel 4, Computers, DayView, Fitness, HDHomeRun, HomeCam, Infuse, ITVX, Movies, Music, My5, Netflix, News Explorer, Photos, Plex, Podcasts, Prime Video, Search, Settings, Speedtest, TV, TV Shows, Yoga Studio, YouTube

These are all the sources it accepts using the select_source service:

- service: media_player.select_source
  data:
    source: "Plex"
  target:
    entity_id: media_player.appletv

Currently, the Apple TV is in “standby” with the following attributes:

source_list: App Store, Arcade, Computers, F1 TV, FaceTime, Films, Foto's, Instellingen, Muziek, Netflix, Plex, Podcasts, Proximus Pickx, Spotify, Telenet TV, TestFlight, TV, VRT MAX, VTM GO, YouTube, Zoek
app_id: 
friendly_name: Woonkamer
supported_features: 450487

I don’t think the Apple TV is to blame. It correctly launches the Plex app when the select_source service is called.

The problem is that the Plex app fails to relay its “readiness” to Home Assistant and refuses to accept media controls (as per my previous message).

Very strange…

Right, but I was just checking that appletv was not ‘off`’ because it certainly won’t work otherwise.

Sorry, I’m out of ideas. It works for me, so something else is going on.

I asked this before. Can you confirm this feature is enabled in the AppleTV Plex app settings?

1 Like

OMG, that was it! Sort of…

I remember turning this setting ON, but it was OFF when checked it again. Turns out, this is some weird issue with the Plex app for Apple TV.

Found these instructions on the Plex forum:

  1. Close session in Plex on AppleTV.
  2. Force close Plex on AppleTV.
  3. Open Plex on AppleTV.
  4. Skip login/register.
  5. Activate “Announce as player”.
  6. Login again and check “Announce as Player” is active.

That did the trick! The setting is now permanently enabled, and @jchh 's automation now works beautifully.

Thanks everyone!

1 Like

Spoke too soon. It worked for half a day, now I can’t control the media_player again. Only shows the current status, with the “advertise as player” option turned on.

I’m currently running Plex on my Unraid server through Docker. I’m not using the official image. Switching to that one to see if it’s the Plex server or the Plex client.