Simple and Effective Alerting

Jan 2025 Update

I took some time over the last few days to convert the majority of my dashboards to the use of sections and use the UI instead of the yaml files. It was pretty straightforward once I figured out how to paste in yaml to the UI from my existing config and make the minor format changes required.

One of the issues that has cropped up over the past 6 months is the auto-entities cards are not fully hiding the way they should. This means there is additional lines of space at the top of your dashboard which is especially noticeable when you 8 of the cards stacked together the way I do. See issue - show_empty in Sections view · Issue #433 · thomasloven/lovelace-auto-entities

I don’t believe the original author of the auto-entities is active recently, so I decided the easiest thing to do was wrap them in conditional cards which, while not ideal, is working great. The only caveat is that you need to create binary template sensors with the same filter to control the conditional cards. Since many have copied my earlier configuration, I thought I’d update this post to include the new dashboard updates.

Additionally, I made a few style changes to the cards so they work better with themes. For instance, the informational type boxes now used the same background and font colors as the top view bar rather than blue.

image

Updates required to use conditional cards

New sensors required for conditional cards. These give you a count of each alert type. Note that I listed all of mine, but you only need to use those that apply to your build.

- template:
  - sensor:
      ## Note that all these count sensors are a workaround for extra space left between the custom:auto-entities cards when they are empty.  Putting the dashboard alerting in conditional cards.
      - name: "Active Crit Alerts Count"
        state: >
          {% set alerts = states.alert | selectattr('entity_id', 'match', '^alert.*_crit_alert_active$') | list %}
          {{ alerts | rejectattr('state', 'in', ['off', 'idle']) | list | length }}
        attributes:
          active_alerts: >
            {% set alerts = states.alert | selectattr('entity_id', 'match', '^alert.*_crit_alert_active$') | list %}
            {{ alerts | rejectattr('state', 'in', ['off', 'idle']) | map(attribute='entity_id') | list }}
      - name: "Active Warn Alerts Count"
        state: >
          {% set alerts = states.alert | selectattr('entity_id', 'match', '^alert.*_warn_alert_active$') | list %}
          {{ alerts | rejectattr('state', 'in', ['off', 'idle']) | list | length }}
        attributes:
          active_alerts: >
            {% set alerts = states.alert | selectattr('entity_id', 'match', '^alert.*_crit_warn_active$') | list %}
            {{ alerts | rejectattr('state', 'in', ['off', 'idle']) | map(attribute='entity_id') | list }}
      - name: "Active Info Alerts Count"
        state: >
          {% set alerts = states.alert | selectattr('entity_id', 'match', '^alert.*_info_alert_active$') | list %}
          {{ alerts | rejectattr('state', 'in', ['off', 'idle']) | list | length }}
        attributes:
          active_alerts: >
            {% set alerts = states.alert | selectattr('entity_id', 'match', '^alert.*_info_warn_active$') | list %}
            {{ alerts | rejectattr('state', 'in', ['off', 'idle']) | map(attribute='entity_id') | list }}
      - name: "Acknowledged Alerts Count"
        unique_id: acknowledged_alerts_count
        state: >
          {% set alerts = states.alert | list %}
          {{ alerts | rejectattr('state', 'in', ['on', 'idle']) | list | length }}
        attributes:
          acknowledged_alerts: >
            {% set alerts = states.alert | list %}
            {{ alerts | rejectattr('state', 'in', ['on', 'idle']) | map(attribute='entity_id') | list }}
      - name: "Water Issues Count"
        state: >
          {% set sensors = states | selectattr('attributes.device_class', 'eq', 'moisture') | list %}
          {{ sensors | rejectattr('state', 'in', ['off', 'unavailable', 'unknown']) | rejectattr('entity_id', 'search', 'weather') | list | length }}
        attributes:
          water_issues: >
            {% set sensors = states | selectattr('attributes.device_class', 'eq', 'moisture') | list %}
            {{ sensors | rejectattr('state', 'in', ['off', 'unavailable', 'unknown']) | rejectattr('entity_id', 'search', 'weather') | map(attribute='entity_id') | list }}
      - name: "Tech Issues Count"
        state: >
          {% set devices = expand('group.network_devices', 'group.server_devices', 'group.wan_devices') %}
          {{ devices | rejectattr('state', 'in', ['on', 'unavailable']) | list | length }}
        attributes:
          tech_issues: >
            {% set devices = expand('group.network_devices', 'group.server_devices', 'group.wan_devices') %}
            {{ devices | rejectattr('state', 'in', ['on', 'unavailable']) | map(attribute='entity_id') | list }}
      - name: "Information Count"
        state: >
          {% set entities = expand('group.device_uptimes') | selectattr('state', 'match', '[0-9] minutes') | list %}
          {{ entities | length }}
        attributes:
          matching_entities: >
            {% set entities = expand('group.device_uptimes') | selectattr('state', 'match', '[0-9] minutes') | map(attribute='entity_id') | list %}
            {{ entities }}

I also created a manual toggle switch to hide my “Possible issues” card which is a very useful card to quickly spot issues that come up, but sometimes I know what the issue is and don’t want to look at the warning once I know I need to get it fixed.

input_boolean:
  show_possible_issues:
    name: Show Possible Issues
    initial: false

The config I’m providing below is to create a full new section view if you use all of it. The easiest way to do that is by creating a new section view, then edit in yaml as you see in the screenshot. Delete the few lines in the new view, then paste the full text of the config.

title: Home
sections:
  - type: grid
    cards:
      - type: conditional
        conditions:
          - condition: numeric_state
            entity: sensor.active_crit_alerts_count
            above: 0
        card:
          type: custom:auto-entities
          show_empty: true
          card:
            type: entities
            title: Active Critical Alerts
            card_mod:
              style: |
                ha-card {
                  background-color: red;
                  --primary-text-color: white;
                  --secondary-text-color: white;
                  --paper-item-icon-color: white;
                }
          filter:
            include:
              - entity_id: /^alert(.).*_crit_alert_active/
                options:
                  secondary_info: last-changed
            exclude:
              - state: "off"
              - state: idle
          sort:
            method: last_changed
            reverse: true
      - type: conditional
        conditions:
          - condition: numeric_state
            entity: sensor.active_warn_alerts_count
            above: 0
        card:
          type: custom:auto-entities
          show_empty: true
          card:
            type: entities
            title: Active Warning Alerts
            card_mod:
              style: |
                ha-card {
                  background-color: orange;
                  --primary-text-color: white;
                  --secondary-text-color: white;
                  --paper-item-icon-color: white;
                }
          filter:
            include:
              - entity_id: /^alert(.).*_warn_alert_active/
                options:
                  secondary_info: last-changed
            exclude:
              - state: "off"
              - state: idle
          sort:
            method: last_changed
            reverse: true
      - type: conditional
        conditions:
          - condition: numeric_state
            entity: sensor.active_info_alerts_count
            above: 0
        card:
          type: custom:auto-entities
          show_empty: true
          card:
            type: entities
            title: Active Information Alerts
            card_mod:
              style: |
                ha-card {
                  background-color: var(--app-header-background-color);
                  --primary-text-color: var(--app-header-text-color);
                  --secondary-text-color: var(--app-header-text-color);
                  --paper-item-icon-color: var(--app-header-text-color);
                }
          filter:
            include:
              - entity_id: /^alert(.).*_info_alert_active/
                options:
                  secondary_info: last-changed
            exclude:
              - state: "off"
              - state: idle
          sort:
            method: last_changed
            reverse: true
      - type: conditional
        conditions:
          - condition: numeric_state
            entity: sensor.acknowledged_alerts_count
            above: 0
        card:
          type: custom:auto-entities
          show_empty: true
          card:
            type: entities
            title: Acknowledged Alerts
            card_mod:
              style: |
                ha-card {
                  background-color: var(--app-header-background-color);
                  --primary-text-color: var(--app-header-text-color);
                  --secondary-text-color: var(--app-header-text-color);
                  --paper-item-icon-color: var(--app-header-text-color);
                }
          filter:
            include:
              - domain: alert
                options:
                  secondary_info: last-changed
            exclude:
              - state: "on"
              - state: idle
          sort:
            method: last_changed
            reverse: true
      - type: conditional
        conditions:
          - condition: numeric_state
            entity: sensor.water_issues_count
            above: 0
        card:
          type: custom:auto-entities
          show_empty: true
          card:
            type: entities
            title: Water Issues
            card_mod:
              style: |
                ha-card {
                  background-color: red;
                  --primary-text-color: white;
                  --secondary-text-color: white;
                  --paper-item-icon-color: white;
                }
          filter:
            include:
              - attributes:
                  device_class: moisture
                options:
                  secondary_info: last-changed
            exclude:
              - state: "off"
              - state: unavailable
              - state: unknown
              - entity_id: "*weather*"
      - type: conditional
        conditions:
          - condition: numeric_state
            entity: sensor.tech_issues_count
            above: 0
        card:
          type: custom:auto-entities
          show_empty: true
          card:
            type: entities
            title: Tech Issues
            card_mod:
              style: |
                ha-card {
                  background-color: orange;
                  --primary-text-color: white;
                  --secondary-text-color: white;
                  --paper-item-icon-color: white;
                }
          filter:
            include:
              - group: group.network_devices
                options:
                  secondary_info: last-changed
              - group: group.server_devices
                options:
                  secondary_info: last-changed
              - group: group.wan_devices
                options:
                  secondary_info: last-changed
            exclude:
              - state: "on"
              - state: unavailable
      - type: conditional
        conditions:
          - condition: numeric_state
            entity: sensor.information_count
            above: 0
        card:
          type: custom:auto-entities
          show_empty: true
          card:
            type: entities
            title: Information
            card_mod:
              style: |
                ha-card {
                  background-color: var(--app-header-background-color);
                  --primary-text-color: var(--app-header-text-color);
                  --secondary-text-color: var(--app-header-text-color);
                  --paper-item-icon-color: var(--app-header-text-color);
                }
          filter:
            template: |
              {{
                expand('group.device_uptimes') 
                | selectattr('state', 'match', '[0-9] '[0-9] [Mm]inutes') 
                | map(attribute='entity_id') 
                | list 
              }}
      - type: conditional
        conditions:
          - condition: state
            entity: input_boolean.show_possible_issues
            state: "on"
        card:
          type: custom:auto-entities
          show_empty: false
          card:
            type: entities
            title: Possible Issues
            show_header_toggle: false
            card_mod:
              style: |
                ha-card {
                  background-color: var(--app-header-background-color);
                  --primary-text-color: var(--app-header-text-color);
                  --secondary-text-color: var(--app-header-text-color);
                  --paper-item-icon-color: var(--app-header-text-color);
                }
          filter:
            include:
              - state: unknown
              - state: unavailable
            exclude:
              - entity_id: device_tracker.*
              - entity_id: person.*
              - entity_id: group.*
              - entity_id: scene.*
              - entity_id: update.*
              - entity_id: event.*
              - entity_id: sensor.stokerbbq*
              - entity_id: sensor.auto_backup_last_failure
              - entity_id: sensor.*_last_ding
              - entity_id: switch.wall*_dimmer*
              - entity_id: button.*
              - entity_id: sensor.weatherflow_wind_*
              - entity_id: sensor.weatherflow_feels_*
              - entity_id: number.*_effect_speed
              - entity_id: binary_sensor.updater
              - integration: twinkly
              - entity_id: vacuum.vacuum_fairy
              - entity_id: "*alarm*"
              - entity_id: "*timer*"
              - entity_id: "*reminder*"
              - entity_id: "*shuffle*"
              - entity_id: "*repeat*"
              - entity_id: "*do_not_disturb*"
              - entity_id: media_player.*
              - entity_id: select.gaming*
              - entity_id: "*t*.home_assistant*"
              - entity_id: sensor.*last_seen
              - entity_id: sensor.*spotify*
              - entity_id: sensor.meater*
              - entity_id: "*.speedtest_wan_two_*"
              - integration: mqtt

Obviously, your configuration will be different than mine, so you can also just pick and choose the individual cards and sensors you need from the config above and paste them in directly, as necessary.

FYI - @andrewjswan

Also @vesar, I don’t know of any universal notification handler like you mention, however I did recently start using the :round_pushpin: State Notifications & Actions - Blueprints Exchange - Home Assistant Community which meets the majority of my needs, and they are pretty easy to maintain. Combine that with some of the new categorization and labels, and it can even be organized pretty well.

4 Likes