Relay Trigger when power loss

Hi Guys,
I am very new to this - but have a bit of DIY in me.
I setup an automation to be able to open and close my gates using homeassistant and everything works fine. I have an issue where, in the event of a power loss, it triggers the relay and my gates open. I have backup power and am sorting out the faulty power supply. The issue I have is that I cannot leave this in the current state where if there is a power outage, the gates can open erratically. I know I can add sensors and will get there eventually but I am trying to find the root cause. I have read about not using GPIO 0, 2 and 15 and I have refrained from that. my ESP code is below:

switch:

  • platform: gpio
    pin: GPIO5

    D1 - GPIO5

    white wire = driveway gate

    id: relay
    name: “Driveway Gate”
    icon: “mdi:gate”
    on_turn_on:
    • delay: 500ms
    • switch.turn_off: relay

- Garage Section

  • platform: gpio
    pin: GPIO4

    D2 - GPIO4

    brown wire = blue gate

    id: relay1
    name: “Blue Gate”
    icon: “mdi:gate”
    on_turn_on:
    • delay: 500ms
    • switch.turn_off: relay1

The very important note is that it failed when it looses power, not upon boot.
this is my relay: 1. BDD RELAY BOARD 2CH 5V - Communica [Part No: BDD RELAY BOARD 2CH 5V]

this is how its connected:

Any help would be appreciated.

Hi - maybe fix up the posting of the yaml using some code tags </>. So:

it looks like this.

And also post some logs from the ESP device when the power failure occurs.

Hi,
From the picture it seems you are using the Normally Closed contact on the relay.
Is there a reason for that?
I would guess that you are somehow simulating a button press with the relay, is it correct?

1 Like

Also, you didn’t mention which esp you have. And your relay is wired unproperly for 3.3V trigger.

Try to move your blue gate wires to left terminals on relays output.