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

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.

If running Plex or HA in Docker, you’ll need to run in “host” networking mode for the local network client discovery to work.

Remember you may need to trigger the button.scan_clients entity a short time after launching the Plex app.

It’s running in host mode and I have tried the button.scan_clients. It’s strange that it briefly worked, and overnight, it became broken again.

I see that the next update of Plex Media Server contains a fix for:

(Player) Controlling a player didn’t work in some cases (#14567)

I hope that relates to the Apple TV. Will report back once the update is available for everyone.

I really appreciate all your help! Thanks a lot!

I’m having the same issues as you. Please report back if you find any fixes!!

Hello,

I have na issue where when I does launch plex app, the play button I’ve coded does not work at all(grayed out)

However if I manually start a movie with my roku remote, then everything works fine in home assistant.

Could this be related to that scan button that people are talking about in the comments?

I’m using a roku not Apple, but I feel like it may be a related issue?

Launching a Plex client app unfortunately does not notify the integration that it’s available to use. You’ll need to either trigger a scan for clients (using the button entity) or wait for the next scheduled scan, which can be several minutes. Starting playback on the device directly will notify the integration about the new client, but that usually defeats the purpose of having an automation.

Thanks for the reply. I think this helps me.

So I have and input field. Where I type in any move and click the play button. It immediately launches the title on any of my my 6 Roku decices(depending on which tv I have selected of course)

Works perfect except for when I first launch the app.

Few minutes in or after something is playing I can play 100 movies in a row with ten text search field
And it works perfect.

So In my case I think it makes perfect sense to initiate that scan upon app launch. Am I explaining this correctly? Would you agree? And is that scan command In the comments above what I should add to the launch script?

Probably. Power on the device, launch the Plex app, sleep for a couple seconds to allow the Plex app to become active enough to respond to scan requests, trigger the scan via button entity, wait for media_player entity to become active.

To be clear - there are multiple threads where people ARE doing the scan and this functionality is still broken.

Even if I actively play some content on Plex, then try to control it - I am unable to do anything with it. Yes, the Plex app is configured for control, I’ve checked every setting I could possibly find diving into the forums here.

I am having the same issues…

The Apple TV starts PLEX as a source without issues and in the PLEX integration in HA the player shows unavailable UNTIL I actively play something. Then in HA it shows up as playing and has the details of what is playing. Even in HA if I try and go into the active player and PLAY the media FROM HA via that integration, ignore the service calls stuff, it still doesn’t work. I think the problem is either on the PLEX side or the HA integration side.

I’ve based my automation and testing on threads like this and previous threads from years ago so I know it has worked but something changed that isn’t working.

For the FOLKS who are working and have worked for years like this I’d love to see what you are doing and if it is actively working now.

Here is what I am seeing in the logs when trying to play something via Plex but the client is online and actively playing something:

2023-12-19 11:35:56.275 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [139872660546496] 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 238, in handle_call_service
    response = await hass.services.async_call(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2067, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2104, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 272, in handle_service
    return await service.entity_service_call(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 878, in entity_service_call
    single_response = 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)

Same issue as everyone here.

However I believe this to be a Plex issue for BOTH iOS and tvOS.

The only way I can get both clients to work briefly is to:

  • sign out
  • force close app
  • open app and skip login
  • settings → advertise as player on
  • close app
  • open sign in and make sure setting is on again while signed in.

Doing the above will allow both clients to be controlled. However as soon as you close the app or after some x amount of time, it reverts back again and doesn’t work anymore.

Compared to using Plex htpc on the same network, same subnet. No issues.