Aubess Switch OFF ON randomly BK7231N BL9042 CB2S

Hello @all,

I flashed a Tuya Smart Switch to OpenBeken. After that I configure the pins. If I configure the PIN24 to TglChanONTgl the switched started randomly switching off and on. So I went to ESPHome and flashed the device with ESPHome.

esphome:
  name: licht-eltern-esp
  name_add_mac_suffix: true

bk72xx:
  board: generic-bk7231n-qfn32-tuya

logger:

web_server:

captive_portal:

mdns:

api:
  password: ""

ota:
  platform: esphome
  password: ""

wifi:
  ssid: techniks2
  password: ******
  manual_ip:
    # Set this to the IP of the ESP
    static_ip: 192.168.0.125
    # Set this to the IP address of the router. Often ends with .1
    gateway: 192.168.0.1
    # The subnet of the network. 255.255.255.0 works for most home networks.
    subnet: 255.255.255.0
  ap:

button:
  - platform: restart
    name: Restart

debug:
  update_interval: 5s

text_sensor:
  - platform: debug
    reset_reason:
      name: Reset Reason
  - platform: libretiny
    version:
      name: LibreTiny Version

sensor:
  - platform: uptime
    name: Uptime
  - platform: bl0942
    uart_id: uart_bus
    current:
      name: BL0942 Current
    voltage:
      name: BL0942 Voltage
    power:
      name: BL0942 Power
      filters:
        multiply: -1
    energy:
      name: BL0942 Energy
    frequency:
      name: BL0942 Frequency
      accuracy_decimals: 2

binary_sensor:
  - platform: gpio
    id: binary_onoff_1
    pin:
      number: P24
      inverted: true
      mode: INPUT_PULLDOWN
    on_state:
      then:
        - switch.toggle: switch_1
  - platform: gpio
    id: binary_switch_all
    pin:
      number: P23
      inverted: true
      mode: INPUT_PULLUP
    on_press:
      then:
        - switch.toggle: switch_1

switch:
  - platform: gpio
    id: switch_1
    name: Relay 1
    pin: P26

status_led:
  pin:
    number: P8
    inverted: true

uart:
  id: uart_bus
  tx_pin: P11
  rx_pin: P10
  baud_rate: 4800
  stop_bits: 1

Now I get a connection and HA see the device but the switch is still switching randomly between ON and OFF.

Linking .pioenvs/licht-eltern-esp/raw_firmware.elf
|-- Image 1: raw_firmware.elf
|   |-- image_bk7231n_app.0x011000.rbl
|   |   |-- raw_firmware.bin
|   |-- image_bk7231n_app.0x011000.crc
|   |-- image_bk7231n_app.0x129F0A.rblh
|   |-- image_bk7231n_app.ota.rbl
|   |-- image_bk7231n_app.ota.ug.bin
RAM:   [====      ]  36.4% (used 95492 bytes from 262144 bytes)
Flash: [========  ]  79.8% (used 864704 bytes from 1083136 bytes)
Building UF2 OTA image
|-- esphome_2025.3.2_generic-bk7231n-qfn32-tuya_bk7231n_lt1.7.0.uf2
|-- firmware.uf2
|-- firmware.bin
========================= [SUCCESS] Took 68.29 seconds =========================
INFO Successfully compiled program.
INFO Connecting to 192.168.0.125 port 8892...
INFO Connected to 192.168.0.125
INFO Uploading /data/build/licht-eltern-esp/.pioenvs/licht-eltern-esp/firmware.uf2 (2982912 bytes)
Uploading: [============================================================] 100% Done...

INFO Upload took 12.92 seconds, waiting for result...
INFO OTA successful
INFO Successfully uploaded program.
INFO Starting log output from 192.168.0.125 using esphome API
INFO Successfully connected to licht-eltern-esp @ 192.168.0.125 in 19.541s
INFO Successful handshake with licht-eltern-esp-f4da61 @ 192.168.0.125 in 0.021s
[08:23:21][I][app:100]: ESPHome version 2025.3.2 compiled on Mar 26 2025, 08:22:19
[08:23:21][C][status_led:019]: Status LED:
[08:23:21][C][status_led:020]:   Pin: 8
[08:23:21][C][wifi:600]: WiFi:
[08:23:21][C][wifi:428]:   Local MAC: 38:A5:C9:F4:DA:61
[08:23:21][C][wifi:433]:   SSID: 'techniks2'[redacted]
[08:23:21][C][wifi:436]:   IP Address: 192.168.0.125
[08:23:21][C][wifi:439]:   BSSID: 48:5D:35:C9:27:D6[redacted]
[08:23:21][C][wifi:441]:   Hostname: 'licht-eltern-esp-f4da61'
[08:23:21][C][wifi:443]:   Signal strength: -55 dB ▂▄▆█
[08:23:21][C][wifi:447]:   Channel: 7
[08:23:21][C][wifi:448]:   Subnet: 255.255.255.0
[08:23:21][C][wifi:449]:   Gateway: 192.168.0.1
[08:23:21][C][wifi:450]:   DNS1: 255.255.255.255
[08:23:21][C][wifi:451]:   DNS2: 255.255.255.255
[08:23:21][C][logger:177]: Logger:
[08:23:21][C][logger:178]:   Max Level: DEBUG
[08:23:21][C][logger:179]:   Initial Level: DEBUG
[08:23:21][C][logger:181]:   Log Baud Rate: 115200
[08:23:21][C][logger:182]:   Hardware UART: UART2
[08:23:21][C][uart.lt:101]: UART Bus:
[08:23:21][C][uart.lt:102]:   Type: hardware
[08:23:21][C][uart.lt:104]:   Port number: 1
[08:23:21][C][uart.lt:106]:   TX Pin: 11
[08:23:21][C][uart.lt:107]:   RX Pin: 10
[08:23:21][C][uart.lt:109]:   RX Buffer Size: 256
[08:23:21][C][uart.lt:111]:   Baud Rate: 4800 baud
[08:23:21][C][uart.lt:112]:   Data Bits: 8
[08:23:21][C][uart.lt:113]:   Parity: NONE
[08:23:21][C][uart.lt:114]:   Stop bits: 1
[08:23:21][C][uptime.sensor:033]: Uptime Sensor 'Uptime'
[08:23:21][C][uptime.sensor:033]:   Device Class: 'duration'
[08:23:21][C][uptime.sensor:033]:   State Class: 'total_increasing'
[08:23:21][C][uptime.sensor:033]:   Unit of Measurement: 's'
[08:23:21][C][uptime.sensor:033]:   Accuracy Decimals: 0
[08:23:21][C][uptime.sensor:033]:   Icon: 'mdi:timer-outline'
[08:23:21][C][uptime.sensor:034]:   Type: Seconds
[08:23:21][C][switch.gpio:068]: GPIO Switch 'Relay 1'
[08:23:21][C][switch.gpio:090]:   Restore Mode: always OFF
[08:23:21][C][switch.gpio:031]:   Pin: 26
[08:23:21][C][gpio.binary_sensor:015]: GPIO Binary Sensor 'binary_onoff_1'
[08:23:21][C][gpio.binary_sensor:016]:   Pin: 24
[08:23:21][C][gpio.binary_sensor:015]: GPIO Binary Sensor 'binary_switch_all'
[08:23:21][C][gpio.binary_sensor:016]:   Pin: 23
[08:23:21][C][restart.button:017]: Restart Button 'Restart'
[08:23:21][C][restart.button:017]:   Icon: 'mdi:restart'
[08:23:21][C][bl0942:199]: BL0942:
[08:23:21][C][bl0942:200]:   Reset: TRUE
[08:23:21][C][bl0942:201]:   Address: 0
[08:23:21][C][bl0942:202]:   Nominal line frequency: 50 Hz
[08:23:21][C][bl0942:203]:   Current reference: 251213.468750
[08:23:21][C][bl0942:204]:   Energy reference: 3304.611328
[08:23:21][C][bl0942:205]:   Power reference: 596.000000
[08:23:21][C][bl0942:206]:   Voltage reference: 15873.359375
[08:23:21][C][bl0942:207]: Voltage 'BL0942 Voltage'
[08:23:21][C][bl0942:207]:   Device Class: 'voltage'
[08:23:21][C][bl0942:207]:   State Class: 'measurement'
[08:23:21][C][bl0942:207]:   Unit of Measurement: 'V'
[08:23:21][C][bl0942:207]:   Accuracy Decimals: 1
[08:23:21][C][bl0942:208]: Current 'BL0942 Current'
[08:23:21][C][bl0942:208]:   Device Class: 'current'
[08:23:21][C][bl0942:208]:   State Class: 'measurement'
[08:23:21][C][bl0942:208]:   Unit of Measurement: 'A'
[08:23:21][C][bl0942:208]:   Accuracy Decimals: 2
[08:23:21][C][bl0942:209]: Power 'BL0942 Power'
[08:23:21][C][bl0942:209]:   Device Class: 'power'
[08:23:21][C][bl0942:209]:   State Class: 'measurement'
[08:23:21][C][bl0942:209]:   Unit of Measurement: 'W'
[08:23:21][C][bl0942:209]:   Accuracy Decimals: 1
[08:23:21][C][bl0942:210]: Energy 'BL0942 Energy'
[08:23:21][C][bl0942:210]:   Device Class: 'energy'
[08:23:21][C][bl0942:210]:   State Class: 'total_increasing'
[08:23:21][C][bl0942:210]:   Unit of Measurement: 'kWh'
[08:23:21][C][bl0942:210]:   Accuracy Decimals: 3
[08:23:21][C][bl0942:211]: Frequency 'BL0942 Frequency'
[08:23:21][C][bl0942:211]:   Device Class: 'frequency'
[08:23:21][C][bl0942:211]:   State Class: 'measurement'
[08:23:21][C][bl0942:211]:   Unit of Measurement: 'Hz'
[08:23:21][C][bl0942:211]:   Accuracy Decimals: 2
[08:23:21][C][captive_portal:089]: Captive Portal:
[08:23:21][C][web_server:285]: Web Server:
[08:23:21][C][web_server:286]:   Address: 192.168.0.125:80
[08:23:21][C][mdns:116]: mDNS:
[08:23:21][C][mdns:117]:   Hostname: licht-eltern-esp-f4da61
[08:23:21][C][esphome.ota:073]: Over-The-Air updates:
[08:23:21][C][esphome.ota:074]:   Address: 192.168.0.125:8892
[08:23:21][C][esphome.ota:075]:   Version: 2
[08:23:21][C][safe_mode:018]: Safe Mode:
[08:23:21][C][safe_mode:019]:   Boot considered successful after 60 seconds
[08:23:21][C][safe_mode:021]:   Invoke after 10 boot attempts
[08:23:21][C][safe_mode:022]:   Remain in safe mode for 300 seconds
[08:23:21][C][api:140]: API Server:
[08:23:21][C][api:141]:   Address: 192.168.0.125:6053
[08:23:21][C][api:145]:   Using noise encryption: NO
[08:23:22][C][lt.component:013]: LibreTiny:
[08:23:22][C][lt.component:014]:   Version: v1.7.0 on generic-bk7231n-qfn32-tuya, compiled at Mar 26 2025 08:21:59, GCC 10.3.1 (-O1)
[08:23:22][C][lt.component:015]:   Loglevel: 3
[08:23:22][D][text_sensor:064]: 'LibreTiny Version': Sending state 'v1.7.0 on generic-bk7231n-qfn32-tuya, compiled at Mar 26 2025 08:21:59, GCC 10.3.1 (-O1)'
[08:23:22][C][debug:021]: Debug component:
[08:23:22][D][debug:035]: ESPHome version 2025.3.2
[08:23:22][D][debug:039]: Free Heap Size: 27464 bytes
[08:23:22][D][debug:016]: LibreTiny Version: 1.7.0
[08:23:22][D][debug:017]: Chip: BK7231N (7b1c) @ 120 MHz
[08:23:22][D][debug:018]: Chip ID: 0x61DAF4
[08:23:22][D][debug:019]: Board: generic-bk7231n-qfn32-tuya
[08:23:22][D][debug:020]: Flash: 2048 KiB / RAM: 256 KiB
[08:23:22][D][debug:021]: Reset Reason: SW Reboot
[08:23:22][D][text_sensor:064]: 'Reset Reason': Sending state 'SW Reboot'
[08:23:23][D][binary_sensor:036]: 'binary_onoff_1': Sending state OFF
[08:23:23][D][switch:020]: 'Relay 1' Toggling ON.
[08:23:23][D][switch:055]: 'Relay 1': Sending state ON
[08:23:23][D][binary_sensor:036]: 'binary_onoff_1': Sending state ON
[08:23:23][D][switch:020]: 'Relay 1' Toggling OFF.
[08:23:23][D][switch:055]: 'Relay 1': Sending state OFF
[08:23:23][D][binary_sensor:036]: 'binary_onoff_1': Sending state OFF
[08:23:23][D][switch:020]: 'Relay 1' Toggling ON.
[08:23:23][D][switch:055]: 'Relay 1': Sending state ON
[08:23:24][D][binary_sensor:036]: 'binary_onoff_1': Sending state ON
[08:23:24][D][switch:020]: 'Relay 1' Toggling OFF.
[08:23:24][D][switch:055]: 'Relay 1': Sending state OFF
[08:23:24][D][binary_sensor:036]: 'binary_onoff_1': Sending state OFF
[08:23:24][D][switch:020]: 'Relay 1' Toggling ON.
[08:23:24][D][switch:055]: 'Relay 1': Sending state ON
[08:23:24][D][binary_sensor:036]: 'binary_onoff_1': Sending state ON
[08:23:24][D][switch:020]: 'Relay 1' Toggling OFF.
[08:23:24][D][switch:055]: 'Relay 1': Sending state OFF
[08:23:26][D][binary_sensor:036]: 'binary_onoff_1': Sending state OFF
[08:23:26][D][switch:020]: 'Relay 1' Toggling ON.
[08:23:26][D][switch:055]: 'Relay 1': Sending state ON
[08:23:26][D][binary_sensor:036]: 'binary_onoff_1': Sending state ON
[08:23:26][D][switch:020]: 'Relay 1' Toggling OFF.
[08:23:26][D][switch:055]: 'Relay 1': Sending state OFF
[08:23:26][D][binary_sensor:036]: 'binary_onoff_1': Sending state OFF
[08:23:26][D][switch:020]: 'Relay 1' Toggling ON.
[08:23:26][D][switch:055]: 'Relay 1': Sending state ON
[08:23:26][D][binary_sensor:036]: 'binary_onoff_1': Sending state ON
[08:23:26][D][switch:020]: 'Relay 1' Toggling OFF.
[08:23:26][D][switch:055]: 'Relay 1': Sending state OFF
[08:23:26][D][binary_sensor:036]: 'binary_onoff_1': Sending state OFF
[08:23:26][D][switch:020]: 'Relay 1' Toggling ON.
[08:23:26][D][switch:055]: 'Relay 1': Sending state ON
[08:23:26][D][binary_sensor:036]: 'binary_onoff_1': Sending state ON
[08:23:26][D][switch:020]: 'Relay 1' Toggling OFF.
[08:23:26][D][switch:055]: 'Relay 1': Sending state OFF
[08:23:28][D][binary_sensor:036]: 'binary_onoff_1': Sending state OFF
[08:23:28][D][switch:020]: 'Relay 1' Toggling ON.
[08:23:28][D][switch:055]: 'Relay 1': Sending state ON
[08:23:28][D][binary_sensor:036]: 'binary_onoff_1': Sending state ON
[08:23:28][D][switch:020]: 'Relay 1' Toggling OFF.
[08:23:28][D][switch:055]: 'Relay 1': Sending state OFF
[08:23:29][D][binary_sensor:036]: 'binary_onoff_1': Sending state OFF
[08:23:29][D][switch:020]: 'Relay 1' Toggling ON.
[08:23:29][D][switch:055]: 'Relay 1': Sending state ON
[08:23:29][D][binary_sensor:036]: 'binary_onoff_1': Sending state ON
[08:23:29][D][switch:020]: 'Relay 1' Toggling OFF.
[08:23:29][D][switch:055]: 'Relay 1': Sending state OFF
[08:23:30][D][binary_sensor:036]: 'binary_onoff_1': Sending state OFF
[08:23:30][D][switch:020]: 'Relay 1' Toggling ON.
[08:23:30][D][switch:055]: 'Relay 1': Sending state ON
[08:23:30][D][binary_sensor:036]: 'binary_onoff_1': Sending state ON
[08:23:30][D][switch:020]: 'Relay 1' Toggling OFF.
[08:23:30][D][switch:055]: 'Relay 1': Sending state OFF
[08:23:30][D][binary_sensor:036]: 'binary_onoff_1': Sending state OFF
[08:23:30][D][switch:020]: 'Relay 1' Toggling ON.
[08:23:30][D][switch:055]: 'Relay 1': Sending state ON
[08:23:30][D][binary_sensor:036]: 'binary_onoff_1': Sending state ON
[08:23:30][D][switch:020]: 'Relay 1' Toggling OFF.
[08:23:30][D][switch:055]: 'Relay 1': Sending state OFF
[08:23:31][D][binary_sensor:036]: 'binary_onoff_1': Sending state OFF
[08:23:31][D][switch:020]: 'Relay 1' Toggling ON.
[08:23:31][D][switch:055]: 'Relay 1': Sending state ON
[08:23:31][D][binary_sensor:036]: 'binary_onoff_1': Sending state ON
[08:23:31][D][switch:020]: 'Relay 1' Toggling OFF.
[08:23:31][D][switch:055]: 'Relay 1': Sending state OFF
[08:23:31][D][binary_sensor:036]: 'binary_onoff_1': Sending state OFF
[08:23:31][D][switch:020]: 'Relay 1' Toggling ON.
[08:23:32][D][switch:055]: 'Relay 1': Sending state ON
[08:23:32][D][binary_sensor:036]: 'binary_onoff_1': Sending state ON
[08:23:32][D][switch:020]: 'Relay 1' Toggling OFF.
[08:23:32][D][switch:055]: 'Relay 1': Sending state OFF
[08:23:32][D][binary_sensor:036]: 'binary_onoff_1': Sending state OFF
[08:23:32][D][switch:020]: 'Relay 1' Toggling ON.
[08:23:32][D][switch:055]: 'Relay 1': Sending state ON
[08:23:32][D][binary_sensor:036]: 'binary_onoff_1': Sending state ON
[08:23:32][D][switch:020]: 'Relay 1' Toggling OFF.
[08:23:32][D][switch:055]: 'Relay 1': Sending state OFF
[08:23:32][D][binary_sensor:036]: 'binary_onoff_1': Sending state OFF
[08:23:32][D][switch:020]: 'Relay 1' Toggling ON.
[08:23:32][D][switch:055]: 'Relay 1': Sending state ON
[08:23:32][D][binary_sensor:036]: 'binary_onoff_1': Sending state ON
[08:23:32][D][switch:020]: 'Relay 1' Toggling OFF.
[08:23:32][D][switch:055]: 'Relay 1': Sending state OFF
[08:23:34][D][binary_sensor:036]: 'binary_onoff_1': Sending state OFF
[08:23:34][D][switch:020]: 'Relay 1' Toggling ON.
[08:23:34][D][switch:055]: 'Relay 1': Sending state ON
[08:23:34][D][binary_sensor:036]: 'binary_onoff_1': Sending state ON
[08:23:34][D][switch:020]: 'Relay 1' Toggling OFF.
[08:23:34][D][switch:055]: 'Relay 1': Sending state OFF
[08:23:34][D][binary_sensor:036]: 'binary_onoff_1': Sending state OFF
[08:23:34][D][switch:020]: 'Relay 1' Toggling ON.
[08:23:34][D][switch:055]: 'Relay 1': Sending state ON
[08:23:34][D][binary_sensor:036]: 'binary_onoff_1': Sending state ON
[08:23:34][D][switch:020]: 'Relay 1' Toggling OFF.
[08:23:34][D][switch:055]: 'Relay 1': Sending state OFF
[08:23:34][D][binary_sensor:036]: 'binary_onoff_1': Sending state OFF
[08:23:34][D][switch:020]: 'Relay 1' Toggling ON.
[08:23:34][D][switch:055]: 'Relay 1': Sending state ON
[08:23:34][D][binary_sensor:036]: 'binary_onoff_1': Sending state ON
[08:23:34][D][switch:020]: 'Relay 1' Toggling OFF.
[08:23:34][D][switch:055]: 'Relay 1': Sending state OFF
[08:23:34][D][binary_sensor:036]: 'binary_onoff_1': Sending state OFF
[08:23:34][D][switch:020]: 'Relay 1' Toggling ON.
[08:23:34][D][switch:055]: 'Relay 1': Sending state ON
[08:23:34][D][binary_sensor:036]: 'binary_onoff_1': Sending state ON
[08:23:34][D][switch:020]: 'Relay 1' Toggling OFF.
[08:23:34][D][switch:055]: 'Relay 1': Sending state OFF
[08:23:36][D][binary_sensor:036]: 'binary_onoff_1': Sending state OFF
[08:23:36][D][switch:020]: 'Relay 1' Toggling ON.
[08:23:36][D][switch:055]: 'Relay 1': Sending state ON
[08:23:36][D][binary_sensor:036]: 'binary_onoff_1': Sending state ON
[08:23:36][D][switch:020]: 'Relay 1' Toggling OFF.
[08:23:36][D][switch:055]: 'Relay 1': Sending state OFF
[08:23:36][D][binary_sensor:036]: 'binary_onoff_1': Sending state OFF
[08:23:36][D][switch:020]: 'Relay 1' Toggling ON.
[08:23:36][D][switch:055]: 'Relay 1': Sending state ON
[08:23:36][D][binary_sensor:036]: 'binary_onoff_1': Sending state ON
[08:23:36][D][switch:020]: 'Relay 1' Toggling OFF.
[08:23:36][D][switch:055]: 'Relay 1': Sending state OFF
[08:23:36][D][binary_sensor:036]: 'binary_onoff_1': Sending state OFF
[08:23:36][D][switch:020]: 'Relay 1' Toggling ON.
[08:23:36][D][switch:055]: 'Relay 1': Sending state ON
[08:23:36][D][binary_sensor:036]: 'binary_onoff_1': Sending state ON
[08:23:36][D][switch:020]: 'Relay 1' Toggling OFF.
[08:23:36][D][switch:055]: 'Relay 1': Sending state OFF
[08:23:37][D][binary_sensor:036]: 'binary_onoff_1': Sending state OFF
[08:23:37][D][switch:020]: 'Relay 1' Toggling ON.
[08:23:37][D][switch:055]: 'Relay 1': Sending state ON
[08:23:37][D][binary_sensor:036]: 'binary_onoff_1': Sending state ON
[08:23:37][D][switch:020]: 'Relay 1' Toggling OFF.
[08:23:37][D][switch:055]: 'Relay 1': Sending state OFF
[08:23:37][D][binary_sensor:036]: 'binary_onoff_1': Sending state OFF
[08:23:37][D][switch:020]: 'Relay 1' Toggling ON.
[08:23:37][D][switch:055]: 'Relay 1': Sending state ON
[08:23:37][D][binary_sensor:036]: 'binary_onoff_1': Sending state ON
[08:23:37][D][switch:020]: 'Relay 1' Toggling OFF.
[08:23:37][D][switch:055]: 'Relay 1': Sending state OFF
[08:23:40][D][binary_sensor:036]: 'binary_onoff_1': Sending state OFF
[08:23:40][D][switch:020]: 'Relay 1' Toggling ON.
[08:23:40][D][switch:055]: 'Relay 1': Sending state ON
[08:23:40][D][binary_sensor:036]: 'binary_onoff_1': Sending state ON
[08:23:40][D][switch:020]: 'Relay 1' Toggling OFF.
[08:23:40][D][switch:055]: 'Relay 1': Sending state OFF
[08:23:40][D][binary_sensor:036]: 'binary_onoff_1': Sending state OFF
[08:23:40][D][switch:020]: 'Relay 1' Toggling ON.
[08:23:40][D][switch:055]: 'Relay 1': Sending state ON
[08:23:40][D][binary_sensor:036]: 'binar

Has someone an idea why it´s doing this and how can I make it working reliable. This device worked 6 month normally with the original firmware. So it must be some thing wrong with ESPHome firmware or configuration of the PINs.

Thanks in advanced.

What Tuya Smart Switch? There are quite a few.

Also - please have a read of this - specifically point 11 about correctly formatting your post. Use preformatted text tags for logs and yaml. They are accessed using the </> button on the posting toolbar.

Hello,

This is the device.

Thank you for help.

Sure of that?

I don´t know if it´s right.

try with INPUT_PULLUP, chances are much higher.

Hello.

I went back to OpenBeken. I found there a new config for the switch.
Till now its working.

Thank you for help.

The supported config for these switches is slightly different - may be worth a try: