Switching 1 relais on and 3 relais off

This week i started working with ESPHome and i am quite impressed so far in programming esp32 microcontroller OTA.
I made some progress and integrated 4 relais so far and i can toggle them on and off individually. that works fine.
For my task i want to switch one of the 4 relais on and want ESPHome switching off the other 3 automatically. This works with automations i guess. But i am not sure if the best way to do this is in the ESPHome.yaml or create an automation in home assistant.

Also i am not sure with the code, when its in the ESPHome.yaml. And how it is possible not to use this sliders for relais 1, 2, 3 or 4 but use some kind of radio-button, to set Option 1, 2, 3 or 4.

Can somebody help me out with this? Thanks you!!!


Closest thing to a radio button:

Unfortunately this only works for two outputs:


I thinks its best to put the automation directly on the esp board that is controlling the relays. If you look through the documentation, it gives you lots of examples. Like this one for example. This is very close to what you are looking for. So, when switch1 turns on (on_turn_on) then turn off 2,3,4

    - switch.turn_off: relay1
    - switch.turn-off: relay2
    - switch.turn_off: relay3

I had to look up what a “radio-button” was so, you taught me something today!

Actually there is no best way. It depends on You.

You can keep ESPHome devices configuration as simple as possibe - using HA for automations.
Another way - do as much as possible locally on devices, using HA for inter-device operations.

Ya, theres a best way for most esphome projects. If theres a problem with HA, your esphome automations can still run. They cant run if you put them all on HA and it fails.