Help to my first automation: I have a doubt

You could also use a custom component like Schedy, This way you won’t have to code as much.