Create a counter to know how many times user are logins

setup automations.yaml, automations.yaml and lovelace.yaml as attachments.
after I run the automations, counter will add 1, but when I login, the counter did not work.
I try ti find the Doc but I have no idea what entity_id con use for when user login?
could you help me. thank.

# configuration.yam
counter:
  user_login_count:
    name: User Login Count
    initial: 0
    step: 1
    icon: mdi:account-check


# automation:
  - alias: Increment User Login Counter
    trigger:
      - platform: event
        event_type: homeassistant_log
        event_data:
          message: 'Login attempt or success'
    condition:
      - condition: template
        value_template: "{{ 'success' in trigger.event.data.message.lower() }}"
    action:
      - service: counter.increment
        target:
          entity_id: counter.user_login_count


# Lovelace UI
type: entity
entity: counter.user_login_count

When you select “run” for an automation it will skip the triggers and conditions and just run the actions. That is why your automation will increment the counter when you run it manually.

However, the bigger issue is that there is no native event you can trigger off of when a user logs in. I’m not sure where you came up with the homeassistant_log event type, but I don’t think that is anything. There is a logbook_entry (defined here) and a system_log_event (defined here, must be enabled first) but neither will have anything regarding successful logins.

There was a custom integration in HACS that could provide this info (here), but it has been deprecated. There are a few forks of it that you could try (here is one).

1 Like