Kodi control

Hey, I am building a multi-room audio system controlled by Home Assistant.

As a part of this I need to control Kodi audio output and have experimented with scripts using the player.kodi_call_method:

script:
  audio_tv:
    sequence:
      - service: media_player.kodi_call_method
        data:
          entity_id: media_player.kodi_stue
          method: Settings.SetSettingValue
          setting: "audiooutput.audiodevice"
          value: "PI:HDMI"

But, it’s all hardcoded and no state feedback.

The Settings.GetSettingValue Kodi api can read out the audiooutput.audiodevice, but how to get it to display to the user?

For simular integration with Snapcast using switches to control a zone input stream I get the state like:

script:
  stream_spotify:
    sequence:
    - service: media_player.select_source
      data:
        entity_id: media_player.snapcast_group_b66dd6c63c3b8de95237d287b1b8adaa
        source: "Spotify"

binary_sensor:
  - platform: template
    sensors:
      stream_spotify_on:
        friendly_name: "Stream Spotify"
        entity_id: media_player.snapcast_group_b66dd6c63c3b8de95237d287b1b8adaa
        value_template: >
          {{ is_state_attr('media_player.snapcast_group_b66dd6c63c3b8de95237d287b1b8adaa', 'source', 'Spotify') }}

switch:
  - platform: template
    switches:
      switch_stream_spotify:
        friendly_name: "Stream Spotify"
        entity_id: binary_sensor.stream_spotify_on
        value_template: >
          {{ states('binary_sensor.stream_spotify_on') }}
        turn_on:
          service: script.stream_spotify
        turn_off:

This works nicely with multiple switches, each press turns off the others due to the binary_sensor feedback.

But, how to get state for Kodi? My initial thought was to make a kodi_audio_status script and call from the value_template of binary_sensor but ehh…can’t figure out if a script actually can return a result and how to get it from the template… I really suspect I’m barking up the wrong tree.

So, any1 input on how to get some kind of selection of the configured Kodi audio output including status feedback?

None?

Is it possible to reflect state of a Kodi setting, read with media_player.kodi_call_method, in a binary sensor?

Not sure which state you’re after but Kodi publishes a load of states, I use the media_content_type one regularly, this is what mine shows currently, don’t know if that helps…

media_player.kodi	paused	volume_level: 1
is_volume_muted: false
media_content_id: {
  "imdb": "tt6931944",
  "tvdb": "6367725"
}
media_content_type: tvshow
media_duration: 2670
media_title: Traveler 0027
media_album_name: 
media_series_title: Travelers (2016)
media_season: 2
media_episode: 8
friendly_name: Kodi
entity_picture: /api/media_player_proxy/media_player.kodi?token=428e0b270bc65047e6eb1ea4cd2dc5e9c65538d233696026742ea86afd0544f3&cache=3cd6b52b8357c9f3
supported_features: 54847

Thx for reply, the state is a non-published one, the audio output device.

Basically I route output to different devices and want to control it from a dashboard. I use the media_player.kodi_call_method to get/set the device.

But I can’t figure out how to use the return value from media_player.kodi_call_method to get the state and set a switch or sensor accordingly.

No probs, sorry it didn’t help.

I finally figured out how to do something similar to what I was trying to do.

  1. Make a “set Kodi audio output to HDMI” script for each value I wanted
  2. Make an input selector containing the states, one for each value (hidden)
  3. Make a switch for each value, let them get their value from from the input selector and turn on by a sequence of the script and setting the input selector

This leaves me with a row of switches, when I press one the others turn off.

But, it still does not necessarily reflect the real value of the Kodi audio output configuration, I’ve pretty much given up on that :frowning:

So, performing a simple JSON-RPC call and use the return value to anything is out of the scope without modifying the Kodi media_player I guess.