Using RX, TX as GPIO does not work even with baud_rate: 0

Hi, I need to use RX, TX pins as GPIO on TYWE2S (ESP-02S), but even though I turn off logging over UART something writes to those pins. Any idea? This is my configuration:

# Configuration
substitutions:
  name: esp-switch-2g-1

esphome:
  name: ${name}

esp8266:
  board: esp8285
  restore_from_flash: true

# Enable logging
logger:
  #Turn off RX T
  baud_rate: 0

# Enable Home Assistant API
api:
  encryption:
    key: !secret esp_home_api_password

ota:
  password: !secret esp_home_ota_password

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "${name} Fallback Hotspot"
    password: !secret esp_home_fallback_wifi_password

captive_portal:

button:
  - platform: factory_reset
    name: Resetování do továrního nastavení
    id: reset

output:
  - platform: gpio
    pin: GPIO4
    id: relay1
  - platform: gpio
    pin: GPIO5
    id: relay2

light:
  - platform: status_led
    name: "${name} stavová LED"
    icon: mdi:led-on
    pin:
      number: GPIO12
      inverted: true

  - platform: binary
    name: "${name} světlo 1"
    icon: mdi:ceiling-light-multiple
    id: light1
    output: relay1
    restore_mode: RESTORE_DEFAULT_OFF
  
  - platform: binary
    name: "${name} světlo 2"
    icon: mdi:ceiling-light-multiple
    id: light2
    output: relay1
    restore_mode: RESTORE_DEFAULT_OFF

binary_sensor:
  # Wired switch 1
  - platform: gpio
    name: "${name} vypínač 1"
    icon: mdi:light-switch
    id: the_switch_1
    pin:
      number: RX
      mode: INPUT_PULLUP
      inverted: true
    on_state:
      - light.toggle: light1

  # Wired switch
  - platform: gpio
    name: "${name} vypínač 2"
    icon: mdi:light-switch
    id: the_switch_2
    pin:
      number: TX
      mode: INPUT_PULLUP
      inverted: true
    on_state:
      - light.toggle: light2

  # Button on mini switch
  - platform: gpio
    name: "${name} tlačítko"
    icon: mdi:gesture-tap-button
    pin:
      number: GPIO14
      mode: INPUT_PULLUP
      inverted: true
    on_multi_click:
      - timing:
          - ON for at most 1s
          - OFF for at least 0.2s
        then:
          - light.toggle: light1
          - light.toggle: light2
      - timing:
          - ON for at least 4s
        then:
          - button.press: reset

  - platform: status
    name: "${name} stav"

text_sensor:
  - platform: wifi_info
    ip_address:
      name: "${name} IP adresa"
      icon: mdi:ip-network

sensor:
  - platform: wifi_signal
    name: "${name} signál"
    update_interval: 10s
  
  - platform: uptime
    name: "${name} doba běhu"

time:
  - platform: sntp
    id: my_time  

Using RX and TX as inputs should be okay. The TX pin might have some output during boot loader but shouldn’t interfere with operation.

Try GPIO1 for TX and GPIO3 for RX.

You might have typo in light2 with relay1 instead of relay2.

Thanks for reply mulcmu, I have already tryed GPIO1, GPIO3 instead of TX, RX, but the result is still the same, the relays are turning on and off because state of GPIO1 (TX) and GPIO3 (RX) changes. Something has to be writing there but I can not find what. I have to use these pins because I have retrofitted esp-02s to Aubess 2 gang switch which is using these pins as inputs for switch buttons.

I have also saw on YT that the function of the pin should be changed, to FUNCTION3, this was done in arduino code, not sure if this is possible in esphome.

pinMode(1, FUNCTION_3);
pinMode(3, FUNCTION_3);

Logs:

[08:37:35][D][binary_sensor:036]: 'esp-switch-2g-1 vypínač 1': Sending state ON
[08:37:35][D][binary_sensor:036]: 'esp-switch-2g-1 vypínač 1': Sending state OFF
[08:37:36][D][binary_sensor:036]: 'esp-switch-2g-1 vypínač 1': Sending state ON
[08:37:36][D][binary_sensor:036]: 'esp-switch-2g-1 vypínač 1': Sending state OFF
[08:37:36][D][binary_sensor:036]: 'esp-switch-2g-1 vypínač 1': Sending state ON
[08:37:36][D][binary_sensor:036]: 'esp-switch-2g-1 vypínač 1': Sending state OFF
[08:37:36][D][binary_sensor:036]: 'esp-switch-2g-1 vypínač 1': Sending state ON
[08:37:36][D][binary_sensor:036]: 'esp-switch-2g-1 vypínač 1': Sending state OFF
[08:37:37][D][binary_sensor:036]: 'esp-switch-2g-1 vypínač 2': Sending state ON
[08:37:37][D][light:035]: 'esp-switch-2g-1 světlo 2' Setting:
[08:37:37][D][light:046]:   State: ON
[08:37:37][D][binary_sensor:036]: 'esp-switch-2g-1 vypínač 2': Sending state OFF
[08:37:37][D][light:035]: 'esp-switch-2g-1 světlo 2' Setting:
[08:37:37][D][light:046]:   State: OFF
[08:37:37][D][binary_sensor:036]: 'esp-switch-2g-1 vypínač 2': Sending state ON
[08:37:37][D][light:035]: 'esp-switch-2g-1 světlo 2' Setting:
[08:37:37][D][light:046]:   State: ON
[08:37:37][D][binary_sensor:036]: 'esp-switch-2g-1 vypínač 2': Sending state OFF
[08:37:37][D][light:035]: 'esp-switch-2g-1 světlo 2' Setting:
[08:37:37][D][light:046]:   State: OFF
[08:37:37][D][binary_sensor:036]: 'esp-switch-2g-1 vypínač 1': Sending state ON
[08:37:37][D][binary_sensor:036]: 'esp-switch-2g-1 vypínač 1': Sending state OFF
[08:37:37][D][binary_sensor:036]: 'esp-switch-2g-1 vypínač 1': Sending state ON
[08:37:37][D][binary_sensor:036]: 'esp-switch-2g-1 vypínač 1': Sending state OFF
[08:37:38][D][binary_sensor:036]: 'esp-switch-2g-1 vypínač 1': Sending state ON
[08:37:38][D][binary_sensor:036]: 'esp-switch-2g-1 vypínač 1': Sending state OFF
[08:37:38][D][binary_sensor:036]: 'esp-switch-2g-1 vypínač 1': Sending state ON
[08:37:38][D][binary_sensor:036]: 'esp-switch-2g-1 vypínač 1': Sending state OFF
[08:37:38][D][binary_sensor:036]: 'esp-switch-2g-1 vypínač 2': Sending state ON
[08:37:38][D][light:035]: 'esp-switch-2g-1 světlo 2' Setting:
[08:37:38][D][light:046]:   State: ON
[08:37:38][D][binary_sensor:036]: 'esp-switch-2g-1 vypínač 2': Sending state OFF
[08:37:38][D][light:035]: 'esp-switch-2g-1 světlo 2' Setting:
[08:37:38][D][light:046]:   State: OFF
[08:37:38][D][binary_sensor:036]: 'esp-switch-2g-1 vypínač 2': Sending state ON
[08:37:38][D][light:035]: 'esp-switch-2g-1 světlo 2' Setting:
[08:37:38][D][light:046]:   State: ON
[08:37:38][D][binary_sensor:036]: 'esp-switch-2g-1 vypínač 2': Sending state OFF
[08:37:38][D][light:035]: 'esp-switch-2g-1 světlo 2' Setting:
[08:37:38][D][light:046]:   State: OFF

New configuration:

# Configuration
substitutions:
  name: esp-switch-2g-1

esphome:
  name: ${name}

esp8266:
  board: esp8285
  restore_from_flash: true

# Enable logging
logger:
  #Turn off RX TX
  baud_rate: 0

# Enable Home Assistant API
api:
  encryption:
    key: !secret esp_home_api_password

ota:
  password: !secret esp_home_ota_password

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "${name} Fallback Hotspot"
    password: !secret esp_home_fallback_wifi_password

captive_portal:

button:
  - platform: factory_reset
    name: Resetování do továrního nastavení
    id: reset

output:
  - platform: gpio
    pin: GPIO4
    id: relay1
  - platform: gpio
    pin: GPIO5
    id: relay2

light:
  - platform: status_led
    name: "${name} stavová LED"
    icon: mdi:led-on
    pin:
      number: GPIO12
      inverted: true

  - platform: binary
    name: "${name} světlo 1"
    icon: mdi:ceiling-light-multiple
    id: light1
    output: relay1
    restore_mode: RESTORE_DEFAULT_OFF
  
  - platform: binary
    name: "${name} světlo 2"
    icon: mdi:ceiling-light-multiple
    id: light2
    output: relay2
    restore_mode: RESTORE_DEFAULT_OFF

binary_sensor:
  # Wired switch 1
  - platform: gpio
    name: "${name} vypínač 1"
    icon: mdi:light-switch
    id: the_switch_1
    pin:
      number: GPIO1
      mode: INPUT_PULLUP
      inverted: true
    on_state:
      - light.toggle: light1

  # Wired switch
  - platform: gpio
    name: "${name} vypínač 2"
    icon: mdi:light-switch
    id: the_switch_2
    pin:
      number: GPIO3
      mode: INPUT_PULLUP
      inverted: true
    on_state:
      - light.toggle: light2

  # Button on mini switch
  - platform: gpio
    name: "${name} tlačítko"
    icon: mdi:gesture-tap-button
    pin:
      number: GPIO14
      mode: INPUT_PULLUP
      inverted: true
    on_multi_click:
      - timing:
          - ON for at most 1s
          - OFF for at least 0.2s
        then:
          - light.toggle: light1
          - light.toggle: light2
      - timing:
          - ON for at least 4s
        then:
          - button.press: reset

  - platform: status
    name: "${name} stav"

text_sensor:
  - platform: wifi_info
    ip_address:
      name: "${name} IP adresa"
      icon: mdi:ip-network

sensor:
  - platform: wifi_signal
    name: "${name} signál"
    update_interval: 10s
  
  - platform: uptime
    name: "${name} doba běhu"

time:
  - platform: sntp
    id: my_time  

Ok, it seems to be some HW problem, when I deployed the code on another Aubess 2 gang switch it works. Just to note, there was originally different board which I switched for esp-02s. The FL_MM99_V3 is the problematic one. Everything seams to be working there, it even registers the switch inputs on the RX and TX pins, but there is just noise on them as well causing lights flickering.

BTW it is strange that the FL_MM99_V3 has different pin out printed on it, but it corresponds to the another board when I measured it.

Just for completeness, the FL_MM99_V3 board seams to be in the wifi + bluetooth variant of this switch.


A filter might help with electrical noise on the binary_sensors.

    filters:
      - delayed_on_off: 100ms

Thanks, I will try and let you know if it helped. Do you have any idea what might be causing it?