How to read values from the Kodi/OSMC integration?

I’m a bit confused how to read values from osmc via the integration. In other words, I want to know if the osmc device is playing some media, or has stopped or paused the media (if it was playing).

Is there some way to do this? All the docs point to controlling osmc. I’m looking for triggering lighting automations based on what osmc is doing.

Thanks!

You check the media player state like this:

trigger:
  - platform: state
    entity_id: media_player.your_kodi_here
    to: 'playing'

Other states are, paused, or idle.

Here are a couple of my automations:

- id: dee5268e-ad06-481a-b40a-6634608266bb
  alias: "Lounge Movie Scene On"
  trigger:
    platform: state
    entity_id: media_player.lounge_osmc_kodi
    to: 'playing'
  condition:
  - condition: state
    entity_id: input_select.lounge_scene
    state: 'Automatic'
  - condition: state
    entity_id: light.all_lounge_lights
    state: 'on'
  action:
  - service: input_select.select_option
    data:
      entity_id: input_select.lounge_scene
      option: "Watch Movie"
  - condition: state
    entity_id: switch.lounge_dehumidifier_power
    state:  'on'
  - service: switch.turn_off
    entity_id: switch.lounge_dehumidifier_power

- id: 5e4aa2fa-5de9-4531-ba1b-a26456c84a02
  alias: "Lounge Movie Scene Off"
  trigger:
    platform: state
    entity_id: media_player.lounge_osmc_kodi
    from: 'playing'
    for:  # Required on my setup to prevent triggering the automation if a "next episode" plays automatically.
      seconds: 1
  condition:
  - condition: state
    entity_id: input_select.lounge_scene
    state: 'Watch Movie'
  action:
  - service: input_select.select_option
    data:
      entity_id: input_select.lounge_scene
      option: "Automatic"

I have another automation that runs when the input select changes. This way I always know which scene is active and can use it in conditions.

- id: 3c6e8948-47f7-49ba-bc69-f78135315f98
  alias: 'Lounge Scene Select'
  trigger:
    platform: state
    entity_id: input_select.lounge_scene
  action:
  - service: lifx.effect_stop
    entity_id: group.all_lounge_lights
  - service: homeassistant.turn_on
    data:
      entity_id: >
        {% if states('input_select.lounge_scene') == 'Off' %}
          scene.lounge_off
        {% elif states('input_select.lounge_scene') == 'Manual' %}
          script.lounge_manual
        {% elif states('input_select.lounge_scene') == 'Automatic' %}
          scene.lounge_automatic
        {% elif states('input_select.lounge_scene') == 'Blood' %}
          scene.lounge_blood
        {% elif states('input_select.lounge_scene') == 'Bright' %}
          scene.lounge_bright
        {% elif states('input_select.lounge_scene') == 'Forest' %}
          scene.lounge_forest
        {% elif states('input_select.lounge_scene') == 'Imperial' %}
          scene.lounge_imperial
        {% elif states('input_select.lounge_scene') == 'Night Light' %}
          scene.lounge_night_light
        {% elif states('input_select.lounge_scene') == 'Party' %}
          script.lounge_party
        {% elif states('input_select.lounge_scene') == 'Sky' %}
          scene.lounge_sky
        {% elif states('input_select.lounge_scene') == 'Under Water' %}
          scene.lounge_under_water
        {% elif states('input_select.lounge_scene') == 'Watch Movie' %}
          scene.lounge_watch_movie
        {% elif states('input_select.lounge_scene') == 'Zen' %}
          scene.lounge_zen
        {% else %}
          scene.lounge_automatic
        {% endif %}

Awesome info and thanks for sharing your automation scripts. As you were probably composing that, I did finally use the dev tools to check the state of the player, and for me it’s a little different (entity_id):

Here’s my evening lighting on (30 mins. before sunset) script so far:

alias: 'Daily timed events: Evening lighting on'
description: A little before sunset, turn some lights on
trigger:
  - platform: sun
    event: sunset
    offset: '-30'
condition: []
action:
  - scene: scene.kitchen_cabinets_normal
  - scene: scene.dennis_office_back_hallway_lamp_purple
  - condition: state
    entity_id: media_player.kodi_9f7b06e0e40ef9b873f50
    state: idle
  - service: automation.trigger
    target:
      entity_id: automation.family_room_tv_lights_on_daily_color
mode: single

The idea is that if the TV is playing something, don’t turn on the lights next to the tv. Otherwise, turn on the lights next to the TV if osmc is idle.

Thanks again for the help!