Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Alerts #53

Open
reven opened this issue Oct 27, 2022 · 3 comments
Open

[Feature] Alerts #53

reven opened this issue Oct 27, 2022 · 3 comments
Labels
enhancement New feature or request planned To be implemented in future release

Comments

@reven
Copy link

reven commented Oct 27, 2022

Is your feature request related to a problem? Please describe.

No

Describe the solution you'd like

It would be great to have notifications (errors, task completion, etc). They could be informative and also be the basis for automations.

Describe alternatives you've considered

I've used a rest sensor for alerts but it often gives errors as the api returns empty json if there are none. I know that the api exposes notification dismissal too, but not sure how that would be implemented.

Additional context

@reven reven added the enhancement New feature or request label Oct 27, 2022
@tomaae
Copy link
Owner

tomaae commented Oct 27, 2022

can you give me endpoint which you used?

@reven
Copy link
Author

reven commented Oct 27, 2022

Of course!

The main alert endpoint is /api/v2.0/alert/list (GET). To dismiss an alert the endpoint is /api/v2.0/alert/dismiss (POST).

The rest sensor I had is below. As I said this gives errors in HA because if there are no alerts the json returned is []. I don't know if this is expected. The conditional tries to catch the exception, but I wasn't able to find a way to make the attribute loading conditional, which I guess is what fails because the Indexes don't exist if it's empty.

Hope this helps.

# Alerts. Error if response is empty.
- platform: rest
  name: tn_alert_level
  resource: http://___address___/api/v2.0/alert/list
  headers:
    Authorization: !secret tn_api_key
    Content-Type: application/json
    User-Agent: Home Assistant
  scan_interval: 300
  json_attributes:
    - level
    - formatted
  value_template: >
    {% if value_json is defined %}
      {{ value_json[0].level }}
    {% else %}
      {{ "None" }}
    {% endif %}
- platform: template
  sensors:
    ## Alert message
    tn_alert_message:
      unique_id: 6c8fd927-e198-4f0e-b67e-2d42e7c9ed04
      friendly_name: "Alert Message"
      value_template: "{{ state_attr('sensor.tn_alert_level', 'formatted') }}"

@tomaae
Copy link
Owner

tomaae commented Oct 27, 2022

Yes, that is most likely correct behavior since you query a list.
I will have a look into what we could do with alerts.

@tomaae tomaae added the planned To be implemented in future release label Oct 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request planned To be implemented in future release
Projects
None yet
Development

No branches or pull requests

2 participants