I am pretty certain that, providing your community do not ban it, you will need permission from regional gov (in my case it would be Junta de Andalusia) that means a regular inspection, with a fee (every so many years) and a permit.
Then, as a non resident, you will be required to pay, I think is just gone up from 24% to 25%, on the total income, including electricity and water bills, etc., with NO DEDUCTIONS allowed for anything, wear and rear, damage, loss of rent etc. nothing.
And, if you have the rent collected by an agency/ third party then maybe IVA too will have to added and IVA tax returns submitted (maybe every time the IVA is collected).
Resident owners get to make deductions.
Hope this may have changed since I investigated it for my son a couple of years ago, someone will tell you.
But, I know from asking several ‘experts’ (including some letting agencies) they all disagreed with each other but all changed their advice when I questioned parts of it. So I don’t know where you will get competent advice. Certainly not from people who have been renting for years (almost always illegally) and are not even aware of it.
Also, remember that letting also carries potential problems of non payer, damage, upsetting existing neighbours, having pets, noisy/destructive children, just to mention a few.
Good luck.