Monitor log file of add-on for specific error message

I want to monitor the log-file of the tesla proxy add-on for specific error messages and report a message to my phone when this happens (for this topic, let’s ignore the part on sending a message).

What I’ve done so far:

  • i’ve found the way to browse the logs of add-ons by using :
    ha host logs --identifier addon_tesla_http_proxy
    (mind I’ve left out the full name of the identifier, don’t know if there’s security info there)
  • when grepping on this I get the error messages I’m looking for:
    ha host logs --identifier addon_tesla_http_proxy | grep 'Too Many Requests

I’ve tested this in a terminal using the 'advanced SSH & Web terminaladd-on and that works fine, without any errors (checked withecho$?` )

Now I think the way to get this integrated into HA is to use a command-line sensor

The YAML I use in the config file for that:

  - sensor:
      name: Tesla_Proxy_Log_API_limit_Error_Monitor
      unique_id: tesla_proxy_api_limit_error
      command: '/usr/bin/ha host logs --identifier addon_tesla_http_proxy | grep ''Too Many Requests'''
      scan_interval: 60
      value_template: >
        {% if value == '' %}
          No Error
        {% else %}
        {% endif %}

This is the part where I need help… When executing this the HA log reports
Command failed (with return code 1): /usr/bin/ha host logs --identifier addon_tesla_http_proxy | grep 'Too Many Requests'

To debug this I’ve tried to replace ‘No Error’ with {{ value }} to get the actual output of the command, this results in ‘unkown’ as sensor value.

I hope someone has build something similar or can get me a hint on how to proceed debugging/fixing this