Open drain output and binary sensor at the same pin

I have been trying put together a similar solution for anohter setup, posted about it here:

Didn’t get any hints but worked my way to be able to change pinmode at runtime and execute reads and write in sequence to the same pin, maybe you could have use for my code:

binary_sensor:
- platform: gpio
  name: "ingang5"
  id: in5
  pin:
    id: in_pin_5
    number: GPIO5
    allow_other_uses: true
    mode: INPUT_PULLUP
    inverted: true

output:
- platform: gpio
  id: out5
  pin:
    id: out_pin_5
    number: GPIO5
    allow_other_uses: true
    inverted: true

button:
- platform: template
  name: "toggel pin 5"
  on_press:
    - logger.log: Button Pressed

    - lambda: |-
        id(out_pin_5)->pin_mode(gpio::FLAG_OUTPUT);
        id(out5)->setup();
    - output.turn_on: out5

    - delay: 10ms

    - lambda: |-
        id(in_pin_5)->pin_mode(gpio::FLAG_INPUT);
        id(in5)->setup();
2 Likes