You may be considered a Spanish tax resident if you spend more than 183 days in Spain during the calendar year. Spanish tax residency may also arise if the main centre or base of your economic activities or interests is in Spain. Sporadic absences may be included when determining the 183-day test unless tax residence in another country is demonstrated.
https://www.boe.es/buscar/act.php?id=BOE-A-2006-20764
Spain Tax Residency
More than 183 days in Spain in the current calendar year