Switch to switch between HDMI MAIN and SUB

I´m struggling with creating a simple switch that switches between the two outputs on my ONKYO receiver. In the end I would like to have a nice icon for this in lovelace showing a projector when hdmi main is selected and TV when hdmi sub is selected.
That´s why I thought input_boolean would be the right way to go instead of an input_select. But I do not get it to behave as expected, it toggles when I click it.
I tried to put a template switch in between but no go :cry:

Code:

input_boolean:
  onkyo_hdmi:
    name: Onkyo HDMI switch
    initial: on




automation:
# Change to SUB
  - alias: Set Onkyo HDMI SUB
    trigger:
      platform: state
      entity_id: input_boolean.onkyo_hdmi
      to: "off"
    condition:
    - condition: state
      entity_id: media_player.onkyo
      state: "on"
    action:
      - service: media_player.onkyo_select_hdmi_output
        data:
          entity_id: media_player.onkyo
          hdmi_output: out-sub
  - alias: Set Onkyo HDMI MAIN
    trigger:
      platform: state
      entity_id: input_boolean.onkyo_hdmi
      to: "on"
    condition:
    - condition: state
      entity_id: media_player.onkyo
      state: "on"
    action:
      - service: media_player.onkyo_select_hdmi_output
        data:
          entity_id: media_player.onkyo
          hdmi_output: out

Lovelace card:

color: auto
entity: input_boolean.onkyo_hdmi
icon: >-
  [[[ if (entity.state = "off") return "mdi:television-classic"; else return
  "mdi:projector" ]]]
name: '[[[ if (entity.state = "off") return "Hdmi TV"; else return "Projector" ]]]'
type: 'custom:button-card'

The automation itself works when testing it but maybe a script is more suitable?

Any ideas why this is not working or what would be the best approach?

Thanks!

it is because its not doing anything
you need to add the tap action

color: auto
entity: input_boolean.onkyo_hdmi
tap_action:
    action: call-service
    service: input_boolean.toggle
    service_data:
      entity_id: input_boolean.onkyo_hdmi
icon: >-
  [[[ if (entity.state = "off") return "mdi:television-classic"; else return
  "mdi:projector" ]]]
name: '[[[ if (entity.state = "off") return "Hdmi TV"; else return "Projector" ]]]'
type: 'custom:button-card'

Thank you, that actually seems to solve the automation functionality.
I thought toggle was default, reading the docs:

tap_action: “Define the type of action on click, if undefined, toggle will be used.”

I still have issues with the icon changing though, for some reason state is always “off” on the input_boolean.

EDIT: Think I found the error, missing a = in entity.state = “off”.
This actually set the status to off instead of checking state :upside_down_face:

Explains why when I was testing it mine kept toggling off :rofl:

can you post the code you ended up with. trying to do the same :slight_smile: and if you used helpers and such.