Arlec PC191HA - Button self triggering due to serial data?

I bought an Arlec PC191HA (Beken chips) at Bunnings last weekend and just flashed ESPHome to it. I then copy and pasted an example config, edited for a pin-swap between the WB2S and CB2S modules (P6 looks to be swapped with P8 according to the libretiny docs), and uploaded… This caused the relays to randomly trigger.

What I think is going on is that the button on these is wired to the TX1 pin, which obviously in the real firmware, they just don’t use for serial. I suspect ESPHome is sending logging data out this pin even though it’s defined for something else. This is then triggering the pin to appear toggled at times, and it processes the event for pressing the button, which toggles the relay.

Could someone have a look over my config and tell me if anything stands out… The version I’m posting here currently has logging disabled and UART2 set, which didn’t help at all, but commenting out the whole button section stopped the random relay toggling. It’s getting late here now, so I’m stopping my own experimentation for now.

Config below - top section down to captive portal was generated by ESPHome except the substitutions, which I added to match the copy-pasta that follows beyond captive portal.

esphome:
  name: arlec-pc191ha-2
  friendly_name: Arlec-PC191HA-2

substitutions:
  device_name: "arlec_PC191HA"
  name: "ARLEC PC191HA"

bk72xx:
  board: cb2s

# Enable logging
logger:
  level: NONE
  hardware_uart: UART2

# Enable Home Assistant API
api:
  encryption:
    key: "<removed>"

ota:
  - platform: esphome
    password: "<removed>"

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

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Arlec-Pc191Ha-2 Fallback Hotspot"
    password: "<removed>"

captive_portal:
    

#
# PC191HA basic switch operation - button, relay and LED
#
    # button is momentary on - shows "on" in HA except for the moment the button is being pressed
    # LED should have same on/off state as the relay.  
    # there is also a wifi_LED, but it is not seen from outside the case

#binary_sensor:    # the button
#  - platform: gpio
#    pin: P11
#    name: ${device_name} button
#    id: button
#    device_class: window
#    # when button is pressed, toggle the switch on/off
#    on_press:
#      then:
#        - switch.toggle: relay



switch:          # the relay
  - platform: gpio
    pin: P8
    name: "${name}"
    id: relay
    restore_mode: always off   # default when power is turned on
    icon: mdi:power-socket-au
    # synchronise the LED with the relay
    on_turn_on:
      then:
        - output.turn_on: button_led
    on_turn_off:
      then:
        - output.turn_off: button_led

output:        # the light in the button
  - platform: gpio
    id: button_led
    pin: P26
    #restore_mode: always off   # default when power is turned on


#
# PC191HA sensors - power monitoring and wifi signal
#
sensor:
  - platform: wifi_signal         # report wi-fi signal strength from this end
    name: $name WiFi Signal
    id:   ${device_name}_wifi_signal
    update_interval: 30s    # how often to report wifi signal strength

    # PC191HA includes a BL0937 chip for measuring power consumption
    #     and BL0937 is a variation of hlw8012, but using inverted SEL pin functionality
  - platform: hlw8012
    model: BL0937     # note that the model must be specified to use special calculation parameters
    sel_pin:          # I believe that cf_pin reports either Voltage or Current depending on this select pin
      inverted: true  # determine whether true reports Voltage
      number: P24
    cf_pin:           # current or voltage (ele_pin: 7)
      inverted: true  # the logic of BL0937 is opposite from HLW8012
      number: P7
    cf1_pin:          #  Power (vi_pin: 8)
      inverted: true  # the logic of BL0937 is opposite from HLW8012
      number: P6

    update_interval: 15s      # How often to measure and report values

    # PC191HA measures and returns Voltage OR Current according to the value of sel_pin,  
    #   but it can change the value of sel_pin periodically
    initial_mode: "VOLTAGE"       # reports VOLTAGE or CURRENT
    change_mode_every: 4          # how many times to report before swapping between
        #   reporting Voltage or Current. Note that the first value reported should be ignored as inaccurate

    # Adjust according to the actual resistor values on board to calibrate the specific unit
    voltage_divider:  775     # LOWER VALUE GIVES LOWER VOLTAGE
    current_resistor: 0.0009  # HIGHER VALUE GIVES LOWER WATTAGE

    #
    # how the power monitoring values are returned to ESPHome
    #

    voltage:
      name: $name Voltage
      id:   ${device_name}_voltage
      unit_of_measurement: V
      accuracy_decimals: 1
      filters:
        - skip_initial: 2
    power:
      name: $name Power
      id:   ${device_name}_power
      unit_of_measurement: W
      accuracy_decimals: 2
      filters:
        - skip_initial: 2

    # power should simply be current x voltage -- except that the pc191ha doesn't follow that formula.  
    # Setting current_resistor to give an accurate Amperage does NOT also give the correct Wattage
    # so here I calculate current from power and voltage

  - platform: template  
    name: $name Current
    id:   ${device_name}_current
    unit_of_measurement: A
    accuracy_decimals: 2
    update_interval: "30s"
    lambda: |-
      return (id(${device_name}_power).state / id(${device_name}_voltage).state);
    filters:  
      - skip_initial: 2

  - platform: uptime
    name: $name Uptime
    id:   ${device_name}_uptime
    update_interval: "30s"

I don’t know your device, but if you tried with uart logging disabled, you could try to set the internal pullup for button.

In case anyone else comes across this (or I forget when I buy more :rofl:)- the fix is to set baud rate to 0…

logger:
  baud_rate: 0