core: media_player and media_extractor dont work with Kodi entity

The problem

After the beta update I am unable to start my Youtube watch later playlist with media_player.play media service OR play youtube video via media_extractor service.

What is version of Home Assistant Core has the issue?

2021.40b0

What was the last working version of Home Assistant Core?

2021.4

What type of installation are you running?

Home Assistant Supervised

Integration causing the issue

No response

Link to integration documentation on our website

No response

Example YAML snippet

alias: Youtube WL
description: ''
trigger:
  - platform: state
    entity_id: input_boolean.youtube_wl
    from: 'off'
    to: 'on'
condition: []
action:
  - service: media_player.play_media
    data:
      media_content_type: video
      media_content_id: >-
        plugin://plugin.video.youtube/play/?playlist_id=my personal playlist id&order=shuffle&play=1
    target:
      entity_id: media_player.osmc_vivian
  - service: input_boolean.turn_off
    data: {}
    target:
      entity_id: input_boolean.youtube_wl
mode: single

Anything in the logs that might be useful for us?

Logger: homeassistant.components.automation.youtube_wl
Source: components/kodi/media_player.py:716
Integration: Automation (documentation, issues)
First occurred: 5:27:22 PM (2 occurrences)
Last logged: 5:27:22 PM

Youtube WL: Error executing script. Unexpected error for call_service at pos 1: (-32602, 'Invalid params.', {'error': {'code': -32602, 'data': {'method': 'Player.Open', 'stack': {'message': 'Received value does not match any of the union type definitions', 'name': 'item', 'type': 'object'}}, 'message': 'Invalid params.'}, 'id': 516297241, 'jsonrpc': '2.0'})
While executing automation automation.youtube_wl
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 354, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 554, in _async_call_service_step
    await service_task
  File "/usr/src/homeassistant/homeassistant/core.py", line 1480, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1515, in _execute_service
    await handler.job.target(service_call)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 206, in handle_service
    await self.hass.helpers.service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 644, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 692, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 681, in _handle_entity_call
    await result
  File "/usr/src/homeassistant/homeassistant/components/kodi/media_player.py", line 256, in wrapper
    await func(obj, *args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/components/kodi/media_player.py", line 716, in async_play_media
    await self._kodi.play_file(str(media_id))
  File "/usr/local/lib/python3.8/site-packages/pykodi/kodi.py", line 279, in play_file
    await self.play_item({"file": file})
  File "/usr/local/lib/python3.8/site-packages/pykodi/kodi.py", line 263, in play_item
    await self._server.Player.Open({"item": item})
  File "/usr/local/lib/python3.8/site-packages/jsonrpc_websocket/jsonrpc.py", line 53, in send_message
    return message.parse_response(response)
  File "/usr/local/lib/python3.8/site-packages/jsonrpc_base/jsonrpc.py", line 216, in parse_response
    raise ProtocolError(code, message, data)
jsonrpc_base.jsonrpc.ProtocolError: (-32602, 'Invalid params.', {'error': {'code': -32602, 'data': {'method': 'Player.Open', 'stack': {'message': 'Received value does not match any of the union type definitions', 'name': 'item', 'type': 'object'}}, 'message': 'Invalid params.'}, 'id': 516297241, 'jsonrpc': '2.0'})

First time I am reporting an issue. I will be happy to provide any additional info I can!

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 2
  • Comments: 48 (19 by maintainers)

Most upvoted comments

So if all goes well and the upstream maintainers play along

We did 😃 Version 0.2.4 is released

@frenck thanks, boss!

I can confirm that jsonrpc_base is causing the issue. @dlindnegm: You can

  1. Go to https://downgit.github.io/

xorbital - That worked like a champ. Thanks for the quick work on this!

@xorbital gave the important hint at the messed up json. So, thank you guys for testing, debugging and verifying. Hopefully nothing else breaks due to the dependency updates.

@cgtobi said they’re working on it, so chill. In fact, it seems like there’s already a pull request open: https://github.com/OnFreund/PyKodi/pull/11 (Thank you very much, Tobi!) So if all goes well and the upstream maintainers play along, this could be fixed in the next point release of Home Assistant. For now, apply the temporary fix, downgrade or wait.

I have the same problem and can confirm that after installing old version of jsonrpc_base it starts working pip install jsonrpc_base==1.1.0

Reverting back to https://github.com/home-assistant/core/tree/72281f4718b6ca71b77b515fa3afc466d2d812d9/homeassistant/components/kodi had no effect, I’m done for today, however I found out the root problem:

I’ve enabled Debug Logging for the JSON-RPC component inside Kodi and this is the API call when using media_player.play_media:

DEBUG: JSONRPC: Incoming request: {"jsonrpc": "2.0", "method": "Player.Open", "params": [{"item": {"file": "https://www.monstercat.com/podcasts/mss/episodes/MSS-589.mp3"}}]
, "id": 4328164615441371358}

And this is the call using kodi.call_method directly:

DEBUG: JSONRPC: Incoming request: {"jsonrpc": "2.0", "method": "Player.Open", "params": {"item": {"file": "https://www.monstercat.com/podcasts/mss/episodes/MSS-589.mp3"}}, 
"id": 934075246035723163}

Weirdly enough, there are no errors in the log, but maybe I haven’t enabled the logging of those or they are only in the replies to the call? In any case, I guess the extra [ ] might be our problem here…

Hm, but you’re also running OSMC stable, so Kodi v18.9, which means there aren’t any Kodi API changes. I’ll set up Kodi as a custom component and revert to before #47315 (Thank you for your work, @cgtobi!), seems like this PR changed some of the inner workings of the integration.

Yes, doesn’t work for me either. Using video doesn’t change that. My setup, roughly:

  • Home Assistant OS on an Intel NUC
  • Kodi installed on a different machine (OSMC), same subnet.
  • Everything else is working with Kodi, kodi.call_method puts out events like it should, the entity state of kodi is also reported correctly, sending play/pause commands works as well. I’ll test with a few LibreELEC boxes as well to make sure it’s not a kodi issue.