Failed Login Detection

Haven’t tried, but what happens when you test for it with a template trigger?

trigger:
  - platform: template
      value_template: '{% if (states.persistent_notification.name_of_notification.state) %}true{% else %}false{%endif%}'

edit: @fanaticDavid came to the rescue while I was testing my syntax

The notification works, however, it does give another notification when you dismiss. Ill have to work on the condition.

Hmmm try removing the single quotes around None, so:

condition:
  - condition: template
    value_template: "{{ trigger.to_state.state != None }}"
1 Like

That did the trick :slight_smile:

Update: It does create an empty notification (only the title, message is blanc) after dismissing the login failure persistant notification in the frontend which is kind of annoying. Any idea how to dismiss these in silence (or even better: dismiss them at once since I will allready be notified anyway)?

2 Likes

Found it.

The condition must be:

condition:
  - condition: template
    value_template: "{{ trigger.to_state.state != off }}"

Doesn’t work anymore after upgrading to 0.38.2 since there is no entry in the logfile anymore.

Update: same issue on 0.38.3

1 Like

And same on 0.38.4.

Works like a charm on 0.39 :slight_smile:

I have solved this by adding a value_template that always subtracts 1 :

- platform: command_line
  name: bad_login
  command: "grep -c 'Login attempt' /home/homeassistant/.homeassistant/home-assistant.log"
  value_template: '{{ value | int - 1 }}'

My sensor reports 0 after a restart and the actual number of bad logins when they occur.

1 Like

anyone using this be sure to validate that it still works after the 0.86 update. I noticed that persistent_notification.httplogin has become persistent_notification.http_login on my configuration which breaks the automation many are using.

(unique content to make the forum not freak out)

1 Like

Thanks a lot. This saved me a huge head ache.

1 Like

This discussion is old, but maybe it can still be useful …
to avoid another notification when ignoring… i use this condition…

from your github - pc_security

replace…

    condition:
      - condition: template
        value_template: "{{ trigger.to_state.state != 'None' and trigger.to_state.entity_id is defined}}"

and removed service: persistent_notification.dismiss

FYI the following seems a good workaround just by adding || true

command: ‘grep -c “Login attempt” /config/home-assistant.log || true’