Look into templates for how to create variables and do math and working with time and timestamps is another subject you are looking at there.
Also You are saying automations, you are showing code related to blueprints, and asking in a blueprints category.
You are also sharing the minimum code, so any answer we give is at risk for being wrong because we don’t have any context.
My suggestion is post more of your code, clarify if blueprint or automation.
If this is a blueprint, do not start learing with these. Build automations first and learn how to do that. Get what you want working, then make the blueprint out of that by adding the !inputs and variables and such.
There are hundreds of examples of working blueprints in the blueprint exchange and I have about 20 of them in my link bottom of this message. Do a little reading, look thru some examples, and then come back with questions.
At this point we would be just writing your code for you because you don’t yet understand what you are doing, and I for one do not usually write code for others except when I build something and share that IE the links below.