Hi All,
Does anyone use the Unifi access products (Access Ultra etc) as card readers integrated into openhab? I want to try and get events from an access ultra to do automations, or when Shelly 1 buttons are pressed, send unlock commands to the Access Ultra
Keen to see if anyone has done this?
Google Gemini says this is possibe:
You said
Is it possible to use Openhab webhooks binding to get events into openhab when the access ultra is used?
Gemini said
Yes, it is possible, but there is a specific "UniFi quirk" you need to know to make sure you get actual data (like the User's name) instead of just a generic "Door Unlocked" alert.
1. The Trap: Alarm Manager vs. Developer API
In the UniFi Access settings on your Cloud Gateway Max, you will see two places to set up webhooks.
Alarm Manager (Avoid): This sends a "surface-level" notification. OpenHAB will receive a hit, but the payload is often empty or missing the "Actor" (the person who swiped).
Developer API (Use This): You must create an API Token and register your OpenHAB webhook URL via the UniFi Access Developer API. This ensures the payload contains the full JSON structure with the actor (User Name) and location (Gate Name).
2. OpenHAB 5.0.2 Configuration (Full Script)
A. The Webhook Thing
First, install the Webhook Binding and create the Thing. This creates a local listener on your OpenHAB instance.
Code snippet
// File: /etc/openhab/things/unifi_access.things
Thing webhook:webhook:unifi_gate "UniFi Gate Webhook" [
id="unifi_gate",
expression="req.body"
]
Your endpoint will be: http://[OPENHAB_IP]:8080/webhook/unifi_gate
B. The DSL Items
Code snippet
// File: /etc/openhab/items/unifi_access.items
// This item updates every time the webhook is hit
DateTime Gate_Webhook_LastCall { channel="webhook:webhook:unifi_gate:lastCall" }
// We will extract the user from the JSON body in the rule
String Gate_Last_User "Last Gate User [%s]"
3. The JavaScript Rule (Trigger)
Since you prefer the JS Engine, this rule will fire when the webhook hits, parse the UniFi JSON, and log who just entered.
JavaScript
rules.JSRule({
name: "Handle UniFi Access Webhook",
description: "Parses UniFi Access JSON to identify the user",
triggers: [triggers.ItemStateChangeTrigger('Gate_Webhook_LastCall')],
execute: (event) => {
// Access the raw JSON body from the webhook
const rawBody = items.getItem('webhook:webhook:unifi_gate:lastCall').state;
// Note: You may need to pull from a secondary string channel if the binding
// doesn't store the full body in the lastCall item directly.
try {
const data = JSON.parse(rawBody);
// UniFi Access API structure: data.actor.display_name
const userName = data.data.actor.display_name;
const eventType = data.event; // e.g., "access.door.unlock"
items.getItem('Gate_Last_User').postUpdate(userName);
console.log(`Access Granted: ${userName} via ${eventType}`);
// Logic: If it's 2 AM and the user is 'Kris', turn on the Hallway Lights
if (userName === "Kris" && items.getItem('Night_Mode').state === 'ON') {
items.getItem('Hallway_Lights').sendCommand('ON');
}
} catch (e) {
console.error("Failed to parse UniFi Webhook JSON: " + e);
}
}
});
4. How to Register the Webhook with UniFi
You can't just type the URL into the UI for the Developer API; you usually have to send a one-time curl command to your Cloud Gateway Max to "subscribe" OpenHAB to the events.
The Command:
Bash
curl -X POST "https://[GATEWAY_IP]/proxy/access/api/v1/developer/webhooks" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"url": "http://[OPENHAB_IP]:8080/webhook/unifi_gate",
"events": ["access.door.unlock"]
}' --insecure
Summary of your "Hybrid" System:
Incoming (Fobs): Someone swipes → UniFi Ultra → Cloud Gateway Max → Webhook → OpenHAB.
Outgoing (Exit Button): You press button → Shelly 1 → OpenHAB → API Call → Cloud Gateway Max → UniFi Ultra → Gate Opens.
Would you like me to generate the OpenHAB 5.0.2 Item for the Shelly 1 that specifically matches the "Detached" switch mode for your exit button?
Thanks!