core icon indicating copy to clipboard operation
core copied to clipboard

Jellyfin Duplicate Chromecast Media Players

Open crazystick opened this issue 1 year ago • 14 comments

The problem

Jellyfin creates a new Chromecast device/entity every time you play something using the native Jellyfin app on Android.

This seems to be the same as issue #105000 but since I don't use AppleTV I don't know what Swiftfin is so not sure what the resolution might be.

What version of Home Assistant Core has the issue?

core-2023.11.1

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Container

Integration causing the issue

Jellyfin

Link to integration documentation on our website

No response

Diagnostics information

config_entry-jellyfin-787b9eb6dd7dfe73d109348717be4c1b.json.txt

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

crazystick avatar Jan 18 '24 07:01 crazystick

Hey there @j-stienstra, @ctalkington, mind taking a look at this issue as it has been labeled with an integration (jellyfin) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of jellyfin can trigger bot actions by commenting:

  • @home-assistant close Closes the issue.
  • @home-assistant rename Awesome new title Renames the issue.
  • @home-assistant reopen Reopen the issue.
  • @home-assistant unassign jellyfin Removes the current integration label and assignees on the issue, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


jellyfin documentation jellyfin source (message by IssueLinks)

home-assistant[bot] avatar Jan 18 '24 13:01 home-assistant[bot]

@crazystick On your Jellyfin server do you have DLNA "Play To" enabled?

  1. Login as an admin user
  2. Open the hamburger menu
  3. Under Administration click Dashboard
  4. Under Devices click DLNA

It's the top checkbox under "Settings". I have a misbehaving Toshiba TV which was showing up as 200 separate DLNA cast targets. Turning that off has stopped it from happening, with the downside I can't use the DLNA Cast feature.

tim-hitchins-ekkosense avatar Feb 21 '24 18:02 tim-hitchins-ekkosense

@tim-hitchins-ekkosense I tried your suggestion but it doesn't seem to have improved matters. I removed and readded the integration which got rid of most of the entities, but they are still going up.

crazystick avatar Mar 19 '24 20:03 crazystick

the common issue is that devices are created based on the reporting that the session device supports persistent identifier. The client applications report this to the server but they usually use some method on the client device as the identifier and its expected to be persistent.

However, client devices can regenerate identifier to improve privacy that can cause the identifier to be less persistent than thought. Think of it like resetting Google advertising IDs on Android devices.

ctalkington avatar Mar 30 '24 20:03 ctalkington

for chromecast, it's deriving deviceId by base64 the name of receiver or first sender ID or time. This likely leads to the growing list of devices.

https://github.com/jellyfin/jellyfin-chromecast/blob/66a21d2df36ed7d3d69cfec44ec8e8180d858f34/src/components/jellyfinApi.ts#L33-L49

https://github.com/jellyfin/jellyfin-chromecast/blob/66a21d2df36ed7d3d69cfec44ec8e8180d858f34/src/components/maincontroller.ts#L310

so it's actually not creating persistent identifier and properly reports SupportsPersistentIdentifier: false so you see the media players still because its generating new playback session ids

However, in your diagnostics, most your chromecast seem to report SupportsPersistentIdentifier: true which is intriguing

ctalkington avatar Mar 30 '24 20:03 ctalkington

I'm wondering if we should just ignore sessions where the device_id starts with "chromecast_" as it seems like these are transient sessions and keeping them around as entities wouldn't have any benefit

ctalkington avatar Mar 30 '24 21:03 ctalkington

I don't think this issue is only related to Chromecast devices. also to iPhone apps (Finamp and the regular app) and the LG Smart TV app.

For the record, there is only one actual iPhone and LG Smart TV device.

Entities (x watching sensor I kept out of the screenshot): Scherm­afbeelding 2024-05-20 om 15 32 32 Devices: Scherm­afbeelding 2024-05-20 om 15 33 32

In the past, I've deleted these duplicate media_player entities several times but they are coming back

golles avatar May 20 '24 13:05 golles

I get basically the same issue. I play a video file using Jellyfin Andriod app and cast to Chromecast . I pause playback, disconnect chromecast & close jellyfin. New entries show up. I currently have 196. image image

Edit: Is it possible to mass delete entries?

Bluey-Speaker avatar Jun 15 '24 11:06 Bluey-Speaker

I’m having the same issue with multiple devices appearing several times, not limited to chromecast devices only either. IMG_9474

ThatJRadGuy avatar Jun 21 '24 14:06 ThatJRadGuy

I'm the OP from https://github.com/home-assistant/core/issues/105000 ( <- nice number )

Just to confirm this is still an issue, but in my case, there are only duplicate Apple TV Swiftfin entries, no duplicates for my phone nor desktops, but then again, I don't remember when is the last time I actually played something on a player other than my TV, so there's that.

rwjack avatar Jun 21 '24 14:06 rwjack

I'm having a similar issue but it's hard to tell how much of it is actually that in jellyfin itself each user account on each device and in the case of phones each client app (like if you use both the jellyfin app and finamp app like I do) all show up as separate entities. So maybe before fixing this more details about the media session should be displayed such as the user account and the client app the session represents. That would be a helpful feature in its own right in addition to being useful in debugging this issue.

Binvention avatar Aug 15 '24 13:08 Binvention

I'm curious why every app or player that interacts with Jellyfin generates a media player entity in Home Assistant in the first place. Generating 245 different media players is either funny or annoying, depending on your perspective, but what problem does generating even one solve?

alanpaone avatar Aug 30 '24 18:08 alanpaone

Probably if users are watching on their TV / Phone / Desktop, each one of those is a "separate media player", but tbh I don't remember when I last watched something other than on my TV.

rwjack avatar Aug 30 '24 18:08 rwjack

So to recap, if we're seeing this on both AppleTV Swiftfin and other Jellyfin players, phones/desktops, wouldn't it make more sense to implement the fix in the integration here?

Something along the lines of: If the player name is the same, even if the ID changed, don't create a new entity?

I just went through the process of deleting 30 media players (again).

rwjack avatar Sep 22 '24 10:09 rwjack

Any updates on this? Its definitely an issue that should be solved in this integration, not in every single client.

image

Im not even sure why this is creating media_player entities for clients anyway. Can we have a configuration option to disable this behaviour until a longer term fix is implemented?

asellitt avatar Nov 24 '24 09:11 asellitt

Just want to add that I'm seeing the same behaviour from most of my devices including from the standard Jellyfin for Android TV app on my Sony Bravia kd-55x9000h with Google TV. The issue isn't so much that there are multiple devices/entities created but that it is not possible to create a reliable automation as the active Entitity ID keeps getting incremented (i.e. media_player.media_room_tv_2 becomes media_player.media_room_tv_3 and so on)

In my case I have an automation that adjusts the rooms brightness based on the state of the media_player so you can see what you are doing when you paus a movie for example. This issue breaks the automation

zoucet avatar Jan 04 '25 06:01 zoucet

This issue continues to clutter my interface. I have 17 AppleTV instances listed!

I guess the easiest thing to do is to disable this integration until this is resolved...

satmandu avatar Mar 03 '25 04:03 satmandu

I'm having similar - I have one device in question (Bravia) but it appears as 3 devices in HA despite being one device in Jellyfin. Only one of them shows the now playing and allows control, the others are just unavailable. Erasing the jellyfin devices and reloading/disabling/reconfiguring HA integration has no effect...

jwh avatar Mar 30 '25 23:03 jwh

https://github.com/home-assistant/core/blob/dev/homeassistant/components/jellyfin/media_player.py#L39 seems to be where it creates per session

CloCkWeRX avatar Apr 16 '25 08:04 CloCkWeRX

Seems like it should check to see if an entry already exists before adding, right?

satmandu avatar Apr 17 '25 14:04 satmandu

This code creates the entity addition, with if session_id not in coordinator.session_ids: gating the addition:

async def async_setup_entry(
    hass: HomeAssistant,
    entry: JellyfinConfigEntry,
    async_add_entities: AddConfigEntryEntitiesCallback,
) -> None:
    """Set up Jellyfin media_player from a config entry."""
    coordinator = entry.runtime_data

    @callback
    def handle_coordinator_update() -> None:
        """Add media player per session."""
        entities: list[MediaPlayerEntity] = []
        for session_id in coordinator.data:
            if session_id not in coordinator.session_ids:
                entity: MediaPlayerEntity = JellyfinMediaPlayer(coordinator, session_id)
                LOGGER.debug("Creating media player for session: %s", session_id)
                coordinator.session_ids.add(session_id)
                entities.append(entity)
        async_add_entities(entities)

However, the JellyfinConfigEntry entry data is coming from https://github.com/home-assistant/core/blob/1307cd4b108d93af61b1640d4ff602b3c8e9992a/homeassistant/components/jellyfin/coordinator.py#L19

My uneducated guess would be that the session_id is per connection to the jellyfin server, and every time that HASS connects to the jellyfin server, it gets a new session id. So maybe we gate the addition by server_id instead.

So maybe the code in https://github.com/home-assistant/core/blob/dev/homeassistant/components/jellyfin/media_player.py should be:

    def handle_coordinator_update() -> None:
        """Add media player per session."""
        entities: list[MediaPlayerEntity] = []
        for session_id in coordinator.data:
            if session_id not in coordinator.session_ids and server_id not in coordinator.server_ids:
                entity: MediaPlayerEntity = JellyfinMediaPlayer(coordinator, session_id)
                LOGGER.debug("Creating media player for session: %s", session_id)
               coordinator.server_ids.add(server_id) 
               coordinator.session_ids.add(session_id)
                entities.append(entity)
        async_add_entities(entities)

and in https://github.com/home-assistant/core/blob/dev/homeassistant/components/jellyfin/coordinator.py :

    def __init__(
        self,
        hass: HomeAssistant,
        config_entry: JellyfinConfigEntry,
        api_client: JellyfinClient,
        system_info: dict[str, Any],
        user_id: str,
    ) -> None:
        """Initialize the coordinator."""
        super().__init__(
            hass=hass,
            logger=LOGGER,
            config_entry=config_entry,
            name=DOMAIN,
            update_interval=timedelta(seconds=10),
        )
        self.api_client = api_client
        self.server_id: str = system_info["Id"]
        self.server_name: str = system_info["Name"]
        self.server_version: str | None = system_info.get("Version")
        self.client_device_id: str = config_entry.data[CONF_CLIENT_DEVICE_ID]
        self.user_id: str = user_id

        self.server_ids: set[str] = set()
        self.session_ids: set[str] = set()
        self.remote_session_ids: set[str] = set()
        self.device_ids: set[str] = set()

satmandu avatar Apr 17 '25 14:04 satmandu

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

bump

rwjack avatar Jul 16 '25 21:07 rwjack

this continues to be an issue, and I still don't know what problem its solving here, why is jellyfin creating extra entities that already exist as players provided by all the various TV integrations?

Image

alanpaone avatar Jul 16 '25 21:07 alanpaone

I have the same problem :(

tomoffel85 avatar Aug 07 '25 23:08 tomoffel85

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

b

rwjack avatar Nov 06 '25 07:11 rwjack

Jellyfin added 131 dead entities since the last time this issue was marked as stale. Again, why are we duplicating media players that already exist and have their own integrations? every chromecast, apple TV, or smart TV in a home has its own media player entity already! if we can't fix this bug, would it be easier to just remove this behaviour entirely?

alanpaone avatar Nov 06 '25 07:11 alanpaone

I just realized that we could disable adding new entities by this integration directly in HA. Solves the problem temporarily.

Actually, I just remembered I had already disabled the whole integration. It's useless anyways as the player always has an idle state (unusable for automations)

rwjack avatar Nov 06 '25 08:11 rwjack