Ah. Are you trying to use Routines?
You should look into Rule Machine for this. It’s a community created SmartApp that allows you to set up Rules based on triggers (in this instance presence) with conditions (here that will be time of day) and actions (your lights and thermostats).