Custom GCode help

Part of my Printer custom GCode in PrusaSlicer is

M104 S{first_layer_temperature[0]*0.9} ; set extruder temp to 90%\n
M140 S[first_layer_bed_temperature] ; set bed temp\n
M190 S[first_layer_bed_temperature] ; wait for bed temp\n
M104 S[first_layer_temperature] ; set real extruder temp\n
M109 S[first_layer_temperature] ; wait for extruder temp\n

I did this because I didn't want the nozzle sitting a high temp waiting for bed.

Which works quite well except where I immediately restart. Then the nozzle temp is set to the 90% value even thought it's already above that and thus cools while bed heats. I'd like to add a condition to the effect that if nozzle temp greater than "{first_layer_temperature[0]*0.9}" then nozzle temp = "[first_layer_temperature]" else nozzle temp = "{first_layer_temperature[0]*0.9}".

Obviously thats not going to work as a slicetime thing so I want to migrate that simple logic to OctoPrint.

I assume this code would go in "Before print job starts". I've found the docs for Jinja but I don't understand the sysntax of last_temperature, can anyone help?

Seems like I should be using pause_temperature, is there a

You may have a look on this plugin. It's really smart.

and in addition this:

Thanks for your time, I'll check them out.