imhotep / hass-unifi-access

Unifi Access Integration for Home Assistant
Apache License 2.0
65 stars 16 forks source link

Feature Request: NFC/PIN Authorized Event as Trigger #17

Closed dirkgiessamer closed 7 months ago

dirkgiessamer commented 9 months ago

First of all, great work, much appreciated!

My use case would be that if the G2 Reader Pro „grants“ access to a user (via NFC or PIN, does not matter) this could be used as a trigger to do other stuff in HA (like unarming the alarm system). Quite similar to the „doorbell_pressed“ trigger a kind of „user_authorized“ trigger would be great. And even better to get the userID passed on to i.e. start a different scene on entry to the house for a certain person (play different welcome music etc).

imhotep commented 9 months ago

I like this idea! Would it be like a "last_authorized_user" text entity? I'd have to check whether we get user info events on unlocks but if we do, it should be pretty straightforward.

dirkgiessamer commented 9 months ago

Yes, as long as we get this info right away kind of „onUnlock“ and start an action, that would be perfect!

FermedePommerieux commented 9 months ago

This would be extraordinary to be able to do that.

imhotep commented 9 months ago

https://github.com/imhotep/hass-unifi-access/releases/tag/v1.1.3-beta

If you could help test it and report issues, I'd really appreciate it!

dirkgiessamer commented 9 months ago

Installation worked, the Logbook shows events (see screenshots), the events entities though show up as unavailable... Let me know what to do to help!

Screenshot 2024-01-17 at 10 22 39 Screenshot 2024-01-17 at 10 22 45 Screenshot 2024-01-17 at 10 22 50
imhotep commented 9 months ago

Have you tried opening the door or pressing the doorbell? Can you share some logs?

valerix85 commented 9 months ago

Hi guys, I've installed this morning without any issues

image

I've open a ticket on UniFi asking for the live stream via API if the doorbell is pressed, I'll keep you updated

dirkgiessamer commented 9 months ago

Have you tried opening the door or pressing the doorbell? Can you share some logs?

Yes, I did, doorbell as well as NFC opening the door - just checked again and now it works!

Screenshot 2024-01-17 at 22 33 50 Screenshot 2024-01-17 at 22 34 12

I like this idea! Would it be like a "last_authorized_user" text entity? I'd have to check whether we get user info events on unlocks but if we do, it should be pretty straightforward.

Did you check on this idea? To get the authorized user?

imhotep commented 9 months ago

Yes! It's in this release. Go to Developer Tools > Events > Listen to events and type one of these events then click on Start listening.

You should get some metadata when the event fires that gives you info on who entered or exited a door. It will be in the actor field.

ttjorvi commented 8 months ago

hi, just trying this integration and it looks pretty good.

Wondering if it would be possible to get the NFC friendly name or id as well as the actor in the event notificartion in the case where an actor has many NFC cards.

filip-heens commented 8 months ago

Yes! It's in this release. Go to Developer Tools > Events > Listen to events and type one of these events then click on Start listening.

  • unifi_access_entry
  • unifi_access_exit
  • unifi_access_doorbell_press_start
  • unifi_access_doorbell_press_stop

You should get some metadata when the event fires that gives you info on who entered or exited a door. It will be in the actor field.

Hi Imothep, I'm quite new into this part of the HA. (for now I always created the automations with "standard" building blocks ;-) When I go into the listen mode I do see the actor filled out as supposed, but do you have a link with examples on how to use this when e.g. the actor is user x then do action y

DaleJP commented 8 months ago

Hi, THANK YOU for this integration! Does this feature mean that I can have automation based on the card that entered the door?

I run a small nursery and preschool, and I want to log pickups and dropoffs using the data from Access. I'd like to be able to display avatars of the kids on the Classroom Dashboard, the number of children in the building for emergencies, and log the children's attendance. Having a trigger to work with from the Access API telling me who has entered and exited would be phenomenal.

DaleJP commented 8 months ago

This is fantastic. I have just successfully triggered an automation with the event.

image

I have managed to trigger a notification when the user enters the building.

Superb work.

Edit: unfortunately, the event fires on all readers, whether exit or entry, but I can work with that for now. I assume I can use the id field to determine which reader it was on. Do you have any advice on how I can use the context fields as a prerequisite for firing the automation?

filip-heens commented 8 months ago

Thanks DaleJP!!! It works... for your "problem" if you include the door_id or the door_name it should do the trick. I only have one Acces Reader, so I can't be 100% sure, but think that should do the trick

DaleJP commented 8 months ago

You have no idea how happy this integration has made me. I had an esp32 hooked up to the door to get doorbell notifications before. I mean the "id" field under contexts. They are all different readers on the same door. image

The inside reader is registered as "Exit" in Access and the outdoor ones are "Enter" but they both fire the event as entry.

filip-heens commented 8 months ago

I think that's, because you "enter" the door/gate when leaving in the opposite direction as you "enter" the door when "entering" (if you understand me ;-))

DaleJP commented 8 months ago

All of the readers show up as entry in the integration, whether inside or outside. It could be the API that's messing up. I know it's pretty new.

filip-heens commented 8 months ago

Dale, what I mean.

You Enter the building via entering the door/gate You leave the building via entering the door/gate in the opposite direction. That’s why I think they are saying “entering” (or I misunderstand what you are trying to say, that’s also a possibility 😉)

. . . . . . . . . . . . . . . . . . . . . Filip Heens ICT Consultant [data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAALIAAAA0CAYAAAAuY2KtAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAAFxEAABcRAcom8z8AAC2ySURBVHhe7Z2Hd1bVtvbzr9xv3HuP93iUFkhIQnohEEgPIQmhg2DvvaNi9xw7UqVKB0XEjtixHOxdRHqREkI6887f3Jm8K68RUfB+njOYgzX23quvuZ75rLnW3nlJkKMirS1HpelIh7S3i4pGSJuGZg2NGg5Lx9EGDYc1pakzrUOfxfK36+PRDo1SOXr0qLS1NUtL62Fpa6fcEY1t1dAuHR3U3655yBwFza2BdOr0q99Hob2jSes6ouVatO4j2s8GfW7S+lq0nUZLa9f71tYW7YsN4JjQZlNTkzQ2NkpLS4s9nwphnNR35MgRbbfVnl24p50w7t9BfFwnMra2tjY5fPjwMZ03NzebnrhnLtDbqdZPAphqb1U4KZi1HRUaAEwxIB9VEGsXFJhNes/EKTA1G31xELt0dCj4FGjtHY3S2tagAUBTpjsg6zNgVpC2dzQbKAFrBNRmi1fI2DUCNQo5ovU1a13N0tRM/Ty3Wd1trW2mNBSFEi1OlYoSo7aPWuAepf5W8fJeB3V7vQh1enu/p/4/q3Q3VpdQF4zbg+ufdNfHHwrkdiW+DsVth5JZVDcTBRvGgMz1qMB8ClAFULsWsI7wT+ero10H0+bWCisqcJW9W1oPSnPLIY2nvsii29ujfACZAJgBKOza1HxI8ys4FazE0Q+Yl2AGZGCO7gE7QGYFsI6ooLCGhgbZv3+/KSxqR1O1r4So/UjpnnaiQnnKdleOeA/hJP67CPryMTF+D65X0iEQDw5c0hDKuf5Jpy4vS9ypkIQmxWobhBe1qRUz0cqIyr6i4I3ADBMDYl1KFTjt6k8cVUoGxK0tHXK4oU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oGQc3NR2TlytUydEi59Dg7WbLSh0pG2lBJ7jtQAZch//n/+ij4EqVkaI3MfGKeTuyWYx0/3NAoX37xrdxz16OSm1kmfXrmSHrqUMnJrJABKcUK7gLp32+Q1llmcanJg6WXGkff3nkK5PGyYtkaaW/B0jjvjilux/bdav3TpaSkTNLSBsiECRPML3NBqfPnz5fa2lpJT09X1h4rs2fPlm+++cbY9LdIvMKpG3fm1ltvNQP57rvvOlNOTmgHxgsBcqJysqCgfLQid78HOJ7E6/O9996T8847T1JSUmxe8JOpG/Exnmg75A9dmF8S+2jIXjErkGOZ2azRcOQfswNdunSFlJfVKHhzjDkBY+aAUr2vUkAOVaZNUabOkiuvuFE2bHhT9uzZKx22k9QalO1XLFsr5SVjlcmHWLnMAWVqDGV2zcmstHpyMio1rlSBPVgBPUSGVUyUpYufkQ4YGQnmd9fO3TJ/3gIFap0ycpb6YxNNYaF8//335mYUFhbK4MGDzd148803jVERlInBAcwff/xRfvjhB91E7jIXhDTXB1cYBDYnL3XcfPPNUlVVJVdccYU9E0/YvXu3HDhwwOrFl6SMl9uzZ4/VTRp5du7caYF7JpoJc98TMJOXcizbBOqmDo76wonlnv76Rpd0Nl7kZ+6okzapj3jqok3i3Wiow8sj3hf6ThnaJeALE0c+BzBth3uHt99+Wy6++GIlmDRjZAdyjChjfacO+kW99He7HSjstf6Sn0D95AvLxYsBGby1K9hi+TheifnHgHLevKfUp61WIOcq6CokI7VU/dgqGZRfL3nZ1eYeJCnIJ4y/UHerz2iHdmonYg2/+vI7MnHcVQbclKQiA2y2Ajcva5jk5wy3a3Z6pWQNKFcQq3/Vv0SBfE5XIAfjAHALFixQH7lW8vJyVHEXqQFtODYxCAp64oknJDNT3Z+ePc1fe+WVV2yCCF] Patronale Life NV/SA Verzekeringsonderneming toegelaten onder code 1642, onder toezicht van de NBB Bd Bischoffsheimlaan 33 B-1000 Brussel/Bruxelles Tel: +32 2 4865090 (IT) http://www.patronale-life.be/www.patronale-life.behttps://www.patronale-life.be

From: DaleJP @.> Sent: maandag 5 februari 2024 9:34 To: imhotep/hass-unifi-access @.> Cc: Filip Heens @.>; Comment @.> Subject: Re: [imhotep/hass-unifi-access] Feature Request: NFC/PIN Authorized Event as Trigger (Issue #17)

External mail

All of the readers show up as entry in the integration, whether inside or outside. It could be the API that's messing up. I know it's pretty new.

— Reply to this email directly, view it on GitHubhttps://github.com/imhotep/hass-unifi-access/issues/17#issuecomment-1926459375, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AXJWG4UK72UJBW5O3OPWFKLYSCKPRAVCNFSM6AAAAABBD3CJC6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMRWGQ2TSMZXGU. You are receiving this because you commented.Message ID: @.***>

DaleJP commented 8 months ago

Well, I have two readers outside and one reader inside. In Unifi, the inside is marked "Exit" in the settings, the outdoor ones are both "Entry". Whichever reader I use, it shows up in unifi_access_entry, but with different ids in Context.

To be fair, I haven't listened to unifi_access_exit, yet......

ttjorvi commented 8 months ago

Tried it out on my access unit and got the following using one on the NFC assigned to me:

event_type: unifi_access_entry data: door_name: Cellar door_id: d7e39f94-7fdb-4dab-8852-191fc58b0deb actor: Thorr Tjorvi Einarsson type: unifi_access_entry origin: LOCAL time_fired: "2024-02-06T16:45:09.858770+00:00" context: id: 01HNZMY9B2V08XVW5QR55A2CTZ parent_id: null user_id: null Then with another NFC chip:

event_type: unifi_access_entry data: door_name: Cellar door_id: d7e39f94-7fdb-4dab-8852-191fc58b0deb actor: Thorr Tjorvi Einarsson type: unifi_access_entry origin: LOCAL time_fired: "2024-02-06T16:50:44.989503+00:00" context: id: 01HNZN8GKXE76RKE9QZH5BB2RH parent_id: null user_id: null

It would be good to know which NFC chip was used

DaleJP commented 8 months ago

Unfortunately, I think you would need to create a new id for the other card (Like it used to be with multiple cards for one user). They have encryption etc with the cards so I doubt they will ever expose the raw NFC data. Unifi might expose Card 01, Card 02 or something but I doubt they'll expose the card details over the API.

imhotep commented 7 months ago

Sorry for delay, been very busy. I released a new version and updated documentation on how to use the event feature. Looks like you guys have figured it out. @ttjorvi There is no NFC data accessible through the API as far as I can tell. I didn't dig in too much. Closing this for now but feel free to re-open if you have any questions or suggestions.