One boom barrier, one remote, one button for open, stop and close. That works for a single owner. With guests, staff and suppliers it means a remote for every regular visitor, or a walk to the gate, and a boom that stays up all night when somebody forgets it.
Overview
The barrier itself is usually healthy. It only lacks a brain. Here the motor and its control board stay untouched, and a Shelly Pro 2 with a Pro Sensor Add-on goes on the DIN rail beside them. Its three contacts press the board's own OPEN, CLOSE and STEP inputs for 1 second, like a finger on a push button. A plate camera checks each car against its own allow list and tells the Shelly over the local network. A lane sensor under the boom tells it when the lane is empty. Two Shelly Scripts on the device do the rest, so the gate keeps working when the internet is down.
After the change nobody hands out remotes. A guest is one line in each camera's allow list, with a start and an end date. The Shelly app still operates the gate from a phone, and the gate closes itself after that too.
The same three contacts suit sliding gates, swing gates, garage doors and car-park barriers, because many of their boards offer OPEN, CLOSE and STEP inputs. Swap the plate camera for a keypad or an intercom relay and the Shelly side stays the same.
Important scope note: this is a convenience feature that behaves carefully. It is not a certified safety device. A lane sensor and a script do not replace the safety devices that gate standards require, such as a photocell or a safety edge. Where the board has a photocell input, fit a photocell on it and keep the Shelly logic as the second layer. The Shelly also never switches the motor: the add-on output is rated 30 V / 300 mA, which suits a command input and nothing bigger.
Prerequisites
-
Shelly Pro 2, DIN rail mounted. Ours was the UL variant; the links below describe the EU v.1.
-
Shelly Pro Sensor Add-on, plugged into the Pro 2
-
A gate or barrier board with separate low-voltage OPEN, CLOSE and STEP command inputs against a common terminal (the terminals a key switch or push button would use)
-
A plate-recognition camera with its own allow list and HTTP push, one per direction, on the same local network as the Shelly. We used Dahua ITC413.
-
A lane sensor with a digital output and its 12 V supply. We used a DFRobot SEN0531 laser proximity sensor.
-
Shelly Smart Control app for opening from a phone, and the device's web interface for the scripts
-
Optional: Shelly BLU RC Button 4 as a hand remote. It needs a Bluetooth gateway nearby, and the Pro 2 itself does that job with a third small script that pulses O1 on a button press. That script is not part of this guide.
-
Installation of Shelly Pro 2 must be performed by a qualified electrician. See the Shelly Pro 2 user and safety guide.
Steps
-
Switch the breaker off and prove the board dead with a voltage tester. Dark LEDs are not proof.
-
Plug the add-on into the Pro 2, then power up and activate the add-on before you configure anything else.
-
Find the command inputs in the barrier manual. On our Beninca board they are 12 (common), 15 (OPEN), 16 (CLOSE) and 17 (STEP). Run the common to Pro 2 terminals I1 and I2 and to the add-on's IN terminal. Then wire O1 to STEP, O2 to CLOSE and the add-on OUT to OPEN.
-
Power the lane sensor from its 12 V supply and wire its signal to the add-on's first digital input, with the supply's negative on the add-on GND. Keep this ground away from the barrier's common. Set the input so it reads on when the lane is clear; the logic can be inverted in the input settings.
-
Mount the sensor on the barrier cabinet about 45 cm above the road, looking straight across the lane under the boom. Set its range to stop before it touches the road or the lowered boom. On our gate that was about 2 m.
-
Set all three outputs to switch themselves off after 1 second. A stuck contact would otherwise hold a command on the board.
-
Add the script below in the device's Scripts section, name it "anpr-open" and set it to start with the device. It opens the gate only when the camera says the plate is on its allow list, and it ignores repeats within 5 seconds.
What the script does with each message from the camera.
// Plate camera push -> Shelly. Opens ONLY when the camera says the plate is allowed.
// switch:100 = add-on output wired to OPEN
let OPEN_ENABLED = true;
let OPEN_ID = 100, MIN_GAP_MS = 5000, MAX_BODY = 4000;
let st = { hits: 0, plates: 0, opens: 0, last: "", plate: "", action: "", t: 0 };
let lastOpen = 0;
function field(b, key) { // b has all spaces removed
let i = b.indexOf('"' + key + '":');
if (i < 0) return null;
i += key.length + 3;
let e = i;
while (e < b.length && b[e] !== ',' && b[e] !== '}' && b[e] !== '\n') e++;
return b.slice(i, e).split('"').join('');
}
HTTPServer.registerEndpoint("anpr", function (req, res) {
if (req.method === "POST") {
st.hits++; st.t = Date.now();
let raw = req.body || "";
if (raw.length > MAX_BODY) { st.action = "body too big " + raw.length; raw = ""; }
let b = raw.split(" ").join("").split("\r").join("");
let plate = field(b, "PlateNumber");
if (plate !== null) {
st.plates++; st.plate = plate;
let allow = field(b, "AllowUser") === "true";
let block = field(b, "BlockUser") === "true";
if (!allow || block) st.action = "not allowed";
else if (!OPEN_ENABLED) st.action = "WOULD OPEN (disabled)";
else if (Date.now() - lastOpen < MIN_GAP_MS) st.action = "skip, opened " + (Date.now() - lastOpen) + " ms ago";
else {
lastOpen = Date.now(); st.opens++; st.action = "OPEN";
Shelly.call("Switch.Set", { id: OPEN_ID, on: true, toggle_after: 1 });
}
st.last = plate + " allow=" + allow + " block=" + block;
print("ANPR", st.last, st.action);
}
}
res.code = 200;
res.body = req.method === "GET" ? JSON.stringify(st) : '{"Result":true}';
res.send();
});
-
On each camera: add the allowed plates to its allow list, switch on HTTP push and point it at the address of the anpr script on the Shelly, with pictures off and the plate and allow-list fields on, and set the trigger to video detection. If the push never arrives, look at the address first: the Shelly rejects an extra sub-path, so the plain script address with a query string at the end works. We recommend mounting the cameras higher than plate height, looking down at the lane, so the plate travels down the picture and crosses a normal horizontal trigger line. Ours sit low, at plate height, which is an edge case: the plate hardly moves up or down in the picture. There the line has to be drawn slanted across the path the plate takes, at the point where a car has slowed but not stopped.
-
Add a second script, "auto-close", with
DRY_RUN: true. It sends CLOSE 60 seconds after the last opening, once the lane has been clear for 10 seconds in a row. For the travel time after a close command it watches the sensor and sends OPEN at once if something enters. After three reopenings in a row it stops until a person opens or closes the gate.
The rules it follows:
-
Any opening starts the clock. A plate, the phone app or a second car all reset the 60 seconds.
-
A car in the lane holds the gate open. The clear-lane count restarts every time the sensor sees something.
-
The sensor cannot open a closed gate. A cat walking past at night does nothing.
-
No sensor signal counts as blocked.
-
A remote press on a closed gate means "hold": the gate stays up until the remote is pressed again. Useful for a delivery or a busy arrival day.
// Auto-close. switch:0 STEP (remote) switch:1 CLOSE switch:100 OPEN input:100 true = lane clear
// It does not track the boom position: it assumes CLOSE on a lowered boom has no effect.
// Remote press on a closed gate = HOLD OPEN (no auto-close) until the remote is pressed again.
// The sensor can open the boom ONLY inside the guard window after a close command or remote press.
let CFG = { DRY_RUN: true,
TRAVEL_S: 10, // full close time + 2 s (MEASURE)
IDLE_S: 60, // no open command / remote press / reopen for this long
CLEAR_S: 10, // lane sensor continuously clear for this long
MAX_REOPEN: 3 };
let S = { active: false, hold: false, lastAct: 0, clearSince: 0, guardUntil: 0, reopens: 0, fault: false,
closes: 0, opens: 0, why: "boot" };
function now() { return Date.now() / 1000; }
function clear() { // null / missing / error = NOT clear
let s = Shelly.getComponentStatus("input:100");
return !!s && s.state === true && !(s.errors && s.errors.length);
}
function say(m) { if (S.why !== m) { S.why = m; print("AUTOCLOSE", m); } }
function pulse(id, what) {
if (CFG.DRY_RUN) { print("AUTOCLOSE DRY", what); return; }
Shelly.call("Switch.Set", { id: id, on: true, toggle_after: 1 });
}
function reopen(why) {
S.guardUntil = 0; S.reopens++; S.opens++; S.active = true; S.lastAct = now(); S.clearSince = 0;
if (S.reopens >= CFG.MAX_REOPEN) S.fault = true;
say("REOPEN: " + why + (S.fault ? " (FAULT: auto-close stopped until next open/remote)" : ""));
pulse(100, "OPEN");
}
function guard() { if (S.guardUntil && now() < S.guardUntil && !clear()) reopen("object in lane while closing"); }
Shelly.addStatusHandler(function (e) {
if (e.component === "input:100") { guard(); return; }
if (!e.delta || e.delta.output !== true) return;
let t = now();
if (e.component === "switch:100") { S.active = true; S.lastAct = t; S.guardUntil = 0; }
else if (e.component === "switch:0") { // STEP: BLU remote (source loopback) or app/phone
S.fault = false; S.reopens = 0;
let remote = e.delta.source === "loopback";
if (remote && !S.active && !S.hold) { S.hold = true; say("HOLD: opened by remote, stays up until remote is pressed again"); }
else { S.hold = false; S.active = !remote; S.lastAct = t; if (remote) say("remote close"); }
S.guardUntil = t + CFG.TRAVEL_S; guard();
}
else if (e.component === "switch:1") { S.guardUntil = t + CFG.TRAVEL_S; guard(); }
});
Timer.set(1000, true, function () {
let t = now(), c = clear();
if (!c) S.clearSince = 0; else if (!S.clearSince) S.clearSince = t;
if (S.guardUntil) {
if (t < S.guardUntil) { guard(); return; }
S.guardUntil = 0;
if (S.closes && S.why === "CLOSE sent") { S.active = false; S.reopens = 0; say("closed, idle"); }
}
if (S.hold || !S.active || S.fault) return;
if (t - S.lastAct < CFG.IDLE_S) { say("open, waiting " + CFG.IDLE_S + " s"); return; }
if (!c || t - S.clearSince < CFG.CLEAR_S) { say("waiting for clear lane"); return; }
S.closes++; say("CLOSE sent");
if (CFG.DRY_RUN) { print("AUTOCLOSE DRY CLOSE"); S.guardUntil = t + CFG.TRAVEL_S; }
else Shelly.call("Switch.Set", { id: 1, on: true, toggle_after: 1 });
});
HTTPServer.registerEndpoint("gate", function (req, res) {
res.code = 200; res.body = JSON.stringify({ dry: CFG.DRY_RUN, clear: clear(), t: now(), s: S }); res.send();
});
-
Test with an empty box under the boom, never a person or a car. Check each output on its own, then the sensor with the box at the near and the far edge of the lane, then the script log in dry-run. Time a full close with a stopwatch, set
TRAVEL_Sto that plus 2 seconds, and setDRY_RUN: false. -
Drive up with an allowed plate and with one that is not on the list, from each direction, by day and at night with headlights on.
Troubleshooting
-
The camera never captures a plate → check its trigger mode. Ours shipped set to a ground loop; set it to video detection and reboot the camera.
-
The gate opens with no car there → something requested a snapshot from the camera. A forced snapshot is pushed like a real capture, so never fetch snapshots from a camera that is armed to open the gate.
-
The boom reopens after every close → the sensor range is too long and it sees the road or the lowered boom. Shorten the range and aim straight across under the boom.
Tips
-
Use OPEN and CLOSE, not STEP, for anything automatic. A STEP press means "do the next thing", so a script can never be sure which way the boom will go.
-
Let the camera push. A script that polled the camera every 2 seconds made our Shelly stop answering for minutes.
-
A camera at plate height sees the plate move sideways, so a horizontal trigger line is never crossed. If it captures by day and misses at night, look at the trigger line and the glass first.
-
No sensor signal counts as blocked. With a cut wire or a missing add-on the gate will not close by itself, which is the safe direction.
-
The part of the lane beyond the sensor's range is not watched. That is one more reason to fit a photocell.
Devices Used
-
Shelly Pro 2
-
Shelly Pro Sensor Add-on
-
Shelly BLU RC Button 4 (optional)
Documentation & References
-
Shelly Pro 2 v.1 — potential-free contacts, 16 A per channel, and scripting support; useful here because O1 and O2 press the board's inputs and both scripts run on it.
-
Shelly Pro Sensor Add-on — digital input voltage levels and the solid-state output; useful for wiring the lane sensor in step 4 and the OPEN contact in step 3.
Check also:
-
Preventing Dry-Run Damage in a Home Water Pump System Using Shelly Pro 1PM JavaScript Automation — another Shelly Pro script built on a repeating timer and
Switch.Set; see it for adding and enabling a script in the web interface.
Why It's Worth It
Known cars drive up and the boom lifts in about 1.5 seconds, then closes behind them a minute later. A new guest is one line in each camera's allow list, and nothing in the barrier was replaced.
Conclusion
The barrier now has three clear commands and a controller that uses them. Cars on the list get in without a remote, and the boom comes down once the lane is empty. The remote still works, and a press on a closed gate now holds it open until the next press.
---
vertical: access-control
concept: plate-recognition-gate-auto-close
complexity: advanced
devices: [Shelly Pro 2, Shelly Pro Sensor Add-on]
optional_devices: [Shelly BLU RC Button 4]
---