[Solved] Help with using input_select as entity_id

Hey all,

Trying to tidy up my code and need a bit of help with this one.

Kodis setup like so as mediaplayers:

  - platform: kodi
    host: !secret kodi_up_ip
    name: Upstairs
    username: *
    password: *

(same for Downstairs)

input_select with a list of my Kodis:

  name: Kodi
    - Upstairs
    - Downstairs
  initial: Upstairs

Example script to clean library:

  alias: Clean Video Library
    - service: media_player.kodi_call_method
        entity_id: *** What Goes Here ***
        method: VideoLibrary.Clean

How do I use the input_select entry as an entity_id to send the command to?

Do I need something (automation, booleon etc) somewhere to say 'if input_select = Upstairs set entity_id = mediaplayer.upstairs' or is there an easier way to pull the input_selects state through as an entity_id?

This would clean up a lot of my code as I can pass everything to a set of scripts then rather than have a script per kodi instance!


Last three lines should be

  entity_id: "media_player.{{ states('input_select.select_kodi') }}"
  method: VideoLibrary.Clean

Edit - not sure if the upstairs / downstairs will need to be lowercase for that to work, but it definitely works with the entries in the input_select being lowercase as that’s how my music player works.

Thats brilliant mate, got close last night with states('input_select.select_kodi) but syntax with the media_player was well off!

Did a little renaming of my kodis so they are more uniform but they work perfectly now :slight_smile:

The upper/lower didnt seem to make a difference as well :):

domain=media_player, service=kodi_call_method, service_data=entity_id=media_player.Bedroom, method=VideoLibrary.Clean

All the scripts run nicely :smiley:

Thanks again!

1 Like