How to make notifications more efficient

I currently have the following notification set up:

Any suggestions on how to make it more efficient? They’re all false by default, but during an error the specific codes go to true. I’d like to just include the ones that are true in the notification.

alias: Hot Tub - Errors
description: ""
mode: single
triggers:
  - entity_id:
      - binary_sensor.spa_errors
    from: "off"
    trigger: state
conditions: []
actions:
  - action: telegram_bot.send_message
    metadata: {}
    data:
      message: |
        Hot Tub has errors.
        ERR1: "{{ state_attr('binary_sensor.spa_errors', 'system_err1') }}"
        ERR2: "{{ state_attr('binary_sensor.spa_errors', 'system_err2') }}"
        ERR3: "{{ state_attr('binary_sensor.spa_errors', 'system_err3') }}"
        ERR4: "{{ state_attr('binary_sensor.spa_errors', 'system_err4') }}"
        ERR5: "{{ state_attr('binary_sensor.spa_errors', 'system_err5') }}"
        ERR6: "{{ state_attr('binary_sensor.spa_errors', 'system_err6') }}"
        ERR7: "{{ state_attr('binary_sensor.spa_errors', 'system_err7') }}"
        ERR8: "{{ state_attr('binary_sensor.spa_errors', 'system_err8') }}"
        ERR9: "{{ state_attr('binary_sensor.spa_errors', 'system_err9') }}"
|```

This should get you most of the way there:

Hot Tub has errors.
{{states.binary_sensor.spa_errors.attributes.items()
| select('search', 'system_err') | selectattr(1, 'eq', true) 
| map(attribute=0) | map('replace', 'system_', '')| map('upper')
| join(', ') }}

You may need to play around with it to get whatever formatting you want.

1 Like

That looks fun! Where can I read up on what the map() command does? I’m struggling to find it in HA documentation.

EDIT: Found it in the ansible documentation :slight_smile:

Your config worked a treat!

1 Like

End result