Having one Automation to cover multiple sensor states?

I have several windows sensors that have a state to determin if they are opened or closed.

Right now I have separate automations for performing an action when the sensor is open and when it is closed, and when it has been left open when the property is vacant (For example, reminding you to close the windows before you leave at night)

Is there any way to combine these together so that the same automation deals with both the opened and the closed events?

For example, if this is my code for the automation. The automation for closing it is identical except I’ve flipped the open and close around.

Can I have one automation that sends one message when the door is opened and another when it is closed, rather than two separate automations?

alias: Sensor_Loadingdock_Door_Opened
description: sends an email when the loading dock pedestrian door has been opened.
trigger:
  - platform: state
    entity_id:
      - binary_sensor.sensor_Loadingdock_door_opening
    from: "off"
    to: "on"
condition: []
action:
  - service: notify.email_notification
    data:
      message: The Loading Dock Pedestrian door was opened {{ now().strftime( '%d-%m-%y %H:%M') }}
      title: Loading Dock Door Opened ({{ now().strftime( '%d-%m-%y %H:%M') }})
      target: email.address.com
mode: single

Yes.

Set a Trigger ID for each trigger (click the 3 dots at the top right of the trigger and select “Edit ID”).

Then use a “Choose” action for each trigger ID, set the condition to “Triggered by” for each option.

You might need to change the mode for the automation, depending on how often it might get triggered, and how you want it to respond.

Could I please have a quick example, I’m not very familiar with the way that coding is done in Home Assistant so I don’t yet know how to do that, I’m still getting by modifying code to fit rather than writing it from scratch.

The examples I gave were using the UI. If you’re having issues with coding, it’s much easier to work in the UI to start. Here’s an example in code.

trigger:
  - platform: time
    at: "08:00:00"
    id: Time trigger 1
  - platform: time
    at: "08:25:00"
    id: Time Trigger 2
action:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - Time trigger 1
        sequence: []
      - conditions:
          - condition: trigger
            id:
              - Time Trigger 2
        sequence: []