Any way to combine this into one automation?

I have about 12 sensors, and in essence, 12 automations. I’ve included 3 of them below… how can I merge this all into one automation?

At one point I was attempting to use a script that tried to combine them all, but if multiple sensors were in the ON state at the same time, i ran into issues where the wrong sensor’s datetime would be updated.

  - alias: Kitchen Window Last Opened
    trigger:
      - platform: state
        entity_id: binary_sensor.kitchen_window
        from: 'off'
        to: 'on'
    action:
    - service: input_datetime.set_datetime
      data_template:
        entity_id: >
         input_datetime.kitchen_window_open
        time: '{{ (as_timestamp(now()) | timestamp_custom("%H:%M:%S", true)) }}'
        date: '{{ (as_timestamp(now()) | timestamp_custom("%Y-%m-%d", true)) }}'
		
  - alias: Bedroom Window Last Opened
    trigger:
      - platform: state
        entity_id: binary_sensor.bedroom_window
        from: 'off'
        to: 'on'
    action:
    - service: input_datetime.set_datetime
      data_template:
        entity_id: >
         input_datetime.bedroom_window_open
        time: '{{ (as_timestamp(now()) | timestamp_custom("%H:%M:%S", true)) }}'
        date: '{{ (as_timestamp(now()) | timestamp_custom("%Y-%m-%d", true)) }}'
		
  - alias: Front Window Last Opened
    trigger:
      - platform: state
        entity_id: binary_sensor.front_window
        from: 'off'
        to: 'on'
    action:
    - service: input_datetime.set_datetime
      data_template:
        entity_id: >
         input_datetime.front_window_open
        time: '{{ (as_timestamp(now()) | timestamp_custom("%H:%M:%S", true)) }}'
        date: '{{ (as_timestamp(now()) | timestamp_custom("%Y-%m-%d", true)) }}'

Do you need to do it that way or can you use the built in last changed attribute or sql sensor instead of using input datetime to record state changes?

If you need to do it this way, there is a way but it just seem redundant.

Something like this

  - alias: State change to input date
    trigger:
      - platform: state
        entity_id: 
          - binary_sensor.bedroom_window
          - binary_sensor.kitchen_window
        from: 'off'
        to: 'on'
    action:
    - service: input_datetime.set_datetime
      data_template:
        entity_id: >
         input_datetime.{{ trigger.entity_id }}_open
        time: '{{ (as_timestamp(now()) | timestamp_custom("%H:%M:%S", true)) }}'
        date: '{{ (as_timestamp(now()) | timestamp_custom("%Y-%m-%d", true)) }}'

I will give this a try and see what happens. I wanted to do it this way since the last_triggered field has issues with binary sensors, and resets on a reboot of hass i think.