Flip Flop (bistable/stable) relay triggered by esphome relay with live wire feedback/sensing in lighting application

Hello everyone, hope you’re well. Please guide me through this configuration:

1. The lights in the house were installed using the https://www.findernet.com/en/worldwide/series/27-series-step-relays-10-a/ . These relays make a flip (conduct electricity) when there is momentary power sent to them and remain in that state untill again momentary power is applied. Momentary power is applied using push buttons (ringbell type) instead of classic light switches. There is no way to know if the light circuit is closed or opened (light on or off) unless you see the light :slight_smile:. This type of wiring/solution is not an improvisation and allows me to use the lights without a working automation.

2. The automation hardware consists of: a 16 relay board based on an esp8266 driving a pcf8575 + a separate 16 ports live wire (220v) sensing board like this ones (https://www.aliexpress.com/w/wholesale-220V-Optocoupler-Isolation-Module%2F16-Channels-220V.html?spm=a2g0o.home.search.0) connected through also a pcf8575 to the other board’s esp8266 installed with esphome. Wires are routed from the relays (both finder and esp) and the setup works as intended.

3. To flip/flop the lighting relay (turn bulb on or off) from HA → Settings → Integrations → ESPLIGH → Controls I have to fast cycle the webpage switch on and off (1-2 seconds appart). This switch action always turns on and off the relay on the 16 relay automation board and, as said, this flip acts as the signal for the actual light action relay (finder) to toggle. When the actual light bulb is lighting/lit there is live power fed to the sensing board and I get the message “Pin #x turned on”. When the actual light bulb is off I get the opposite “Pin #x turned off”. From the wall obviously I just have to push that momentary button and it will toggle the light (by momentary power to the finder relay) and the state of the light will reflect in HA’s logbook as “Pin #x turned on” or off respectivelly.

Excerpts from the code:

pcf8574:
  - id: 'pcf8575_relays' #Soldered on ESP board
    address: 0x27
    i2c_id: bus_a
    pcf8575: true

    ## Phisical pin on device right-3 SCL right-4 SDA
  - id: 'pcf8575_external_220v_sense' #External board
    address: 0x20
    i2c_id: bus_a
    pcf8575: true

switch:
  - platform: gpio
    restore_mode: RESTORE_DEFAULT_OFF
    name: "Relay_1"
    id: relay_1
    pin:
      pcf8574: pcf8575_relays
      number: 0
      mode:
        output: true
      inverted: true

<snip

binary_sensor:
  - platform: gpio
    name: "Pin #1"
    pin:
      pcf8574: pcf8575_external_220v_sense
      number: 0
      mode:
        input: true
      inverted: true

Now the questions, please, since I’m new to HA and Esphome and trying to get my head around them surelly caused some confusion:

A. Is this the right way to define the Esphome components? Can there be a better and more complex way of doing it ?

B. How to integrate this in the HA as a usefull Light that can be used in automations since there are multiple actions involved for each bulb turned on/off. The 2 x relay switching actions are decoupled from the sensing of the actual light state.

Thank you for your help and expertise.

I have a similar circuit for the stairwell, with a surge relay.
I used a 4 channel relay card with ESP32, you can find the EspHome configuration here:

I also wrote an automation that simply sets the relay back to OFF when it is was switched ON.
The automation is triggered by a zigbee switch and by the relay itself.

alias: stairwell
description: Switches the staircase light and turns Relay1 into a push button
trigger:
  - device_id: ee5f2d555b5a411b327a50f8c241166e
    domain: zha
    platform: device
    type: remote_button_double_press
    subtype: button
  - platform: state
    entity_id:
      - switch.relay1_2
    to: "on"
    from: "off"
condition: []
action:
  - service: switch.turn_off
    data: {}
    target:
      entity_id: switch.relay1_2
mode: single

Not an expert but you’d probs want to use toggle : when the switch turns on you toggle the relay.

Hi Guido, the issue for me is that from automation the real state of the bulb on or off is given by the Pin state of the sensing board (without it you just toggle without knowing if the light is on or off) and to opperate the bulb on and off I have to quickly turn on and turn off the relay on the 16 relays board.

So I think I will need a component, that would look like a lamp or something in HA, and it will have the state from the pin and when actioned will have to call the cycle action (on-1s-off) on the relay.

I don’t think our setups are similar, you are lacking the feedback board.