What is ideal method to created a command line switch to recall state

I have several command line switches configured. I use them in a custom way. Some are a normal on off where as some are simply used to run 1 command using the on button and a separate command that is run by the off button. This has allowed me to create some custom switches to do what I want using command line. These are almost all completely IP control to operate either a TV or a Yamaha Receiver. I will show some examples as I go along.

This first photo shows a card I use in my master Bedroom for TV operations:

Power off is a simple On and Off button used
Apple TV / TiVo is an HDMI input 1 and 2; Off = Apple TV (HDMI 1) and On = Tivo (HDMI 2)
Sleep 30 /60 is: Off = 30 min Sleep timer ; On = 60 min Sleep timer
Sleep 90 /120 is: Off = 90 min Sleep timer ; On = 120 min Sleep timer

I wanted to help all understand how I use some of these command line switches to accomplish my goals.

The above card works 100% as I need and want it to without need for anything. It is simply an example to help communicate how I use it which comes into play with the following.

I am about to show you my Sirius Presets card I use. The first photo I will show is completely with everything showing off. Instead of using the on off for two separate lightning bolts (one for off and one for on) I am using a toggle on/off by using assumed_state: false within the switch in the customization file. I will follow the photo with a detailed explanation of its use:

Sirius All Off:

Here is an example of the power command line switch and the 1st preset:

patio_power:
  command_on: echo -e "@MAIN:PWR=Standby" | nc 192.168.xxx.xxx 50000
  command_off: echo -e "@MAIN:PWR=On" | nc 192.168.xxx.xxx 50000
  friendly_name: Power Off
patio_sir1:
  command_on: echo -e "@SIRIUSXM:PRESET=1\r\n" | nc 192.168.xxx.xxx 50000
  command_off: echo -e "@SIRIUSXM:PRESET=1\r\n" | nc 192.168.xxx.xxx 50000
  friendly_name: 80's on 8

The power switch has two separate commands: one for on and off.
The SiriusXM presets are the same command whether using on or off for a single preset SiriusXM channel. I have a total of 7 Presets and the one Power button.

The power button works exactly how I want with no suggestions needed. I simply turn it on or off and the toggle will represent its proper state.

It is with the Presets which I seek ideas or suggestions from the community. When I toggle a preset whether from on or off for the same Preset it will toggle the icon to either on or off based on how many times it is pressed. What I am wanting to do is find a method to remember what preset was last selected. The issue is let’s say I start by selecting a single channel such as 80’s on 8. The toggle will reflect on and turn blue and the other MDI icon is yellow. I want this to be the case for just 1 channel at a time. However when I change to an alternate channel such as Road Trip Radio, now I have multiple channels showing as on. Below is a photo showing multiple channels being on; it reflects the power of A/V being on with several Presets showing on (or active in my case):

Sirius Unfortunate Reality:

This is what I would prefer to be shown at any given time:

Sirius Ideal:

The above shows the power state of the Patio A/V equipment. It also shows one active Preset.

The assistance I am seeking is the best method to this. Ideally I am always starting from blank showing all presets off and the A/V system as off. I turn on the A/V and its state shows as expected. I will then tune a Preset such as 1 and that shows as on. Once pressed I want it to stay on until I select a different preset. Let’s say I then press Preset 3. I want some type of method to know to now turn Preset to an Off State and turn Preset 3 to an On State. Then when pressing each subsequent Preset it turns the newly selected one to On State and also turns the previous one to an Off State.

In the end I want to always show the Power State On and only 1 Active Preset at a time. This way when we are viewing the Sirius Preset card we always know what channel is tuned. I wasn’t sure if this is a job for the input boolean which I can say I know next to nothing about. I did some reading and felt maybe this is my answer. Additionally my receiver does offer a method to get the channel via IP control. I don’t know if Hassio has a way of receiving the GET response from the receiver and storing its information. Or a method to display that channel information on a card. Any tips or reference to HELP on such capabilities is appreciated.

I know this was a lot of information. I wanted to ensure I was able to effectively communicate my goal and present how I am using the command line switch which may be a but unconventional. If you read all of this post to this post, thank you! I appreciate any and all help you may be able to suggest and or offer.

One idea I thought I may try is just a simple automation. When the switch is turned on, send a command to turn off the other 6 switches. This may be simple enough to do since I only am using 7 presets. I was hoping for a more universal/cleaner way to do it when adding more switches for additional Presets.

Well sometimes thinking and typing out a question in details gives the brain a jump start. Well I kept thinking and came up with a pretty simple solution. It may not be the most eloquent but it just works and does exactly what I am wanting while using a command line switch. I wanted to share with others whom may search a similar topic in the future and this may apply to them.

As indicated earlier I was using a command line switch for the IP Command sent to my Yamaha Receiver. I was sending the same command to tune the pre-set for both on or off. So every time it was toggled it would tune that same preset. I decided that I can simply only send the desired IP command using the ON button. I changed the OFF button to simply send a blank space. Which in turn is ignored by the Yamaha receiver and does absolutely nothing. This is the code for that command line switch:

    patio_sir1:
      command_on: echo -e "@SIRIUSXM:PRESET=1\r\n" | nc 192.168.xxx.xxx 50000
      command_off: echo -e " " | nc 192.168.xxx.xxx 50000
      friendly_name: 80's on 8

The next thing I did was create an automation. The automation is triggered by the newly tuned preset being in the ON state for 3 seconds. Once it senses it is now ON for 3 seconds, it then sends an off command for every one of the other PRESETS on the card that I am managing. Since I have 7 PRESETS total, each automation sends 6 separate OFF commands for all PRESETS except the current one being activated. So you do see two PRESETS showing as ON or active for about 3-5 seconds before it updates and you see it change to OFF. The card now operates fully as I would want.

The Automation:

- id: 'Sirius Preset 4'
  alias: Patio Sirius Preset 4 State
  trigger:
  - entity_id: switch.patio_sir4
    platform: state
    to: 'on'
    for: 00:00:03
  condition: []
  action:
  - data:
     entity_id: switch.patio_sir1
    service: switch.turn_off
  - data:
     entity_id: switch.patio_sir2
    service: switch.turn_off
  - data:
     entity_id: switch.patio_sir3
    service: switch.turn_off
  - data:
     entity_id: switch.patio_sir5
    service: switch.turn_off
  - data:
     entity_id: switch.patio_sir6
    service: switch.turn_off
  - data:
     entity_id: switch.patio_sir7
    service: switch.turn_off
  initial_state: true

I am still open to the discussion of other ways that may be cleaner or shorter. Or less clumsy. I am also interested to find out how to have it GET the channel info and displayed within the card. I know it is possible. The Yamaha auto discovery for the Media Player actively shows the song information from Sirius. It shows the song name, Artist and the Year. I am sure I could GET the information for the SONG and the Channel. That would be wonderful to figure out how to receive the response and display it on a card like the Media Player does. That may be too much customization.