Kodi HomeAssistant and Json
#1
Im having a mess about with home assistant and currentlytesting out the kodi integration to see if it will suit my purposes

Its quite a leaning curve for me as I dont know how JSON calls work in general let alone how you set up scripts in home assistant !!

But I have managed to get a playlist to play using the information From https://forum.kodi.tv/showthread.php?tid...pid2694920

where I found this from Dave


[{"jsonrpc": "2.0", "id": 0, "method": "Playlist.Clear", "params": {"playlistid": 0}},
{"jsonrpc":"2.0","id":0,"method":"Playlist.Add","params":{"playlistid":0,"item":{"recursive":true, "directory":"special://profile/playlists/music/zzzz.xsp"}}},
{"jsonrpc":"2.0","id":0,"method":"Player.Open","params":{"item":{"playlistid":0,"position":0}}}]

from which I have created home assistant scripts that look like the following

kodi_party_mode:
  alias: Kodi 1950s
  sequence:
  - service: kodi.call_method
    data:
      entity_id: media_player.rasp3libre
      method: Playlist.Clear
      playlistid: 0
  - service: kodi.call_method
    data:
      method: Playlist.Add
      playlistid: 0
      item:
        recursive: true
        directory: special://profile/playlists/music/1950s.xsp
    target:
      entity_id: media_player.rasp3libre
  - service: kodi.call_method
    data:
      entity_id: media_player.rasp3libre
      method: Player.SetPartymode
      playlistid: 0
      item:
        playerid: 0
        partymode: true
  - service: kodi.call_method
    data:
      entity_id: media_player.rasp3libre
      method: Player.Open
      item:
        playlistid: 0
        position: 0
  mode: single
  icon: mdi:disc-player

The playlist plays perfectly but I am unable to workout how to play it in party mode, I have tried Player.SetPartymode both before and after Playlist.Add but without success

Looking at the json api details on the wiki I'm beginning to think I need to set partymode in Player.open but I dont know enough json to workout how to supply all the parameters

Could someone with some JSON knowledge post a sample call whch opens an existing call in party mode, from that I'm pretty sure I'll be able to workout the homeassistant script entries

thanks in advance
Reply
#2
In the iOS remote app the commands look like this:

Enable PartyMode:
{"jsonrpc":"2.0","id":0,"method":"Player.Open","params":{"item":{"partymode":"music"}}

Disable PartyMode
{"jsonrpc":"2.0","id":0,"method":"Player.SetPartymode","params":{"playerid":0,"partymode":""toggle"}}
Reply
#3
Thanks for that

How do you get the ios app to show what is being sent to server ?

I have an android phone and have tried both yatse and the officail app,  but can not find anything that displays what is being sent to server
Reply
#4
I did read the code Smile

But to my knowledge you can also enable JSON debug on the Kodi server to show the communication.
Reply
#5
thanks again

yes I have enabled json debugging in the log and can find everything I need now

but  I'm baffled

Yatse sends the following which works and invokes party mode

{"jsonrpc": "2.0", "method": "Player.Open", "params": {"params": {"item": {"partymode": "music"}}}, "id": "dbcc4623-382d-403f-ac5c-39edf413cd18"}

my Home Assistant script sends the following which appears identical apart from the id, but doesn't appeaar to do anyting so I'm presumably missing a step somewhere before the partymode call

{"jsonrpc": "2.0", "method": "Player.Open", "params": {"params": {"item": {"partymode": "music"}}}, "id": "ba9d34ff-d65e-4c26-87a2-916699b47eab"}
Reply
#6
Can you compare what your script and what Kore sends (reading from Kodi server's JSON debug messages)? Do you in both cases load your smart playlist?
Reply
#7
I cant actually find a way to get the Kore app to start partymode. I use the Yatse app which does have a way to do it.

But Ive got it working from Home assistant anyway

For anyone interested this works in scripts.yaml

Code:


kodi_party_mode:
  alias: Kodi Party Mode
  sequence:
  - service: kodi.call_method
    target:
      entity_id: media_player.rasp3libre
    data:
      entity_id: media_player.rasp3libre
      method: Player.SetPartyMode
      playerid: 0
      partymode: true
  mode: single
  icon: mdi:music


I had added an 'id: "1"' field once I removed that it worked perfectly
Reply
#8
Eventually got this working

see this post for more details

368269 (thread)

given a kodi playlist similar to the following

Code:


<smartplaylist type="songs">
    <name>Short</name>
    <match>all</match>
    <rule field="genre" operator="doesnotcontain">
        <value>xmas</value>
    </rule>
    <rule field="time" operator="lessthan">
        <value>3:01</value>
    </rule>
    <rule field="playlist" operator="is">
        <value>Two-weeks-old</value>
    </rule>
</smartplaylist>


to play it in party mode from home assistant requires something similar to the following added to the home assistant scripts.yaml file

Code:


kodi_short_songs:
  alias: Kodi Short Songs
  sequence:
    - service: kodi.call_method
      target:
        entity_id: media_player.rasp3libre
      data:
        entity_id: media_player.rasp3libre
        method: Player.Stop
        playerid: 0
    - service: kodi.call_method
      target:
        entity_id: media_player.rasp3libre
      data:
        entity_id: media_player.rasp3libre
        method: Playlist.Clear
        playlistid: 0
    - service: kodi.call_method
      target:
        entity_id: media_player.rasp3libre
      data:
        entity_id: media_player.rasp3libre
        method: Player.Open
        item:
          partymode: /storage/.kodi/userdata/playlists/music/Short.xsp
  mode: single
  icon: mdi:music

Reply



Logout Mark Read Team Forum Stats Members Help
Kodi HomeAssistant and Json0
This forum uses Lukasz Tkacz MyBB addons.