Creating a switch based on the media_player platform

I would like to make my own switches to call for a few media_player options - pioneer, and panasonic viera. This would be especially useful within the ‘Custom UI Tiles’ by @eddi89 - but I don’t quite know how to leverage the media_player platform to achieve that.

Has anyone successfully achieved this? Or (I suspect) is there a smarter way to go about this?

Thanks in advance!
Matt

My stab (from a switch.yaml):

- platform: media_player
  switches:
    pioneer_powertoggle:
      command_on: media_player.lounge_vsx.turn_on
      command_off: media_player.lounge_vsx.turn_off
      state: media_player.lounge_vsx.state

Seems this is what I was after: chanced on a ‘template switch’ after hitting google for the nth time… maybe this will help someone else :slight_smile:

- platform: template
  switches:
    pioneer_powertoggle:
      value_template: "{% if is_state('media_player.lounge_vsx', 'on') %}on{% else %}off{% endif %}"
      turn_on:
        service: media_player.turn_on
        data:
          entity_id: media_player.lounge_vsx
      turn_off:
        service: media_player.turn_off
        data:
          entity_id: media_player.lounge_vsx
4 Likes

I also wanted to pass this on; as Kodi has a number of ‘states’ indicating it is ‘on’ (such as idle, playing etc.) the best way to deduce the state for this switch is using “not off”. This is achieved like this (not the 'not is_state) - hopefully this helps someone too:

loungekodi_powertoggle:
  value_template: "{% if (not is_state('media_player.lounge_kodi', 'off')) %}on{% else %}off{% endif %}"
  turn_on:
    service: media_player.turn_on
    data:
      entity_id: media_player.lounge_kodi
  turn_off:
    service: switch.turn_off
    data:
      entity_id: switch.bedroom_kodi_sleep
2 Likes