Sonoff R4 mini S1 and S2 sensor entities

Hello All!

My problem is that I can not make a binary sensor to work for the Sonoff R4 mini smart switch. If i use this wiring everything is fine, i can see the switching binary entity in home assistant using the GPIO27 when i short S1 and S2 with a wire (picture on the left, the working one): https://cdn.cnx-software.com/wp-content/uploads/2023/02/SONOFF-MINIR4-Wiring-instructions-720x436.jpg?lossy=1&ssl=1
But my bathroom is wired like here: https://europe1.discourse-cdn.com/standard21/uploads/ewelinkforum/original/2X/f/f8e778bf8f9dedb31906e7f3cf0da16c447d6f15.jpeg
In this case the binary swithc does not work, its always in off state, despite i use the same config file.
The device is flashed with esp32dev by Espressif Firmware: 2023.8.3
In this case when i turn on the physical wall mounted switch (live wire on, like in the second wiring picture) nothing happens.

Thanks in advance. by the way the config is:

substitutions:
  display_name: "minir4-esph"
  
esphome:
  name: "minir4-esph"

esp32:
  board: esp32dev
  framework:
    type: arduino
    
wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  ap: 
    ssid: ${display_name}_AP
    password: !secret wifi_password
    ap_timeout: 3min
  
    
captive_portal:

esp32_ble_tracker:
  scan_parameters:
    interval: 300ms
    window: 100ms
    active: true

bluetooth_proxy:
  active: true

logger:

ota:

api:
  
switch:
  - platform: gpio
    name: ${display_name} Relay
    pin:
      number: GPIO26
      inverted: false
    id: relay
    on_turn_on:
      - light.turn_on: relay_led
    on_turn_off:
      - light.turn_off: relay_led
  - platform: restart
    name: ${display_name} Restart

output:
  - platform: gpio
    pin: GPIO19
    inverted: True
    id: relay1_led_gpio

light:
  - platform: binary
    name: "Relay LED"
    id: relay_led
    internal: true    
    output: relay1_led_gpio

binary_sensor:
  - platform: gpio
    internal: true
    pin:
      number: GPIO27
      mode: INPUT_PULLUP
      inverted: false
    name: ${display_name} Switch
    on_state:
      - switch.toggle: relay
  - platform: gpio
    internal: true
    pin:
      number: GPIO0
      mode: INPUT_PULLUP
      inverted: false
    name: ${display_name} Button
    on_press:
      - switch.toggle: relay
  - platform: gpio
    name: "device phase is on"
    pin:
      number: GPIO0  
      mode: INPUT_PULLUP  
      inverted: false  
    internal: false  
  - platform: gpio
    name: "S1-S2 state"
    pin:
      number: GPIO27  
      mode: INPUT_PULLUP  
      inverted: false  
    internal: false 

Hi,

Were you able to find a solution for this? I have exact same issue.

EDIT, this works for me fine now:

#######################################
# Device specific Config Begins Below #
#######################################

status_led:
  pin:
    number: GPIO19
    inverted: true

output:
  # Physical relay on GPIO
  - platform: gpio
    pin: GPIO26
    id: relay_1

light:
  - platform: binary
    id: light_1
    name: ${device_name}
    restore_mode: restore_default_off
    output: relay_1

binary_sensor:
  - platform: gpio
    pin: GPIO00
    id: button
    filters:
      - invert:
      - delayed_off: 50ms
    on_press:
      - light.toggle:
          id: light_1

  - platform: gpio
    name: s1
    pin:
      number: GPIO27
      mode: INPUT_PULLUP
      inverted: true
    id: s1
    filters:
#      - invert:
      - delayed_off: 50ms
    on_press:
      then:
        - light.toggle:
            id: light_1


I am having the exact same problem with Tasmota. Do you have any idea what resolved the problem exactly?