How To: Driveway Swing Gate Automation (Shelly + BFT) - Working Perfectly with states!

Hi all,

First post here, so go easy!

I’ve been trying to replicate what I’ve read in this thread for my BFT Thalia and using a Shelly Plus Uni. Annoyingly the Shelly Plus Uni inputs are different from the previous Shelly Uni ones and I’ve struggled to get my head around them as I don’t think they’re very well documented for my case of using the digital inputs with both free and powered contacts. Nonetheless this is what I’ve come up with.

Before I plug this in and test it, does anyone have experience with the Shelly Plus Uni who can advise if this is the right way to wire up the digital inputs?

Yeah, the cover pulsates as well, but it eventually ends up as a Close state. I suspect it’s behaving as if a light was hard wired in to flash. I tested a scenario by adding a LIFX bulb inside to show the status of the gate (red Open, green Closed). When the gate closes, the bulb flashes red and green. I bought an ESP32 to see if I can wire up a small LED to provide a similar effect inside the front door.

1 Like

Coming back to this thread in September 2024, it’s gratifying to see so many other users making use of the original information!

In answer to your question, no, I wouldn’t change a thing & my automation has been working flawlessly since install. I turned off the ‘open gate when approaching home’ automation, since on my phones at least, the HA location sensor isn’t reliable enough to open the gate…or at least the whole thing was more trouble than I could be bothered with (may get bored and have another go…).

So - it’s been all good :slight_smile:

Hi @Benjamest ,
I am doing exactly the same as you (BTW, nice diagram :slight_smile: ).

CAUTION: I just burned (a few minutes ago) the Shelly Plus Uni!!!

I did all the connections in my breadboard (test bench) powering the Uni using 5V DC (pin #5 and #6). I tested everything, configured it on Shelly cloud. Everything looking good.

My plan was to follow exactly your diagram, except the IN2! The outputs #20 and #21 are powered by 24VAC!!!
So I wouldn’t connect it to the inputs of the Shelly Uni. I will only use #26 and #27 that are dry contacts (relay).

But when I connected everything on the Thalia, nothing was happening (the Uni was not powering on) and I burned it :frowning:

I got a multimeter to measure the 24VAC outputs (#61 and #62) and I was getting a reading of more than 30VAC !!!
The issue is that The Shelly uni accepts up to 24VAC peak voltage, and the 24VAC
announced by Thalia are RMS!!!

I will get another Shelly and I will use directly a lower voltage from the Thalia transformer that is feeding the main board. It has 3 outputs on the secondary: 15V, 20V and 24V (RMS). The Thalia is using the 24V (>30V) and I will use the 15V which is ~21V peak.
Or I will add a 220VAC to 5VDC transformer jst to power my Uni.

I hope I was able to help you. Let’s share experiences to finish this small, but very usefull, project.

Best,
Pedro

Are you measuring VAC (alternating voltage)?

I assume it does not have local option?

Hello guys. I´d like to make my Key Automation gate opener to smart. Could you help me with setup/wiring ? Of course in combination of Shelly product, thank you.

KA User manual PDF

Hey, I wanted to share rupertas solution upgrade. The difference is that I’m able to distinguish between all states of the gate.

Make sure both Shelly channels are set as:

  1. Relay
  2. Settings → Button Type → Detached Switch
  3. Timer → Turn off after 0.5
  4. Power on default: Off

Wiring is the same on my Deimos Ultra BT A600:
Shelly->BFT

  1. VCC- > 51 (24V+)
  2. N → 50 (24V-)
  3. IN_1 → 20 (AUX0=6)
  4. IN_2- > 26 (AUX3=1)
  5. N/GND_1 → 60 (COM)
  6. N/GND_2 → 60 (COM)
  7. OUT1 → IC1 (IC1=0)
  8. OUT2 → IC2 (IC2=3)

BFT->BFT

  1. 51->27 (Power supply for 27th port)

The main difference is how I utilize AUX inputs:

The 20:AUX0=6

Aux logic= 6 - FLASHING LIGHT output.
Contact stays closed while leaves are operating

This one tells us if the gate is moving or stationary.

The 26: AUX3=1

Aux logic= 1 - SCA GATE OPEN LIGHT output.
Contact stays closed during opening and with the leaf open, intermittent during closing, and open with the leaf closed.

With these, we can get all the possible states, and the hardest part is that

intermittent during closing

In other words, it’s “blinking” or changing states every second or so.
Here’s the template I created to calculate all possible states:

- trigger:
    - platform: homeassistant
      event: start
      id: "init"

    - platform: state
      entity_id: binary_sensor.gate_channel_2_input
      to: "off"
      for:
        seconds: 4 # make this slightly longer than the lamp blink time
      id: "closed"
    - platform: state
      entity_id: binary_sensor.gate_channel_2_input
      to: "on"
      for:
        seconds: 4 # make this slightly longer than the lamp blink time
      id: "open"
    - platform: state
      entity_id: binary_sensor.gate_channel_2_input
      to: # a null 'to' only triggers on all state changes, not attribute changes
      id: "closing"

  sensor:
    - name: "Gate Open State"
      icon: mdi:gate
      state: >
        {% if trigger.id == 'init' %}
          {% if is_state('binary_sensor.gate_channel_1_input', 'on')  %}
            moving
          {% elif is_state('binary_sensor.gate_channel_1_input', 'off') and is_state('binary_sensor.gate_channel_2_input', 'off') %}
            closed
          {% else %}
            open
          {% endif %}
        {% elif trigger.id == 'closed' %}
          closed
        {% elif trigger.id == 'open' %}
          open
        {% elif trigger.id == 'closing' %}
          closing
        {% else %}
          unknown
        {% endif %}

- trigger:
    - platform: homeassistant
      event: start
      id: "init"

    - platform: state
      entity_id: binary_sensor.gate_channel_1_input
      to: "on"
      for:
        seconds: 4.5
      id: "moving"
    - platform: state
      entity_id: binary_sensor.gate_channel_1_input
      to: "off"
      for:
        seconds: 4.5
      id: "stationary"

  sensor:
    - name: "Gate Move State"
      icon: mdi:gate
      state: >
        {% if trigger.id == 'init' %}
          {% if is_state('binary_sensor.gate_channel_1_input', 'on')  %}
            moving
          {% else%}
            stationary
          {% endif %}
        {% elif trigger.id == 'moving' %}
          moving
        {% elif trigger.id == 'stationary' %}
          stationary
        {% else %}
          unknown
        {% endif %}

- sensor:
    - name: "Gate Status"
      icon: "mdi:gate"
      state: >
        {% if states('sensor.gate_open_state') == 'closed' %}
          Closed
        {% elif states('sensor.gate_move_state') == 'moving' and states('sensor.gate_open_state') == 'open' %}
          Opening
        {% elif states('sensor.gate_move_state') == 'stationary' and states('sensor.gate_open_state') == 'open' %}
          Open
        {% elif states('sensor.gate_move_state') == 'stationary' and states('sensor.gate_open_state') == 'closing' %}
          Open
        {% elif states('sensor.gate_move_state') == 'moving' and states('sensor.gate_open_state') == 'closing' %}
          Closing
        {% else %}
          Unknown
        {% endif %}

Then, using this, I created entity cards.
One for seeing both states:

type: entities
entities:
  - entity: sensor.gate_move_state
    name: "Gate Move State"
    secondary_info: last-updated
  - entity: sensor.gate_open_state
    name: Gate Open State
    secondary_info: last-updated

The other interface uses buttons with icons reflecting the gate state (Closed, Opening, Open, or Closing). The input command logic is a bit different here:

  • IC1 = 0 serves as a toggle—Open, Close, or Stop—depending on the current state. Most of the time, I just want to open the gate, but occasionally, I use it to stop it mid-motion.
  • IC2 = 3 is a dedicated Close command. I use this when I want to make sure the gate is closed, regardless of whether it’s currently open, opening, or even already closed—I just hit it to force it shut.

Here are the buttons:

type: vertical-stack
cards:
  - type: custom:button-card
    tap_action:
      action: toggle
    entity: switch.gate_channel_1
    show_state: false
    show_name: true
    show_icon: true
    icon: |
      [[[
        if (states['sensor.gate_status'].state === 'Closed') {
          return 'mdi:gate';
        } else if (states['sensor.gate_status'].state === 'Opening') {
          return 'mdi:gate-arrow-left';
        } else if (states['sensor.gate_status'].state === 'Open') {
          return 'mdi:gate-open';
        } else if (states['sensor.gate_status'].state === 'Closing') {
          return 'mdi:gate-arrow-right';
        }
        // Default fallback icon if none of the above conditions match
        return 'mdi:help-circle';
      ]]]
    name: |
      [[[
        return states['sensor.gate_status'].state;
      ]]]
  - type: custom:button-card
    entity: switch.gate_channel_2
    show_name: true
    show_icon: true
    tap_action:
      action: toggle
    icon: mdi:arrow-collapse-horizontal
    name: Close
    styles:
      card:
        - height: 100px
        - opacity: |
            [[[
              if (['closing', 'closed'].includes(states['sensor.gate_open_state'].state)) {
                return '0.5';  // Semi-transparent to indicate disabled
              }
              return '1';  // Fully opaque when enabled
            ]]]
      lock:
        - pointer-events: none
    state:
      - value: "on"
        styles:
          card:
            - pointer-events: |
                [[[
                  if (['closing', 'closed'].includes(states['sensor.gate_open_state'].state)) {
                    return 'none';  // Disable button interaction 
                  }
                  return 'auto';  // Enable button interaction
                ]]]

The final result looks like this:

2 Likes

Hi Pedro,
were you able to resolve the issue with the Shelly Plus Uni? I have the same configuration and would be glad to hear from you, if there is a way how to solve it.
I checked the Shelly support group and didn’t find any solution.

Hi @all
I read that some of you had the problem of burning their shelly, did you find a possibility to fix this issue?

I burned one shelly when trying to use the 24V power,… after using an external power source I burned a second one when trying to switch the relais, but there where over 30VDC voltage, but the shelly only can handle a max of 30VDC, currently I have no sweet idea to solve the problem, any ideas from you?
Kind regards

Late reply as I have just visited this thread but I used that little relay board mentioned in the post for the 24v output from the BFT to switch a live input in go into the Shelly switch input so I can detect if the gate is opening or has just closed.