Help with list anchor in alert

repeat_freq: &repeat_freq
  - 5
  - 5
  - 5
  - 30

family_phones: &family_phones
  - mobile_app_iphone_14_pro
  - mobile_app_iphone

top_right_gas:
  name: Open top right gas
  done_message: Top right gas is closed
  entity_id: binary_sensor.top_right_gas_contact
  state: "on"
  repeat: *repeat_freq
  message: "Top right gas is open for {{ relative_time(states.binary_sensor.top_right_gas_contact.last_changed)}} from {{as_timestamp(states.binary_sensor.top_right_gas_contact.last_changed)|timestamp_custom('%A %I:%M%p') }}"
  can_acknowledge: true
  skip_first: true
  notifiers: *family_phones

I got this error when I do Check Configuration and the alert doesn’t fire off

Invalid config for ‘alert’ at alert.yaml, line 1: expected a dictionary for dictionary value ‘alert->repeat_freq’, got [5, 5, 5, 30]
Invalid config for ‘alert’ at alert.yaml, line 7: expected a dictionary for dictionary value ‘alert->family_phones’, got [‘mobile_app_iphone_14_pro’, ‘mobile_app_iphone’]

I suspect you are using a separate alerts.yaml file, and therefore are running into the limitation described here On ways of improving YAML configurations (anchors & secrets) - Configuration - Home Assistant Community (home-assistant.io) Because your dummy entries are under the alert key it’s throwing off the yaml parser.

AFAIK you have 3 options:
Define the alerts under configuration.yaml
Move your alerts to packages
Use the first real alert definition to create the anchors instead of the dummy entries you currently have.

I’d probably go for that last option in this case.

Also, I would use notifier groups for the notifiers: key instead of anchors/aliases. You get the same result with less hassle.

I’m no expert, but that’s my educated guess.

2 Likes

Yes, you are correct. I’m using a separate alert.yaml file. Could you illustrate how you do that with option 3? I also did move to the notifier group. Thank you for your help!

Using your code as the anchor example, then any alerts following can use the defined alias. If you’ve converted to notify groups you can remove the second anchor/alias.

top_right_gas:
  name: Open top right gas
  done_message: Top right gas is closed
  entity_id: binary_sensor.top_right_gas_contact
  state: "on"
  repeat: &repeat_freq
    - 5
    - 5
    - 5
    - 30
  message: "Top right gas is open for {{ relative_time(states.binary_sensor.top_right_gas_contact.last_changed)}} from {{as_timestamp(states.binary_sensor.top_right_gas_contact.last_changed)|timestamp_custom('%A %I:%M%p') }}"
  can_acknowledge: true
  skip_first: true
  notifiers: &family_phones
    - mobile_app_iphone_14_pro
    - mobile_app_iphone
next_alert_example:
  name: Next alert example using alias
  done_message: Make sure the anchor is defined before this
  entity_id: binary_sensor.mumble
  state: "on"
  repeat: *repeat_freq
  message: "Example message"
  skip_first: true
  notifiers: *family_phones
1 Like