Sonoff basic with ESPHome triggers impulse switch - How to show up correct state at HA?

Hi all,

Actualy I’m migrating my existing system from fhem/espeasy/tasmota to HA/esphome. Most parts are working fine but with one thing I’m struggeling.
I’ve a sonoff basic with esphome wich triggers a 2-pole impulse switch with 500ms pulses. This switch is used in combination with two 3-way switches to turn on/off ceiling lights.

Here a snip of my current esphome yaml:


binary_sensor:
  - platform: gpio
    pin:
      number: GPIO14
      mode:
        input: true
        pullup: true
      inverted: true
    name: "Sonoff Basic Button"

switch:
  - platform: gpio
    pin: GPIO12
    id: relay
  - platform: template
    name: "Sonoff Basic Relay"
    icon: "mdi:lightbulb"  
    turn_on_action:
    - switch.turn_on: relay
    - delay: 500ms
    - switch.turn_off: relay


GPIO12 is controlling the original sonoff relay which triggers the impulse switch.
GPIO14 is a input using a opto-coupler to check if light are powered or not.
At HA I’m able to turn on and of the lights, but I don’t have any clue how to use GPIO14 as the state. The toggle button at HA turn off imediatelly after switching the button, because it represents the state of the sonoff relay, but I want to see the state of the lights.
Does anybody have a similar setup or any idea/hint how I can setup the ESPHome/Sonoff device that it behaves as wanted?

BR
Kauli80

Hi, did you get this working because i’m having the exact same issue and can’t find the solution for it.

Hi @Schepers_HA
The only way I was able to solve it, was at the HA card configuration:

type: custom:layout-card
layout: custom:vertical-layout
column_width: 100%
cards:
  - type: custom:banner-card
    heading:
      - Gang
  - type: button
    tap_action:
      action: call-service
      service: switch.toggle
      service_data:
        entity_id: switch.sonoff_basic_relay
    entity: binary_sensor.sonoff_basic_button
    name: Licht
    show_state: false
    show_name: true
    show_icon: true
    icon: mdi:light-recessed
    size: 60px
    color: var(--paper-item-icon-color)
    hold_action:
      action: none

Have you found a better way to do it directly in esphome?