Simplify thing / item configuration for HDMI Switch

Hi everyone. I have a question if my current setup can be simplified.

I have a HDMI Switch connected by Tasmota MQTT.
This switch has 5 input ports which can be activated with MQTT.
To control them I have created 5 switch items.
I created rules to send the specific MQTT command based on the selected switch.
This rules are also disabling the other switches so only the current active input switch is ON.
Is there a possibility to simplify this?

Thing:

Group HDMI_Wohnzimmer “HDMI Switch Wohnzimmer” (Wohnzimmer) [“HDMI”, “Equipment”]
Switch HDMI_Wohnzimmer_Power “HDMI Switch” (HDMI_Wohnzimmer) [“Point”] {channel=“mqtt:topic:mosquitto:MQTT_HDMI_Wohnzimmer:Power”, ga=“Switch” [roomHint=“Wohnzimmer”]}
String HDMI_Wohnzimmer_Value “Aktueller Wert” (HDMI_Wohnzimmer) [“Point”] {channel=“mqtt:topic:mosquitto:MQTT_HDMI_Wohnzimmer:Value”}
String HDMI_Wohnzimmer_Input “Input [%s]” (HDMI_Wohnzimmer) [“Point”] {channel=“mqtt:topic:mosquitto:MQTT_HDMI_Wohnzimmer:Input”}

Items:

Switch HDMI_Switch_1
Switch HDMI_Switch_2
Switch HDMI_Switch_3
Switch HDMI_Switch_4
Switch HDMI_Switch_5

rules:

rule “HDMI Switch 1”
when
Item HDMI_Switch_1 changed
then
if(HDMI_Switch_1.state == ON){
HDMI_Wohnzimmer_Input.sendCommand(“port0R”)
HDMI_Switch_2.sendCommand(OFF)
HDMI_Switch_3.sendCommand(OFF)
HDMI_Switch_4.sendCommand(OFF)
HDMI_Switch_5.sendCommand(OFF)
} else {
Kodi.sendCommand(OFF)
}
end

rule “HDMI Switch 2”
when
Item HDMI_Switch_2 changed
then
if(HDMI_Switch_2.state==ON){
HDMI_Wohnzimmer_Input.sendCommand(“port1R”)
HDMI_Switch_1.sendCommand(OFF)
HDMI_Switch_3.sendCommand(OFF)
HDMI_Switch_4.sendCommand(OFF)
HDMI_Switch_5.sendCommand(OFF)
}
end

rule “HDMI Switch 3”
when
Item HDMI_Switch_3 changed
then
if(HDMI_Switch_3.state==ON){
HDMI_Wohnzimmer_Input.sendCommand(“port2R”)
HDMI_Switch_1.sendCommand(OFF)
HDMI_Switch_2.sendCommand(OFF)
HDMI_Switch_4.sendCommand(OFF)
HDMI_Switch_5.sendCommand(OFF)
}
end

rule “HDMI Switch 4”
when
Item HDMI_Switch_4 changed
then
if(HDMI_Switch_4.state==ON){
HDMI_Wohnzimmer_Input.sendCommand(“port3R”)
HDMI_Switch_1.sendCommand(OFF)
HDMI_Switch_2.sendCommand(OFF)
HDMI_Switch_3.sendCommand(OFF)
HDMI_Switch_5.sendCommand(OFF)
}
end

rule “HDMI Switch 5”
when
Item HDMI_Switch_5 changed
then
if(HDMI_Switch_5.state==ON){
HDMI_Wohnzimmer_Input.sendCommand(“port4R”)
HDMI_Switch_1.sendCommand(OFF)
HDMI_Switch_2.sendCommand(OFF)
HDMI_Switch_3.sendCommand(OFF)
HDMI_Switch_4.sendCommand(OFF)
}
end

Could you use a string item with mappings ie INPUT1, INPUT2 etc?
Then 1 rule to send the commands to the mqqt channel based on what the string is changed to?
Not familiar with mqqt but might not even need the rule if the mappings are done like INPUT2=commandtosend

Look here:

Please How to use code fences

How do you represent these on your sitemap? How do you want to? For example, to follow Dave’s suggestion you can use:

Switch item=HDMI_Switch label="HDMI Control [%s]" mappings=[port0R="One", port1R="Two", port2R="Three", port3R="Four", port4R="Five"]

That will give you one element on the sitemap with four buttons labeled One, Two, Three, or Four. When you click one of the buttons it will send “portXR” as the command to the Item where X is the number of the button pressed.

I’m assuming that nothing happens when you set your existing HDMI_Switch Items to OFF.

Create HDMI_Switch as a String Item. And in fact, link that Item to the Channel that sends the command since the message is already what the device needs.

Then create a single Rule:

rule "HDMI_Switch"
when
    Item HDMI_Switch received command port0R
then
    Kodi.sendCommand(OFF)
end

That’s it. You only have the one Item so you don’t need to maintain the states of five different switches. Telling which input is enabled will be apparent from the highlighting on the buttons on the sitemap. And you only do something different (turn off the Kodi) when the Switch 1 is turned ON.