Is it possible to play a specific movie on kodi via hass script?

Hi,

I would like to create a view for my kid, where he is presented with a selection of movies he can choose from and play via KoDi.

For this, I am missing one key ingredient:
How can I play a specific movie from my KoDi library? I would need to know if and where I can find a kodi movie ID which command I need to use to play it.

Can anyone help?

Http://kodi.tv

Please elaborate

The API is best asked about on the kodi forum.

oh, thanks so much…

OK, I figured out a working solution (not sure if it is the optimal way but it works):

Create RESTful Commands for each Kodi movie. One examples is as follows:

rest_command:
  kodi_moviename:
    url: 'http://KODIHTTPIP:KODIPORT/jsonrpc'
    method: post
    username: !secret kodi_username
    password: !secret kodi_password
    payload: '{"jsonrpc":"2.0","id":"1","method":"Player.Open","params":{"item":{"file":"smb://YOURFILESHAREIP/PATH/FILENAME"}}}'
    content_type: 'application/json'

Then create a script for each movie for manually triggering it via HASS GUI:

SCRIPTNAME:
  alias: Play Movie ABC
  sequence:
    - service: rest_command.kodi_moviename

I then added SCRIPT Tiles to tileboard which are linked to the scripts created above and are represented by movie posters images.

Maybe this helps someone with a similar aim. Enjoy and feel free to give expert opinion on how to do it easier, as I am a hass n00b :grinning:

And I actually did find an easier method, by using the HASS kodi call method as script for each movie. So you don’t have to write the RESTful command, but only a script entry for each movie:

movie_xy:
  alias: Play Movie XY
  sequence:
    - service: media_player.kodi_call_method
      data:
        entity_id: media_player.kodi
        method: Player.Open
        item:
          file: "smb://YOURFILESHAREIP/PATH/FILENAME"

the only caveat with this approach, though, is that you must add the kodi component to the config yaml, whereas the RESTful command, directly would communicate with kodi.

1 Like

But how to specify files that are already on the internal memory?
developer-tools/service: kodi.call_method

{
  "entity_id": "media_player.kodi",
  "method": "Player.Open",
    "item": {
      "file": "file:///home/xbian/lift.strm"
    }
}

There is no error on home-assistant but an error on KODI.

1 Like

I found the correct answer: /home/xbian/lift.strm

1 Like

I know this thread is getting old, but I’m trying to take this idea a bit further. I would like to be able to say to my Google Home “Tell Kodi to play XYZ” and this will cause Kodi to play that movie. So far I have two scripts, one that searches for a movie with a given string and returns a single result with the movieid from the database, and another that plays a movie given a specified movieid. These two scripts work perfectly. The issue happens when I try to use an automation to run the second script based on event data from the first script. As far as I can tell the issue is that the template is returning a string instead of an integer but I’ve tried changing it to an integer and it doesn’t help. See relevant code below.

The two scripts

'1593263499843':
  alias: Kodi Get Movie
  sequence:
  - data:
      entity_id: media_player.living_room_tv
      filter:
        field: title
        operator: contains
        value: minions
      limits:
        end: 1
        start: 0
      method: VideoLibrary.GetMovies
    service: kodi.call_method
'1593279336491':
  alias: Kodi Play Movie
  sequence:
  - data_template:
      entity_id: media_player.living_room_tv
      item:
        movieid: '{{ movieid|int}}'
      method: player.open
    service: kodi.call_method

The automation:

- id: '1593279263626'
  alias: Kodi Play Movie
  description: ''
  trigger:
  - event_data:
      input:
        method: VideoLibrary.GetMovies
    event_type: kodi_call_method_result
    platform: event
  condition: []
  action:
  - data_template:
      movieid: '{{ trigger.event.data.result.movies.0.movieid|int }}'
    service: script.1593279336491

and here is the JSON response I get from the second script.

{
    "event_type": "kodi_call_method_result",
    "data": {
        "entity_id": "media_player.living_room_tv",
        "result": {
            "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."
        },
        "result_ok": false,
        "input": {
            "method": "player.open",
            "params": {
                "item": {
                    "movieid": "434"
                }
            }
        }
    },
    "origin": "LOCAL",
    "time_fired": "2020-06-27T19:42:26.248254+00:00",
    "context": {
        "id": "44a317e2601f4bd183e99b352abe675c",
        "parent_id": null,
        "user_id": null
    }
}
1 Like

In case this helps anyone:

i got @noogs approach to work by returning the file path from the search and modifying the Player.Open call accordingly (maybe there’s a more elegant version out there but this works):
Here is the final get movie script (notice the properties: object )

'1593263499843':
  alias: Kodi Get Movie
  sequence:
  - data:
      entity_id: media_player.living_room_tv
        filter:
          field: title
          operator: contains
          value: minions
        limits:
          end: 1
          start: 0
        properties:
          - file
        method: VideoLibrary.GetMovies
      service: kodi.call_method

the automation just passes the path to the script:

- id: '1606993440700'
  alias: OnMovieFound
  description: ''
  trigger:
  - platform: event
    event_type: kodi_call_method_result
    event_data:
      result_ok: true
      input:
        method: VideoLibrary.GetMovies
  action:
  - service: script.play_movie_in_kodi
    data_template:
      file: '{{ trigger.event.data.result.movies.0.file }}'
  mode: single

and the script:

play_movie_in_kodi:
  service: kodi.call_method
    data_template:
      item:
        file: '{{ file }}'
      method: Player.Open
      entity_id: media_player.libreelec
4 Likes