Help with previously working Plex automation (shuffle play a collection)

I used to have this working, but I neglected my Homeassistant setup for a while.

The old (pretty sure untouched) version that used to work and no longer does:

alias: Shuffle Trek
sequence:
  - if:
      - condition: not
        conditions:
          - condition: state
            entity_id: media_player.bedroom_roku
            state: Plex - Free Movies & TV
            attribute: source
    then:
      - service: google_assistant_sdk.send_text_command
        data:
          command: open plex on bedroom roku
    enabled: true
    else: []
  - delay:
      hours: 0
      minutes: 0
      seconds: 5
      milliseconds: 0
  - service: media_player.play_media
    target:
      device_id: [redacted]
      entity_id: media_player.bedroom_roku
    data:
      media_content_id: plex://[redacted]/47962?shuffle=1
      media_content_type: playlist
  - service: media_player.play_media
    target:
      entity_id: media_player.bedroom_robot
    data:
      media_content_id: media-source://media_source/local/moopsy.mp3
      media_content_type: audio/mpeg
    metadata:
      title: moopsy.mp3
      thumbnail: null
      media_class: music
      children_media_class: null
      navigateIds:
        - {}
        - media_content_type: app
          media_content_id: media-source://media_source
    enabled: false
mode: single
icon: mdi:television

I’ve tried starting from scratch in the visual editor on a new version, dropping the state if/then and dropping the audio file for the sake of simplicity, came up with this but it still doesn’t work. Any ideas?

service: media_player.play_media
target:
  entity_id: media_player.plex_plex_for_roku_bedroom_roku
data:
  media_content_id: plex://[redacted]/47962
  media_content_type: playlist
metadata:
  title: Star Trek Television Collection
  thumbnail: /api/plex_image_proxy/[redacted]/47962
  media_class: playlist
  children_media_class: episode
  navigateIds:
    - {}
    - media_content_type: playlists
      media_content_id: plex://[redacted]/all
    - media_content_type: playlist
      media_content_id: plex://[redacted]/47962

Hi, welcome to the forum!

I’m not using Plex but have you looked at home-assistant.io → integrations → plex to see if something has changed compared to your config?
You could also go back, starting from the release you were running till now and check the release notes / breaking changes to see what had changed.

Or, if you don’t want to solve it yourself, wait for someone else to do it for you.

Hi,

Thanks for the reply.

Yes, I’m familiar with that page and have been using it to try and piece together why my old one isn’t working and/or to make a new one.

I attempted to make a simple variation that just plays the movie Star Trek (as opposed to the shuffle of a playlist I’m trying to do in the OP) but still no dice.

action: media_player.play_media
target:
  entity_id: media_player.bedroom_roku
data:
  media_content_id: "{"library_name": "Movies", "title": "Star Trek"}"
  media_content_type: movie

It’s odd because I can interact and manipulate media being played on the plex player from my dashboard, I just can’t get the scripts to communicate to it. :frowning:

Have you tried to run the script manually and did you check the traces?

Yes, while testing I’ve only been running it manually. Checked the trace and I don’t see any obvious errors. When running in homeassistant, I see a notification of “script triggered successfully” but nothing actually happens on the player.

{
  "trace": {
    "last_step": "sequence/0",
    "run_id": "42b7c68039c09d532ab6da9a35fb807c",
    "state": "stopped",
    "script_execution": "finished",
    "timestamp": {
      "start": "2024-08-11T09:24:31.388592+00:00",
      "finish": "2024-08-11T09:24:31.389428+00:00"
    },
    "domain": "script",
    "item_id": "shuffle_trek_new_duplicate",
    "trace": {
      "sequence/0": [
        {
          "path": "sequence/0",
          "timestamp": "2024-08-11T09:24:31.388851+00:00",
          "changed_variables": {
            "this": {
              "entity_id": "script.shuffle_trek_new_duplicate",
              "state": "off",
              "attributes": {
                "last_triggered": "2024-08-11T09:13:47.027597+00:00",
                "mode": "single",
                "current": 0,
                "icon": "mdi:television",
                "friendly_name": "Shuffle Trek New (Duplicate)"
              },
              "last_changed": "2024-08-11T09:24:00.405521+00:00",
              "last_reported": "2024-08-11T09:24:00.405521+00:00",
              "last_updated": "2024-08-11T09:24:00.405521+00:00",
              "context": {
                "id": "[redacted]",
                "parent_id": null,
                "user_id": null
              }
            },
            "context": {
              "id": "[redacted]",
              "parent_id": null,
              "user_id": "[redacted]"
            }
          },
          "result": {
            "params": {
              "domain": "media_player",
              "service": "play_media",
              "service_data": {
                "media_content_id": "\"{\"library_name\": \"Films\", \"title\": \"Star Trek\"}\" ",
                "enqueue": "replace",
                "media_content_type": "movie",
                "entity_id": [
                  "media_player.plex_plex_for_roku_bedroom_roku"
                ]
              },
              "target": {
                "entity_id": [
                  "media_player.plex_plex_for_roku_bedroom_roku"
                ]
              }
            },
            "running_script": false
          }
        }
      ]
    },
    "config": {
      "alias": "Shuffle Trek New (Duplicate)",
      "sequence": [
        {
          "data": {
            "media_content_id": "\"{\"library_name\": \"Films\", \"title\": \"Star Trek\"}\" ",
            "enqueue": "replace",
            "media_content_type": "movie"
          },
          "enabled": true,
          "target": {
            "entity_id": [
              "media_player.plex_plex_for_roku_bedroom_roku"
            ]
          },
          "action": "media_player.play_media"
        }
      ],
      "mode": "single",
      "icon": "mdi:television",
      "description": ""
    },
    "blueprint_inputs": null,
    "context": {
      "id": "[redacted]",
      "parent_id": null,
      "user_id": "[redacted]"
    }
  },
  "logbookEntries": [
    {
      "when": 1723368271.388727,
      "state": "on",
      "entity_id": "script.shuffle_trek_new_duplicate",
      "icon": "mdi:television",
      "context_user_id": "[redacted]"
    },
    {
      "when": 1723368271.3893383,
      "state": "off",
      "entity_id": "script.shuffle_trek_new_duplicate",
      "icon": "mdi:television",
      "context_user_id": "[redacted]",
      "context_state": "on",
      "context_entity_id": "script.shuffle_trek_new_duplicate"
    }
  ]
}

Have you checked the HA log?
Do other actions with your mediaplayer work?

Nothing in the logs related to this other than “Type MOVIE is not supported” which was just a test case I was trying out.

Unfortunately, I don’t know when it stopped working, so I’m not sure which version broke it.

What about this?

I can manipulate media when something is playing, but it looks like when something is not playing it says client is not accepting playback controls. (This was not the behavior previously!)

Some googling yields this, which seems to match in both behavior and timeline.

Particularly this comment:

Sadly no updates on that in several months. Seems one person found a workaround, but I’m not sure I follow their method.

workaround is adding an if else condition if the player is unavailable after plex launched then reloading the plex intervention via script shows it as active

I guess he means reloading the integration.
If you go to ‘Devices & services’ in your settings, I think you can reload the Plex integration, no?

I don’t think reloading it is the key, as I’ve done that many times. Even nuked the integration and readded it a couple of times.

Not sure why the comment would suggest digging in to core.config_entries for the entry_id if it was just reloading the integration.

Ok, was just an idea.
Trying to help.

You’re right

Have you seen that the first entry in that GH thread is from '23 with HA 2023.7.1
Is there nothing else in there which can give you a better understanding of your problem?

You’re good; I appreciate the help.

Unfortunately, nothing that screams out at me.

I’m not keep on such a significant version rollback, tbh.

But since several comments in there seem to confirm that this is broken, at least I know I’m not going insane.

Going off that workaround comment of if player = unavailable might be promising, unfortunately, that state isn’t an option that I’ve seen in any of the conditionals I’ve tried to make so far. Perhaps I’ll try to just skip the conditional and always reload the entry id when running this script and see what happens.