Automation assist with calling multiple services most elegant way?

Hey all. I was wondering if I could get some help with this automation. It works fine as it is but I would like to change it up a bit so that I can attach the three devices that would that all use the same data template. You can see the - service: notify.mobile_app_iphone. Id like to know where can I move this in my automation so that it will use the same data template as the - service: tts.google_translate_say? I also want to add one more phone so I was wondering how to structure the automation for this additional - service: notify.mobile_app_iphone2. I tried playing with it but I guess I am still having a hard time understanding the rules for working with yaml.

- id: Broadcast Door open
  alias: Broadcast Door open
  description: ''
  trigger:
  - platform: state
    entity_id:
    - binary_sensor.garage_tilt_sensor
    - binary_sensor.family_room_slider_contact
    - binary_sensor.garage_side_door_contact
    - binary_sensor.garage_back_door_contact
  action:
  - service: media_player.volume_set
    data_template:
      entity_id: media_player.media_speakers
      volume_level: 1
  - service: tts.google_translate_say
    entity_id: media_player.media_speakers
    data_template:
      message: '{{ trigger.to_state.attributes.friendly_name }} {% if trigger.to_state.state
        == ''on'' %} Open {% else %} Closed {% endif %}'
  - service: notify.mobile_app_iphone
    data:
      title: Door Open/Close
      message: Door status has changed
  mode: single

If you use a variable you only have to create the template once.

  action:
  - variables:
      message: "{{ trigger.to_state.attributes.friendly_name }} {{ 'open.' if trigger.to_state.state == 'on' else 'closed.' }}"
  - service: media_player.volume_set
    data_template:
      entity_id: media_player.media_speakers
      volume_level: 1
  - service: tts.google_translate_say
    entity_id: media_player.media_speakers
    data_template:
      message: "{{ message }}"
  - service: notify.mobile_app_iphone
    data:
      title: Door Open/Close
      message: "{{ message }}"
  - service: notify.mobile_app_iphone2
    data:
      title: Door Open/Close
      message: "{{ message }}"
  mode: single
1 Like

This works so beautifully. Thank you for the help.