HikVision doorbel - who triggers it

I’ve been playing around with Hikvision integration that @pergola.fabio has created (thanks a million for this!).

I’ve got things setup and it works well for most of the things. But I want to be able to create a log of who triggered the lock to open. With pergola.fabio’s help I was able to single out a “control_source” value which the lock passes on to Home Assistant whenever it’s triggered.
It appears that there are at least three different types of values that get produced:

  • One for specifically created users, which can use fingerprints or keycards. In this case every user produces its own unique value, independent of what kind of item (fingerprint or keycard) you use to open the door.

  • Another for all the users who are defined as PIN-code users. So, unfortunately, there’s no separation of identity here.

  • Another one for when you unlock the door from the internal door station (I’ve just got the one, so I don’t know if each would get it’s own value.

What I want to do is have Home Assistant give me a readable notification of who/what opened the door.

I created an automation (with help of ChatGPT). It manages to capture the “control_source” value. But where it fails is to perform mapping of known values with names that I’ve assigned to those names. Instead it treats every values (even if it’s in the mapped section) as a new, unknown value.

I’m sure that this is just ChatGPT failing to do one final thing and me being very bad at coding :slight_smile: Can someone let me know what I’m doing wrong?

alias: Log Door Open with Control Source v2
description: Identification of who opens the door
triggers:
  - entity_id: switch.entry_door_relay_0
    to: "on"
    trigger: state
actions:
  - variables:
      control_source: "{{ trigger.to_state.attributes['control_source'] }}"
      control_source_mapping:
        "494848494849494848484900": Doorstation
        "073248723445752505300": User1
        "90328407234450505300": User2
        "1151179823481059900": PINuser
      person: "{{ control_source_mapping.get(control_source, 'Unknown') }}"
  - choose:
      - conditions:
          - condition: template
            value_template: "{{ person == 'Unknown' }}"
        sequence:
          - data:
              title: New Control Source Detected
              message: >
                The door was opened with a new control source value: '{{
                control_source }}'. Please update the control source mapping to
                associate it with a person.
            action: persistent_notification.create
  - data:
      title: Door Access Log
      message: >
        {{ now().strftime('%Y-%m-%d %H:%M:%S') }} - {{ person }} opened the door
        with '{{ control_source }}'
    action: persistent_notification.create