Turn on switch based on time and temperature

Hi all
After doing the basic automation projects i.e turn on lights after sunset, I felt confident to try out something that is abit more difficult.
The idea is that depending on the outdoor temperature I want to turn on a switch at different time. It should be uses to control the heating to my car.

My thoughts is to start out with a time bases automation project that passes the current temperature to a script and there set the offset for my homeassistant action. I have tried to google abit, but no luck so far.

So has anyone done somthing similar and are willing to share the result?

Br
Niklas

Here is how I do it: https://github.com/Danielhiversen/home-assistant_config/blob/master/automation/temp_control.yaml