Switch.rpi_gpio: how to invert_logic for only some of the ports?

Hello,

I have wired 3 of 8 relays to my RPi zero in the way that they are disabled most of the time and only when there is a HIGH on the GPIO - only then are those 3 relays activated (contrary to the rest of the relays which are activated on LOW). The 3 ports are 2, 4, 27. Here is the configuration:

switch:
  - platform: rpi_gpio
    ports:
      2: Radiator
      invert_logic: true
      3: Sockets
      4: IrrigationBalcony
      invert_logic: true
      14: ToiletsLight
      15: AirConditioning
      17: Plata
      18: Lights
      27: IrrigationLivingRoom
      invert_logic: true

The above doesn’t work. What is the proper way to invert_logic only of a subset of the ports?

Thank you!

I am not familiar with GPIO, but could there be a relationship to the pull_mode setting?

So how should my configuration look like?

Thank you!

Untested best guess:

switch:
  - platform: rpi_gpio
    ports:
      3: Sockets
      14: ToiletsLight
      15: AirConditioning
      17: Plata
      18: Lights

  - platform: rpi_gpio
    ports:
      2: Radiator
      4: IrrigationBalcony
      27: IrrigationLivingRoom
      invert_logic: true

1 Like

@tom_l: Thank you very much! I just had to change it slightly and it worked:

...

  - platform: rpi_gpio
    invert_logic: true
    ports:
      2: Radiator
      4: IrrigationBalcony
      27: IrrigationLivingRoom
1 Like

@tom_l - I have been using your solution for quite a long now and it worked perfect. Now I decided to move one of the gpios (15: AirConditioning) to the “inverted_logic” group so I restarted HA after rewriting my configuration.yaml as follows:

switch:
  - platform: rpi_gpio
    invert_logic: true
    ports:
      2: Radiator
      4: IrrigationBalcony
      15: AirConditioning
      22: IrrigationLivingRoom

  - platform: rpi_gpio
    ports:
      14: ToiletsLight
      17: Plata
      18: Lights
      27: Sockets

After HA restart “15: AirConditioning” indeed didn’t turn on which is what I want. However in the Frontend UI it is displayed as “turned on” while it is actually “off”. If I toggle it - it turns on but is displayed as OFF in the UI. How can I sync these two things?

Thank you!

Try restarting the host (softly - i.e. from the supervisor system page).

I don’t have a supervisor, since I run a docker-based HA, but I did a soft server restart as follows: Configuration → Server Controls → Server management → Restart

but it didn’t help :frowning:

Any ideas? Thank you!

Nope. Sorry. That’s all I had.