If you need that an automation work only during the night you must configure the CONDITION as show below.
In automations.yaml file
Extra example