Home Assistant Kodi with Google Assistant

All,

I found this on github last week:

its pretty awesome and works well, quite response even.

But now I would like to fork it to home assistant.

I tried my way with scripts and so on but I struggle to make even a simple script working.
Anybody open to give me a push in the correct direction?

Thanks!

1 Like

I know this thread is old, but I’m trying to get some of this working through scripts and automations. I’m no developer so I wouldn’t know where to begin with an integration, but I’d be happy with being 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. Hopefully someone has come across this problem with JSON payloads in home assistant before.

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
    }
}

I’m working on something pretty similar, but I have zero scripting ability and I’m brand new to HA, so it’s taking some time.

My approach is to use the GoogleHomeKodi javascript as mentioned in the long long ago OP to do most of the grunt work. HA passes the movie name or PVR channel or whatever to the nodejs that handles the communication with the Kodi instance - matching and playing.

Is something like that possible for your setup?

I suppose I was trying to avoid setting up yet another service to run the nodejs but all things considered this code seems to work great as is (or so I’ve read), and if no one smarter than me is going to pick it up, this is probably the best thing I can do for now. Using home assistant as a way to avoid opening nodejs to the internet would be awesome. I’ll see if I can work on this tonight.

It would be amazing if we could get this functionality in some sort of integration.

1 Like

Ok so I couldn’t stay away and ended up working on this during my lunch hour. I got the node server setup and it’s working perfectly. What I ended up doing was using the rest_command domain to create a service that will run against the node server. I then have IFTTT run an automation in home assistant via webhook, that triggers the rest_command service. I have this working for the “ok google, kodi play x” command and it seems to work flawlessly. Next, I’m going to try to get the parser working so I can have a single IFTTT job based on “ok google, kodi x” where x is a string matching the action I want to perform. HA will pass the entire action string to the phrase parser and so on from there. I’ll post again when I have more info on that.

ok so I think I have it all working but there seems to be an issue with IFTTT where my google assistant isn’t picking up the new voice commands. That being said, it wasn’t too bad to setup at all. You need a single rest_command defined in your configuration.yaml, a webhook based automation to receive commands from IFTTT and relay to the node server, and then a single applet in IFTTT to accept the voice commands from Google Assistant. The rest_command and automation yaml code are below. I’ll confirm everything is working once IFTTT sorts itself out.

EDIT: I’m still having issues with IFTTT but I added a different keyword other than Kodi to start the commands (i.e. living room play x) and that seems to be working. All the commands are parsing properly and the correct actions are happening on my Kodi instance. Thanks to mitchellross for suggesting I just use the original code.

The rest_command:

rest_command:
  kodi_phrase:
    url: 'http://YOUR_NODE_IP:8099/broker?phrase={{ phrase }}'
    method: POST
    content_type: 'application/json'
    payload: '{"token":"YOUR_TOKEN"}'

The Automation:

- id: '1593288345365'
  alias: Google Home Kodi Control
  description: ''
  trigger:
  - platform: webhook
    webhook_id: kodiphrase
  condition: []
  action:
  - data_template:
      phrase: '{{ trigger.json.phrase }}'
    service: rest_command.kodi_phrase
1 Like

Excellent. Sorry I lost track of this thread. I hosed my install and I’m yet to get it back to a place where I can start playing with this again. But I think we ended up in similar places. The IFTTT-webhook-HA thing is pretty simple, but it works.

I get what you’re saying about not wanting yet another nodejs thing running. I don’t think there would be too much work to replicate what googlehomekodi does within HA. I just need to learn more about JSON commands and responses.