Deta 2 way ( 3 way) switch WB3S chip

I have a new (true) Deta 2 way switch (96951HA) from bunnings with WB3S chip.
I’ve flashed using Libretuya ESPHome branch.
My Yaml works perfectly as a single switch going to load.
It also works perfectly physically in 2 way mode, with a physical (non smart switch) at the remote end.

The issue I have is, if I turn it off using the remote switch, it doesn’t register that it is turned off locally (in esphome or home assistant).

The device has 2 relays in it, for 2 way switching. It looks like it is physically wired so if one relay is switched it automatically toggles the other relay.

EDIT
I don’t know what pin (if any) is connected to remote relay to allow notification that it has been switched at the remote end.
Looks like “P8” reports status - on or off (inverted)
P9 controls remote switch

# P24 - status led
# P14 - relay
# P26 - Local button
# P9 - Remote button
# P8 - power status (inverted)

A physical inspection of chip look like the only soldered connections are:

PIN:
1 -VCCRXFE  
3 - EN (26) - Button1
4 - P14 - Relay
8 - VCC
9 - Gnd
10  - Txdata2 - P7 
11 - Rxdata2
12 - PWM3
13 - PWM2 - P8 (P24) - Status LED
15 - RXD1 

My Yaml:

substitutions:

  device_name: masterbedbedsw

  friendly_name: "masterbedbedsw"

  device_ip: 192.168.1.128

esphome:

  name: ${device_name}

  friendly_name: ${friendly_name}

libretuya:

  board: wb3s

  framework:

    version: dev

# Enable logging

logger:

# Enable Home Assistant API

api:

  encryption:

    key: "E1piLrGNTl63LcmF5jIyKN3qLljwxGjbPqKOwNDgKR8="

ota:

  password: "2c0bd0708c739debd734dc13d2d6fc42"

wifi:

  ssid: !secret wifi_ssid

  password: !secret wifi_password

  manual_ip:

    static_ip: ${device_ip}

    gateway: 192.168.1.1

    subnet: 255.255.255.0

  # Enable fallback hotspot in case wifi connection fails

  ap:

    ssid: "Masterbed-bed-Sw"

    password: "pxYBUfA4yRII"

# The web_server & sensor components can be removed without affecting core functionaility.

web_server:

  port: 80

sensor:

  - platform: wifi_signal

    name: ${device_name} Wifi Signal Strength

    update_interval: 60s

  - platform: uptime

    name: ${device_name} Uptime

button:

  - platform: factory_reset

    name: Restart with Factory Default Settings

    id: Reset

output:

 # status led

  - platform: gpio

    pin: P24

    id: white_status_led

    inverted: true

#Relay

  - platform: gpio

    id: relay_output

    pin: P14

light:

  # status Led

  - platform: binary

    name: "${friendly_name} status_led"

    output: white_status_led

    id: status

  # Top (or only) button

  - platform: binary

    name: "${friendly_name} Top"

    output: relay_output

    id: light1

# Buttons

binary_sensor:

  # Top (or only) button

  - platform: gpio

    pin:

      number: P26

      mode: INPUT

      inverted: True

    name: "${friendly_name} Top Button"

    filters:

      - delayed_off: 50ms    

    #toggle relay on push

    on_press:

      - light.toggle: light1

  - platform: gpio

    pin:

      number: P9

      mode: INPUT

      inverted: True

    name: "${friendly_name} remote Button"

    filters:

      - delayed_off: 50ms    

    #toggle relay on push

    on_press:

      - light.toggle: light1

  - platform: gpio

    # https://esphome.io/components/binary_sensor/gpio.html

    pin:

      number: P8

      inverted: True

    id: powersensor

    name: ${friendly_name} Sensor

switch:

  - platform: restart

    name: "${friendly_name} REBOOT"

  # present the state of the switch in HA based on the sensor

  - platform: template

    # https://esphome.io/components/switch/template.html

    name: ${friendly_name}

    id: ${device_name}

    lambda: |-

      if (id(powersensor).state) {

        return true;

      } else {

        return false;

      }

    # https://esphome.io/guides/automations.html#if-action

    turn_on_action:

        - if:

            condition:

              binary_sensor.is_off: powersensor

            then:

              - light.toggle: light1

    turn_off_action:

        - if:

            condition:

              binary_sensor.is_on: powersensor

            then:

              - light.toggle: light1      
1 Like