Adaptive car heating with departure time input (Function of temperature and time)

I have been using homeassistant for one week and mostly to control central heat pump based on sport electricity prices. So I’m still pretty noob with this.

Even though, I would like to learn something new, but after 4hours of headache I think that it’s time to ask for assistance!

Living in Finland it’s freezing in winter and so come it’s recommendable to heat you car before starting it up.
What I would like to set up is a time_input on my dashboard stating the time that I’m about to leave with the car. Since the electricity prices are semi high here in europe, I wouldnt like to waste energy heating it too much nor guessing the temperature at the night and making assumptions.

So what I wish to have is a function with temperature and time (eg 45min at 0 celcius and up to 80min at -25 degrees). If a sliding value would be too hard to make then secondary option would be to set some temp. areas and give fixed times for those.
That is my problem number 1.

Main issue here is the actual timer. I do not know how to make a code for the automation. After trying out at least 3 different variations that I did found from earlier topics the end result still remains unsatisfactory. Mostly because they are implemented differently or they are way old and so come the instructions aint that easy to follow for a noob.

I can try and explain what I have tried so far but I will hold it for now and go with a simple question:

How would you do it?

If this is something that no one has done before nor finds any feasible approaches then I will try to explain the problems that I have encountered during my tries. Otherwise I try to remain silent for now, because I’m afraid that it could only cause some distraction since my skills aint that high and my approaches could be way off for someone more experienced!

Thank you for contributing already!

What i have is outside temp sensor and smart switch for the heater.

I haven’t yet implemented, but have found these examples how it could be done when I find time. Maybe you found these already…

-Engine heater automation
-Car engine heater for Nordic (and other cold climates) - #6 by marieper
-Car Heater (winter is coming) need coding help!

Kiitti aka thanks. Mostly new and untested by me. I had bad keywords to search I guess since those didnt come up earlier. As well as I just kept trying instead of studying.

Will come back if I get one working after researching these this time with bit more time.

I am still using the setup that is described in the second suggestion by @Perttu above. It uses a linear formula to calculate the run time.
You can use calculators like these: line with two points to determine a formula that fits your run time needs, in my case -6x+60 will give you 60 min @ 0o and 120 min @ -20 if I recall correctly.

I made some updates to the instructions recently, you should find them at the end of the thread.