How to write, in short?

Guys, I have this kind of automation …

 - alias: door_bell

  trigger:

    - platform: state

      entity_id: binary_sensor.door_window_sensor_158d0003d08258

      to: 'off'      

  action:

    service: xiaomi_aqara.play_ringtone

    data:

      gw_mac: 34:ce:00:88:c1:a9

    ringtone_id: 10

      ringtone_vol: >

        {% if 0 <= now().hour <= 7 %}

          5

        {% else %}

          90

        {% endif %}

- alias: door_bell_2

  trigger:

    - platform: state

      entity_id: binary_sensor.door_window_sensor_158d0003d08258

      to: 'off'      

  action:

    service: xiaomi_aqara.play_ringtone

    data:

      gw_mac: 04:cf:8c:a1:17:12

      ringtone_id: 10

      ringtone_vol: >

        {% if 0 <= now().hour <= 7 %}

          5

        {% else %}

          90

        {% endif %}

In fact, both automations do the same thing, ring the bell, but on two different bases. Tell me if it is possible to write this more compactly, so that it is not two automation, but one. I just recently installed HA and I still can’t do everything)))

Well you could remove all the unneeded blank lines between every line of yaml. That would make it more compact.

There are no empty lines in the YAML file, they appear when copying the code from VSC to the browser. However, I appreciated your joke, it’s a pity that it is of little use.

I’m glad you recognised it was a joke. That was the intention.

You need to put three backticks, ```, on a line of their own before you paste to prevent that happening. It does make it a lot easier to read and thus help you.

Looking at your automations, you could put both triggers in the one automation and template gw_mac based on trigger variables (trigger.entity_id).