Ventilation System rpi_gpio turn switch off if another is turned on

I have a Ventilation System that runs with a physical switch that turns from 0, 1, 2, 3 each increasing the speed of the system. Now I want to replace this physical switch with a relay controlled by home assistant. I have come so far to know how to add the rpi_gpio switches to my configuration.yaml and see them on my dashboard. In this way I can turn them all on or off.
But now I want to make sure that only one of the three switches may be turned on.
Goal:
when turning on switch 1, then 2 and 3 should be turned off.
when turning on switch 2, then 1 and 3 should be turned off.
when turning on switch 3, then 1 and 2 should be turned off.

I have already added a helper that has the four desired values and i can slide between them.
How do I get the helper to control my switches now?

I have tried implementing a disable switch boolean when other is turned on from this topic: Disable a switch if another switch is turned on
But I seem to not be able to implement it right. If I try putting the code in my configuration.yaml I get errors about the syntax.

So I have tried different ways on achieving my goal. But failed so far. Please help. I’m pretty new to Home Assistant.
Do you have a better idea for my topic?

Thanks in advance.

My specs running on a Raspberry Pi Zero (Only one I have at the moment)
core-2021.11.5
supervisor-2021.10.8
Host: Home Assistant OS 6.6

So I have managed to answer the question myself using number helpers and automations.

Here is my code in configurationfile.yaml for one helper and one switch as example.

#Helper, that is a slider.
input_number:
  zuluft:
    name: Zuluft
    icon: mdi:air-conditioner
    initial: 0
    min: 0
    max: 3
    step: 1

#Automation takes helper value and switch as trigger and turns all other switches off
automation Zuluft 0:
  alias: zulufts_0
  description: ''
  trigger:
  - platform: numeric_state
    entity_id: input_number.zuluft
    below: '0.1'
  condition: []
  action:
  - service: homeassistant.turn_off
    target:
      entity_id:
      - switch.zuluft_1
      - switch.zuluft_2
      - switch.zuluft_3
  mode: single
automation Zuluft 1:
  alias: zulufts_1
  description: ''
  trigger:
  - platform: numeric_state
    entity_id: input_number.zuluft
    above: '0.9'
    below: '1.1'
  - platform: state
    entity_id: switch.zuluft_1
    to: 'on'
  condition: []
  action:
  - service: homeassistant.turn_off
    target:
      entity_id:
      - switch.zuluft_2
      - switch.zuluft_3
  - service: homeassistant.turn_on
    target:
      entity_id: switch.zuluft_1
  - service: input_number.set_value
    target:
      entity_id: input_number.zuluft
    data:
      value: 1
  mode: single
#This automation Zuluft 1 needs to be duplicated and adjusted for the other switches.

I hope this helps someone building their own switch that turnes another of when acitvated.

Here is it, how it works. :slight_smile:

slider and switch

It can be done with one automation and one input number.

input_number:
  zuluft:
    name: Zuluft
    icon: mdi:air-conditioner
    initial: 0
    min: 0
    max: 3
    step: 1
  trigger:
  - platform: state # trigger on any change of the input number
    entity_id: input_number.zuluft
  action:
  - service: switch.turn_off
    target:
      entity_id:
      - switch.zuluft_1
      - switch.zuluft_2
      - switch.zuluft_3
  - condition: numeric_state # stop here with all switches off if input number = 0
    entity_id: input_number.zuluft
    above: 0
  - service: switch.turn_on # otherwise turn the required switch on
    target:
      entity_id: "switch.zuluft_{{ states('input_number.zuluft')|int }}"

Thanks tom_l for that advice that works great with the slider.

But I also wanted to make sure no one can accidentally trigger multiple switches at once. That is why I included code, in my automations, to adjust the input number and to turn off all other switches.

Can I achieve this in your one automation as well?

Then I would add the other triggers like so

  trigger:
  - platform: state # trigger on any change of the input number
    entity_id: input_number.zuluft
  - platform: state
    entity_id: switch.zuluft_1
    to: 'on'
  - platform: state
    entity_id: switch.zuluft_2
    to: 'on'
  - platform: state
    entity_id: switch.zuluft_3
    to: 'on'

But how can I set the service for my input number?
In my automations, that I made, I knew exactly when switch 1 was pressed and then adjusted the input number like so.

  - service: input_number.set_value
    target:
      entity_id: input_number.zuluft
    data:
      value: 1

How can I know what switch is pressed in the service section, if I want to use your one automation method?
Can you help me there too?
Sincerely

Don’t expose the switches on the frontend, only the slider.

I don’t know what physical switches/relays you are using but if you use two physical toggle switches and put the first speed on the normal closed of the first, the open of the first to the input of the second switch and the speed 2 on the normal closed of the second and speed 3 on the open of the second, in this case you only need two relays/switches and you can never activate two speeds… This is how also blinds are typically wired…

Don’t trust on software not to mess up :wink: