Trying to set trigger entity_id from a variable

alias: Water Sensor Automation
description: ""
variables:
  my_entities: 
    - binary_sensor.water_3
    - binary_sensor.water_4

trigger:
  - platform: state
    entity_id: my_entities
      # - binary_sensor.water_3
      # - binary_sensor.water_4
    to: "on"
    variables:
      notify_title: Water Leak Detected!
      notify_message: A water leak has been detected at {{ trigger.entity_id }}!
      button_state: "true"

  - platform: state
    entity_id:
      - binary_sensor.water_3
      - binary_sensor.water_4
    from: "on"
    to: "off"
    variables:
      notify_title: Water Leak Cleared
      notify_message: A water leak has been cleared at {{ trigger.entity_id }}.
      button_state: "false"
condition: []

In order to ‘dry’ up the code, I am trying to eliminate the need to list the same set of entities multiple times. The second trigger is the standard method for triggering on multiple entities, and works perfectly. In the first trigger I have substituted the variable ‘my_entities’ for the individual entities list. This results in the error

Message malformed: Entity my_entities is neither a valid entity ID nor a valid UUID for dictionary value @ data[‘entity_id’]

Is there a syntax that will allow for the list of entity_id’s to be represented by a variable?

Generally, you use templating . However, state triggers do not allow templating for states or entities.

alias: Water Sensor Automation
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.water_3
      - binary_sensor.water_4
    to: 
      - "on"
      - "off"
    from: 
      - "on"
      - "off"
    variables:
      notify_value: "{{ iif(trigger.to_state.state == 'on', 'detected', 'cleared') }}"
      notify_title: Water Leak {{ notify_value | title }}!
      notify_message: A water leak has been {{ notify_value }} at {{ trigger.entity_id }}!
      button_state: "{{ trigger.to_state.state | bool }}"
condition: []