Sensor badlogin unknown

I have set sensor badlogin at sensor.yalm file:

- platform: command_line
    name: badlogin
    command: "grep -c 'Login attempt' /root/config/home-assistant.log"
    scan_interval: 10

I have set logger at configuration.yalm file:

logger:
  default: critical
  logs:
    homeassistant.components.http: warning

I tried twice to log with an invalid credentials into Home assistant. The action filled a log file by two string lines:
2021-04-09 22:03:42 WARNING (MainThread) [homeassistant.components.http.ban] Login attempt…
2021-04-09 22:03:58 WARNING (MainThread) [homeassistant.components.http.ban] Login attempt…

Unfortunately, the is status “unknown” of sensor entity “sensor.badlogin” at Overview. I would expect number 2 instead of “unknown”.

I have tested command grep -c ‘Login attempt’ /root/config/home-assistant.log at terminal and it returns number 2.

Could you please advise what is wrong and explain why I get “unknown” instead of number “2”?

Thank you very much,

Michal

Here is how I got it working on my supervised install.

- platform: command_line
  name: Bad Logins
  command: "LOGIN=`grep -c 'Login attempt' /config/home-assistant.log`; echo $LOGIN"

You may have to adjust the path to the log file.

Credit goes to @CCOSTAN with Halloween Countdown Command Line Sensor for getting me down the right path.

1 Like