BUT: It never sets to zero. Reason:
Sometimes when the command fails (during HA start process - I have no idea why it fails) there´s a line in the home_assistant.log like 2021-01-09 23:55:36 ERROR (SyncWorker_12) [homeassistant.components.command_line] Command failed: grep -c 'Login attempt' /config/home-assistant.log
And the next time the command_line sensor checks the .log file of course the string looking for is found.
Any ideas on how to work around that?
Is there a “grep everything except when xyz”?
(that way I could work around/exlude the lines containing >>>Command failed<<<: grep -c 'Login attempt')
Excluding findings from grep could be achieved with adding " | grep -v" so finally my sensor definition with the following line for the command part does the trick:
I worked around this by adding a second command_line sensor which grep´s explicitly for grep errors. The “Failed Logins” command_line sensor which includes actual failed logins plus false positives can now calculate the actual failed logins.
Still no idea why the grep command fails at all (guaranteed at least once per HA Core run time) but for the moment I can live with that workaround as it gives me real failed logins I can work with (automations, notifications, …).
That (was working for years) seems to be partly broken now after updating to HA 2022.4: now attributes (like hostname, user, new_ip) are completely missing. Don’t know why. Any ideas how to get this back? Mainly detecting new first time/logins for being able to *do something*.
Huh I guess you’re right! That info shows up in the notification though? I’ve never really had anything else set up other than that, so I didn’t even notice.