How to use just one automation to switch on and off at certain times/eventt

Hello everyone…

I am a pretty eager user of home assistant and have a coulle things up and running, but i think it could be done smarter.
Right now i have an extra automation for turn on and turn off of lights…
And i actually would prefer have that in one and i am sure there is a way.
The turn on is looking like this:


alias: Switch_PorchLightOn
description: ""
trigger:
  - platform: sun
    event: sunset
    offset: "-00:01:00"
  - platform: time
    at: "04:50:00"
condition: []
action:
  - type: turn_on
    device_id: fdd4d2d321537d2a89fa8ae3da0821ca
    entity_id: switch.shelly1_8caab56e43a1
    domain: switch
mode: single

And the turn off like this:

alias: Switch_PorchLightOff
description: ""
trigger:
  - platform: time
    at: "07:00:00"
  - platform: time
    at: "21:00:00"
condition: []
action:
  - type: turn_off
    device_id: fdd4d2d321537d2a89fa8ae3da0821ca
    entity_id: switch.shelly1_8caab56e43a1
    domain: switch
mode: single

Would be happy if someone could direct me into the right direction.
I saw the toggle option, but i would like to know if i am turning on or off instead of just toggle without knowing the status

Thx alot upfront

How about something like:

trigger:
  - platform: state
    entity_id:
      - sun.sun
condition: []
action:
  - if:
      - condition: state
        entity_id: sun.sun
        state: below_horizon
    then:
      - service: light.turn_on
        data: {}
        target:
          entity_id: light.yard
    else:
      - service: light.turn_off
        data: {}
        target:
          entity_id: light.yard