Playing media on Kodi - "no active player"

The background: I’m trying this for four years now, with intermittent success. Sometimes it works, but most times it doesn’t.

Just simple playback to Kodi. Kodi is integrated into HA via the official integration, I can see it in the Media sources, I can play to it via HA Media browser UI.

HA 2023.8.3 (irrelevant, happening for years)
Kodi 19.5 (LIBREELEC 10.0.4) (ditto)

The Issue: When trying to play media to it via an automation though, almost always (but not always!) I’m just getting a “no active player” popup in HA. In log:


Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/automation/__init__.py", line 659, in async_trigger
await self.action_script.async_run(
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1569, 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 703, in _async_call_service_step
response_data = await self._async_run_long_action(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 665, in _async_run_long_action
return long_task.result()
^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/core.py", line 1974, in async_call
response_data = await coro
^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/core.py", line 2011, 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 870, in entity_service_call
response_data = await _handle_entity_call(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 942, in _handle_entity_call
result = await task
^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/kodi/media_player.py", line 242, in wrapper
await func(obj, *args, **kwargs)
File "/usr/src/homeassistant/homeassistant/components/kodi/media_player.py", line 749, in async_set_shuffle
raise RuntimeError("Error: No active player.")
RuntimeError: Error: No active player.

The goal: to have NFC tags starting playback on TV for my kid. I have it working for Spotify but Kodi is half broken and Jellyfin support is practically nonexistent in HA.

Any tips? Thanks.

Two things to start with.

  1. Do you have the “web” interface enabled in KODI?

https://kodi.wiki/view/Web_interface

  1. Can you share your automation?
  1. yes I have. As I said, it does work sometimes, usually when something else already plays. That’s a headscratcher.

alias: Štítek tv-vlk_a_zajic je naskenován
description: ""
trigger:
  - platform: tag
    tag_id: 04-30-97-20-19-61-80
condition:
  - condition: time
    after: "08:00:00"
    before: "20:00:00"
action:
  - service: media_player.turn_on
    data: {}
    target:
      entity_id: media_player.samsungtv
  - delay:
      hours: 0
      minutes: 0
      seconds: 2
      milliseconds: 0
  - service: media_player.shuffle_set
    data:
      shuffle: true
    target:
      entity_id: media_player.libreelec
  - service: media_player.select_source
    data:
      source: Cable Box
    target:
      entity_id: media_player.samsungtv
  - service: media_player.play_media
    data:
      media_content_type: DIRECTORY
      media_content_id: special://profile/playlists/video/vlk.m3u
    target:
      entity_id: media_player.libreelec
mode: single

Shuffle is there so a random episode plays.

1 Like

You are trying to “shuffle” when there is no playlist active, yet, hence the error…
Not sure if it’s actually allowed in Kodi, but the HA integration does not allow it.

Try to put it after the play_media.

2 Likes

Hey, that may be it! I thought Shuffle was some sort of mode switch independent on current playback. Looking good so far. Thank you!

I think you may be onto something there. I have done some KODI programming in the past and shuffling without a Playlist is definitely a problem. This may explain why @Stooovie indicates it works “when something else already plays”

1 Like

If you guys have a more elegant way to play a random episode (preferably from a folder so I don’t have to create a playlist for every series), I’m all ears!