Intermittent error in Automation

Hello, i have this abomination of an automation that usually works, but it threw an odd error and bombed out the other night. For complete transparency, i did use AI to mash up two automations to give me a common notification.

The trace tells me I had the following error, “Executed: December 25, 2024 at 7:00:00 PM
Error: TemplateRuntimeError: No filter named ‘attributes.friendly_name’.”

Logger says this, "Logger: homeassistant.components.automation.notification_text_chores_trash
Source: helpers/script.py:2032
integration: Automation (documentation, issues)
First occurred: December 25, 2024 at 7:00:00 PM (1 occurrences)
Last logged: December 25, 2024 at 7:00:00 PM

Notification, Text - Chores & Trash: Error executing script. Error rendering template for variables at pos 2: TemplateRuntimeError: No filter named ‘attributes.friendly_name’."

Automation looks like this:

alias: Notification, Text - Chores & Trash
description: ""
triggers:
  - at: "19:00:00"
    trigger: time
conditions: []
actions:
  - action: calendar.get_events
    metadata: {}
    data:
      duration:
        hours: 24
        minutes: 0
        seconds: 0
      start_date_time: >
        {{ (today_at('00:00') + timedelta(days=1)).strftime('%Y-%m-%d %H:%M:%S')
        }}
    target:
      entity_id: calendar.columbus_trash_new
    response_variable: calendar_events_var
  - variables:
      calendar_events: |
        {{ calendar_events_var['calendar.columbus_trash_new']['events'] }}
      trash_message: |
        {% if calendar_events | count > 0 %}
          Tomorrow: {% for event in calendar_events %} {{ event.summary }} {% endfor %}
        {% else %}
          No trash collection events tomorrow.
        {% endif %}
      overdue_chores: >
        {% set c = states.sensor | selectattr('attributes.device_class',
        'defined') | selectattr('attributes.device_class', 'eq',
        'chore_helper__schedule') | selectattr('entity_id', 'has_value') | list
        %} {% set odcount = c | map(attribute='state') | map('int') |
        select('<', 0) | map('string') | list %} {{ c | selectattr('state',
        'in', odcount) | map(attribute='attributes.friendly_name') | list }}
      today_chores: >
        {% set c = states.sensor | selectattr('attributes.device_class',
        'defined') | selectattr('attributes.device_class', 'eq',
        'chore_helper__schedule') | selectattr('entity_id', 'has_value') | list
        %} {% set tcount = c | map(attribute='state') | map('int') |
        select('==', 0) | map('string') | list %} {{ c | selectattr('state',
        'in', tcount) | map(attribute='attributes.friendly_name') | list }}
      tomorrow_chores: >
        {% set c = states.sensor | selectattr('attributes.device_class',
        'defined') | selectattr('attributes.device_class', 'eq',
        'chore_helper__schedule') | selectattr('entity_id', 'has_value') | list
        %} {% set tmcount = c | map(attribute='state') | map('int') |
        select('==', 1) | map('string') | list %} {{ c | selectattr('state',
        'in', tmcount) | map('attributes.friendly_name') | list }}
      odqty: "{{ overdue_chores | count }}"
      odp1: "{{'is' if odqty == 1 else 'are'}}"
      odp2: "{{'s' if odqty != 1 else ''}}"
      tqty: "{{ today_chores | count }}"
      tp1: "{{'is' if tqty == 1 else 'are'}}"
      tp2: "{{'s' if tqty != 1 else ''}}"
      tmqty: "{{ tomorrow_chores | count }}"
      tmp1: "{{'is' if tmqty == 1 else 'are'}}"
      tmp2: "{{'s' if tmqty != 1 else ''}}"
      chore_message: |
        {% if odqty > 0 %}
          There {{odp1}} {{odqty}} overdue chore{{odp2}}: {{ overdue_chores | join(', ') }}.
        {% endif %} {% if tqty > 0 %}
          There {{tp1}} {{tqty}} chore{{tp2}} due today: {{ today_chores | join(', ') }}.
        {% endif %} {% if tmqty > 0 %}
          There {{tmp1}} {{tmqty}} chore{{tmp2}} due tomorrow: {{ tomorrow_chores | join(', ') }}.
        {% endif %}
      combined_message: >
        {{ trash_message }} {% if odqty > 0 or tqty > 0 or tmqty > 0 %} {{
        chore_message }} {% endif %}
  - condition: template
    value_template: "{{ calendar_events | count > 0 or odqty > 0 or tqty > 0 or tmqty > 0 }}"
  - action: notify.sms_jason_phone
    metadata: {}
    data:
      title: Daily Notification
      message: "{{ combined_message }}"
  - action: notify.sms_corinne_phone
    metadata: {}
    data:
      title: Daily Notification
      message: "{{ combined_message }}"
    enabled: true
mode: single

How do i troubleshoot this?

Thanks.

In the last map() in the definition for tomorrow_chores you are missing the attribute =… without that it is trying to apply attributes.friendly_name as a filter across all the items in c. Since it can’t find a filter called that, it produces an error telling you that.

Generally, it’s good practice to use the name property instead of the friendly_name attribute, just in case the frinedly_name isn’t properly defined. In those cases name will provide the entity ID instead of the “friendly” name.

  - variables:
      calendar_events: |
        {{ calendar_events_var['calendar.columbus_trash_new']['events'] }}
      trash_message: |
        {% if calendar_events | count > 0 %}
          Tomorrow: {% for event in calendar_events %} {{ event.summary }} {% endfor %}
        {% else %}
          No trash collection events tomorrow.
        {% endif %}
      ch_list: >
        {{ states.sensor | selectattr('attributes.device_class', 'defined') 
        | selectattr('attributes.device_class', 'eq', 'chore_helper__schedule') 
        | selectattr('entity_id', 'has_value') | list }}
      overdue_chores: >
        {{ ch_list  | selectattr('state', 'match', '-') | map(attribute='name') | list }}
      today_chores: >
        {{ ch_list  | selectattr('state', 'eq', '0') | map(attribute='name') | list }}
      tomorrow_chores: >
        {{ ch_list  | selectattr('state', 'eq', '1') | map(attribute='name') | list }}
....

Thank you! Sure enough, it’s missing. That’s probably it… I’ll have to go back and see where that dropped (AI?) because that portion was working…

Good tip on friendly name, too. Much appreciated.

I’ll make these changes and hopefully won’t be back. Thanks, again.