Scripting with conditions on entity_id for Kodi Library Update

Hi Everyone,

I’m new to scripting and templates, and am trying to write a script that will tell one of my kodi media players to update its library, based on which one is online.

Currently I have tried a few variations of the following code:

  update_library:
    alias: Update Kodi Library
    sequence:
      - alias: Call Kodi update
        service: media_player.kodi_call_method
        data_template:
          entity_id: >
            {% if is_state('states.media_player.kodi_bedroom', 'off') %}
              media_player.kodi_lounge_room
            {% else %}
              media_player.kodi_bedroom
            {% endif %}
          method: VideoLibrary.Scan

But it doesn’t seem to work. I’m sure there is something obvious that I’m missing, I just don’t know what it is?

Thanks

is_state('states.media_player.kodi_bedroom', 'off')

should be

is_state('media_player.kodi_bedroom', 'off')

As per @pnbruckner’s advice, you only need the additional state prefix if you’re referencing the attributes level

Awesome that worked, thank you!

1 Like