How can I set the entity_id with an input_select in a button-card?

Hi all. I’m having problems when I try to bind the entity_id with the value of an input_select in a button-card.
I have created this input_select from the helper:

In a button-card I have created a call to the remote.send_command service. Within target I include the entity_id associated with the input_select value:

type: custom:button-card
icon: mdi:import
show_name: false
name: source
tap_action:
  action: call-service
  service: remote.send_command
  data:
    command:
      - KEY_SOURCE
  target:
    entity_id: '{{states(''input_select.tv_select'')}}'

but it does not work… :face_with_spiral_eyes:
Can someone give me some idea. Thx.

Not sure you can template there.

You could make your button call a script and switch your tap action to call your script where you would have more flexibility to template the entity_id of target.

tap_action:
  action: call-service
  service: script.remote_send_command
  data:
    my_command: KEY_SOURCE

and your script might look something like this…

  # ------------------------------------------------------------------------
  # Send a Remote Code to a n entity/device
  # ------------------------------------------------------------------------
  remote_send_command:
    alias: Send a Remote Code
    sequence:
    - service: remote.send_command
      target:
        entity_id: "{{ states('input_select.tv_select') }}"
      data:
        command: "{{my_command}}"
        command_type: ir

OK Thanks testkanoo this work for me!! It’s a good solution.

But now I find another problem because one of the button cards should send a sequence to open netflix on my tv like this:
- KEY_HOME
- KEY_RIGHT
- KEY_RIGHT
- KEY_RIGHT
- KEY_RIGHT
- KEY_ENTER
But this sequence will be different depending on the TV I am going to select.

So does anyone know what’s the command to send for the Netflix button on a smart TV remote control? This would make programming easier.

If not, I should try to make a different sequence for each TV I select but it doesn’t work. :confounded:

type: custom:button-card
styles:
  icon:
    - color: red
icon: mdi:netflix
show_name: false
tap_action:
  action: call-service
  service: script.remote_send_command
  data:
    my_command: |-
      {% if is_state('input_select.tv_select','remote.samsung_1_tv') %} 
       - KEY_HOME
       - KEY_RIGHT
       - KEY_RIGHT
       - KEY_RIGHT
       - KEY_RIGHT
       - KEY_ENTER
      {% else %}
       - KEY_HOME
       - KEY_RIGHT
       - KEY_ENTER
      {% endif %}

Thank you very much in advance

What device is streaming Netflix?

If you have to use the remote commands, I’d put all of them in a script and just have the button control the script.

I would like to know what command to send to simulate the Netflix button on this remote control through call service “remote.send_command”:

LiQuid_cOOled is right here. It’s best to just have a script that takes a few parameters.

Tell your script which tv you are targeting and which button you are pressing.

In the script you can more easily use if…else blocks and choose statements to control the actions taken.

Try to keep action logic out of the user interface when possible. It’s not a very scalable approach.

You don’t say exactly how you’ve got the tv integrated, but it seems you’re overcomplicating things.

Can’t you add your tv as a media player and just select Netflix from the source list? Media player - Home Assistant

There’s a thread about a similar issue here, in case it helps.

Selecting the source from media_player can be a good option but in my case only TV and HDMI appear, as you can see below:

How can I add more sources?

I have Netflix as an integrated application

teskanoo …In the script you can more easily use if…else blocks and choose statements to control the actions taken.

I am having problems constructing the if…else block as I show you below. Can you help me?

type: custom:button-card
styles:
  icon:
    - color: red
icon: mdi:netflix
show_name: false
tap_action:
  action: call-service
  service: script.remote_send_command
  data:
    my_command: |-
      {% if is_state('input_select.tv_select','remote.samsung_1_tv') %} 
       - KEY_HOME
       - KEY_RIGHT
       - KEY_RIGHT
       - KEY_RIGHT
       - KEY_RIGHT
       - KEY_ENTER
      {% else %}
       - KEY_HOME
       - KEY_RIGHT
       - KEY_ENTER
      {% endif %}

You could make your button call a script and switch your tap action to call your script where you would have more flexibility to respond to which TV is selected and which button was pressed.

tap_action:
  action: call-service
  service: script.remote_send_command
  data:
    button_pressed: 'NETFLIX_BUTTON'

and your script might look something like this…

  # ------------------------------------------------------------------------
  # Send a Remote Code to a n entity/device
  # ------------------------------------------------------------------------
script:
  alias: remote_send_command
  fields:
    button_pressed:
      selector:
        text: null
      name: Button Pressed
      description: button_pressed is sent from the UI Tap Action
      required: true
  mode: queued
  sequence:
    - choose:
        - conditions:
            - condition: template
              value_template: >-
                (button_pressed == 'NETFLIX_BUTTON') and
                is_state('input_select.tv_select','remote.samsung_1_tv')
          sequence:
            - service: remote.send_command
              data:
                num_repeats: 0
                delay_secs: 0.1
                hold_secs: 0
                command:
                  - KEY_HOME
                  - KEY_RIGHT
                  - KEY_RIGHT
                  - KEY_RIGHT
                  - KEY_RIGHT
                  - KEY_ENTER
              target:
                entity_id: input_select.tv_select
          alias: Netflix - TV One
        - conditions:
            - condition: template
              value_template: >-
                (button_pressed == 'NETFLIX_BUTTON') and
                is_state('input_select.tv_select','remote.my_second_tv')
          sequence:
            - service: remote.send_command
              data:
                num_repeats: 0
                delay_secs: 0.1
                hold_secs: 0
                command:
                  - KEY_HOME
                  - KEY_RIGHT
                  - KEY_RIGHT
                  - KEY_RIGHT
                  - KEY_RIGHT
                  - KEY_ENTER
              target:
                entity_id:
                  - remote.my_second_tv
          alias: Netflix - TV Two
        - conditions:
            - condition: template
              value_template: >-
                (button_pressed == 'NETFLIX_BUTTON') and
                is_state('input_select.tv_select','remote.my_third_tv')
          sequence:
            - service: remote.send_command
              data:
                num_repeats: 1
                delay_secs: 0.4
                hold_secs: 0
                command:
                  - KEY_HOME
                  - KEY_RIGHT
                  - KEY_ENTER
              target:
                entity_id:
                  - remote.my_third_tv
          alias: Netflix - TV Three
      default: []

See The Script syntax for Choose Here

Hi teskanoo, I am trying to launch this script based on the one you told me about, however I must be making some error since the condition “button_pressed == NETFLIX” does not happen when I press that button.

type: custom:button-card
icon: mdi:netflix
show_name: false
tap_action:
  action: call-service
  service: script.remote_send_command
  data:
    button_pressed: NETFLIX

and the script…

alias: remote_send_command
fields:
  button_pressed:
    selector:
      text: null
    name: Button Pressed
    description: button_pressed is sent from the UI Tap Action
    required: true
sequence:
  - if:
      - condition: template
        value_template: >-
          (button_pressed == NETFLIX) and
          is_state('input_select.tv_select','remote.samsung1_tv')
    then:
      - service: remote.send_command
        target:
          entity_id: "{{ states('input_select.tv_select') }}"
        data:
          command:
            - KEY_HOME
            - KEY_RIGHT
            - KEY_RIGHT
            - KEY_RIGHT
            - KEY_RIGHT
            - KEY_ENTER
    else:
      - service: remote.send_command
        target:
          entity_id: "{{ states('input_select.tv_select') }}"
        data:
          command: "{{my_command}}"
mode: single
icon: mdi:remote-tv

You need quotes around NETFLIX in your If action’s condition.

1 Like

It looks like you were missing the {around your if statement. I’ve corrected it above. I’m not sure what the formatting’s going to look like because I’m doing this on my phone.

Also… as already mentioned, you needed to quote the word Netflix.