LDN 00:00
6 minute read

Automatic gate entry using number-plate recognition and UniFi Access.

Home AutomationSecurity#protect#unifi
Will Beeching
Pale green wooden driveway gates between brick pillars in front of a red-brick house, with a dark car at right and overlaid graphics showing a number plate and a "Front Gate — Opening" notification

Getting into the house shouldn’t be a faff. The gate at our old house couldn’t be electrified, which drove me crazy, so when we moved I had a new gate installed with electric rams and set about making it smart.

Here’s how it works now. When one of our cars comes down the road, a camera on the gate reads the number plate and opens the gate. When any car drives out, guests included, a sensor in the driveway opens it for them. Delivery drivers use the intercom, which also recognises the faces of people already on the system. At 7am the gate opens for the day if we’re home or have guests staying, at 7pm it closes, and overnight it closes itself five minutes after it’s opened.

Why number plate recognition

You can keep a remote in the car, but it’s fiddly to use and does nothing unless you’re sat right at the gate.

There are a few other ways to make a gate smarter. A HomeLink receiver on the gate lets you open it from the car’s built-in buttons, but it’s still a remote, just one you can’t lose. A GSM opener lets you ring a number to open the gate, which works for guests but means handing out a phone number. Geofencing through the Home Assistant app can open the gate as your phone approaches, but it only works for people with the app, and GPS isn’t precise enough to trust at the gate itself.

I wanted the gate to recognise our cars without anyone pressing a button or needing a phone with the right app. Number plate recognition fitted that brief. We already had UniFi cameras covering the outside of the property, so UniFi Access with its plate recognition was the obvious fit.

Hardware and cost

That’s about £1,400 in total for what I paid. If you already have the camera it’s about £1,190, and if you also have a Dream Machine Pro or SE, which can run Access and Protect instead of the UNVR, it drops to about £880. None of that includes the gate, the rams or cabling. It’s not the cheapest route, but my networking and security are all UniFi already, so keeping everything in one system made the most sense.

Wiring in the Gate Hub was straightforward: a few wires into the BFT gate controller and a run of outdoor Cat 6A down to the gate post. The BFT controller also has a position output, which I wired into the Gate Hub’s position sensor input so Access always knows whether the gate is open or closed.

Setting up plate recognition

The G6 Bullet is mounted on the gate column, pointing down the road towards approaching cars. That angle catches the front plate head-on as a car comes towards the gate, and it reads plates from around 5 to 10 metres away.

Setup happens in UniFi Access, which I installed on my UNVR. I paired the camera with the Gate Hub and the intercom, then added each person along with their number plates. When the camera reads a plate that belongs to someone on the system, Access opens the gate.

It works well at night and in bad weather, which was my main worry before installing it. Plate recognition is a convenience rather than a security measure, since plates can be cloned, so it’s worth keeping that in mind when you decide who to add.

Getting cars out

Before installing it, I assumed I’d use CarPlay to open the gate on the way out. I hadn’t thought about guests, who also need a way out when the gate is closed. We were already having plastic grates laid under the gravel driveway to stop it shifting, so while the ground was up I installed a Diablo Magna in-road sensor just before the gate safety beams.

This turned out to be one of the most useful parts of the setup. The sensor sends a pulse whenever a large metal object, like a car, is above it. UniFi Access supports exit requests, but the request was also firing as cars came into the driveway, not just when they left. Our gates stay open during the day for deliveries, so that caused problems.

Luckily the Gate Hub supports two doors and I was only using one. I wired the sensor into the second door’s exit request instead. Home Assistant now sees when a car is over the sensor, checks whether the gate is already open, and only triggers it if it isn’t.

Home Assistant automations

I keep all my automations in Home Assistant so the logic lives in one place. The Access integration didn’t always register the gate opening and closing, so I set up webhooks from Access to Home Assistant for three events: gate open, gate closed, and vehicle exiting.

One thing to know before reading the automations: the Gate Hub doesn’t give Home Assistant separate open and close commands. The gate shows up as a lock, and unlocking it sends a single pulse to the BFT controller, the same as pressing a button on a remote. The controller then opens the gate if it’s closed and closes it if it’s open. So lock.unlock really means “press the button”, and every automation checks a helper called input_boolean.gate_position first. As long as that helper matches the gate, a pulse does what’s intended. It’s also why the closing loop waits 45 seconds between attempts. A second pulse while the gate is still moving could stop or reverse it.

Keeping the helper accurate is the important part. It updates from the webhooks, and also from the Access integration’s position sensor as a backup. If a webhook is missed, or Home Assistant restarts, the next update from the integration puts the helper back in line with the gate.

Home Assistant gate device page, door sensor logging every open
Home Assistant gate device page, door sensor logging every open

What you’ll need

  • The UniFi Access integration, which provides lock.gate and binary_sensor.gate_door_position_sensor
  • An input boolean for the gate position (input_boolean.gate_position)
  • Some way of knowing whether you’re home. I use input_boolean.house_unoccupied and input_boolean.guests_here, but swap in whatever you already have
  • Three webhooks set up in UniFi Access, pointing at Home Assistant
  • A template cover if you want the gate in HomeKit and CarPlay (more on that below)

Tracking the gate position

This sets the helper to on when the gate opens and off when it closes, from either the webhooks or the Access integration.

Gate Position Status
alias: Security — Gate — Position Status
description: ''
triggers:
  - trigger: webhook
    allowed_methods:
      - POST
      - PUT
    local_only: true
    webhook_id: your-gate-open-webhook-id
    id: gateopen
  - trigger: webhook
    allowed_methods:
      - POST
      - PUT
    local_only: true
    webhook_id: your-gate-closed-webhook-id
    id: gateclosed
  - trigger: state
    entity_id: binary_sensor.gate_door_position_sensor
    to: 'on'
    id: gateopen
  - trigger: state
    entity_id: binary_sensor.gate_door_position_sensor
    to: 'off'
    id: gateclosed
conditions: []
actions:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - gateopen
        sequence:
          - action: input_boolean.turn_on
            target:
              entity_id: input_boolean.gate_position
      - conditions:
          - condition: trigger
            id:
              - gateclosed
        sequence:
          - action: input_boolean.turn_off
            target:
              entity_id: input_boolean.gate_position
mode: single

Opening and closing on a schedule

At 7am, if we’re home or have guests staying, this opens the gate. At 7pm it closes it, making up to three attempts if the gate doesn’t report closed. Overnight, whenever the gate opens, it waits five minutes and then closes it.

Gates Open/Close
alias: Security - Gates - Open/Close
description: ''
triggers:
  - trigger: time
    at: '07:00:00'
    id: morning
  - trigger: time
    at: '19:00:00'
    id: evening
  - trigger: state
    entity_id: input_boolean.gate_position
    from: 'off'
    to: 'on'
    id: gate_opened
conditions: []
actions:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - morning
          - condition: or
            conditions:
              - condition: and
                conditions:
                  - condition: state
                    entity_id: input_boolean.house_unoccupied
                    state: 'on'
                  - condition: state
                    entity_id: input_boolean.guests_here
                    state: 'on'
              - condition: state
                entity_id: input_boolean.house_unoccupied
                state: 'off'
        sequence:
          - condition: state
            entity_id: input_boolean.gate_position
            state: 'off'
          - action: lock.unlock
            target:
              entity_id: lock.gate
      - conditions:
          - condition: trigger
            id:
              - evening
        sequence:
          - condition: state
            entity_id: input_boolean.gate_position
            state: 'on'
          - repeat:
              while:
                - condition: state
                  entity_id: input_boolean.gate_position
                  state: 'on'
                - condition: template
                  value_template: '{{ repeat.index <= 3 }}'
              sequence:
                - action: lock.unlock
                  target:
                    entity_id: lock.gate
                - delay: '00:00:45'
      - conditions:
          - condition: trigger
            id:
              - gate_opened
          - condition: or
            conditions:
              - condition: time
                after: '19:00:00'
              - condition: time
                before: '07:00:00'
        sequence:
          - delay: '00:05:00'
          - repeat:
              while:
                - condition: state
                  entity_id: input_boolean.gate_position
                  state: 'on'
                - condition: template
                  value_template: '{{ repeat.index <= 3 }}'
              sequence:
                - action: lock.unlock
                  target:
                    entity_id: lock.gate
                - delay: '00:00:45'
mode: restart

Opening the gate for cars leaving

When the driveway sensor fires, this opens the gate, but only if it’s currently closed.

Vehicle Exiting
alias: Security - Gate - Vehicle Exiting
triggers:
  - trigger: webhook
    allowed_methods:
      - POST
      - PUT
    local_only: true
    webhook_id: your-vehicle-exit-webhook-id
conditions:
  - condition: state
    entity_id: input_boolean.gate_position
    state: 'off'
actions:
  - action: lock.unlock
    target:
      entity_id: lock.gate
mode: restart

HomeKit and CarPlay

I used the HomeKit Bridge integration to add the gate to HomeKit, so it shows up in CarPlay if I ever need to open it manually. It’s exposed as a template cover with the gate device class, using input_boolean.gate_position for its state, so CarPlay treats it as a gate rather than a lock.

Would I do it again?

Yes, and I’d build it the same way. Plate recognition has been reliable day and night, in all weathers, and between the camera, the exit sensor and the intercom, nobody has to think about the gate at all.

There's more like this.
Keep reading.

Will Beeching
Maintenance
13 minute read

Effortless lawn care with the Mammotion Luba 2X.

Will Beeching
Maintenance
4 minute read

Monitoring water softener salt levels with a time-of-flight sensor.

Time Of Flight