Cooldown Script / Procedure

Hi,

I got some problems with warping on large PETG and sometimes PLA prints. I got a chamber so it helps if I cool down the part slowly. To do so I wrote a simple script that runs after the print. I'm not really into scripting, so this is really simple 8and probably not really a script):

When printed with 60°C Bed temperature it sets the bed temperature to 59°C, waits 120s and then sets it to 58°C and so on until it hits 30°C. Then it shuts the bed down.

M190 R69 ; 
G4 S120 ; wait for 2min
M190 R68 ; 
G4 S120 ; wait for 2min
M190 R67 ; 
G4 S120 ; wait for 2min
M190 R66 ; 
G4 S120 ; wait for 2min
M190 R65 ; 
G4 S120 ; wait for 2min
M190 R64 ; 
G4 S120 ; wait for 2min
M190 R63 ; 
G4 S120 ; wait for 2min
M190 R62 ; 
G4 S120 ; wait for 2min
M190 R61 ; 
G4 S120 ; wait for 2min
M190 R60 ; 
G4 S120 ; wait for 2min
M190 R59 ; 
G4 S120 ; wait for 2min
M190 R58 ; 
G4 S120 ; wait for 2min
M190 R57 ; 
G4 S120 ; wait for 2min
M190 R56 ; 
G4 S120 ; wait for 2min
M190 R55 ; 
G4 S120 ; wait for 2min

M190 R54 ; 
G4 S120 ; wait for 2min
M190 R53 ; 
G4 S120 ; wait for 2min
M190 R52 ; 
G4 S120 ; wait for 2min
M190 R51 ; 
G4 S120 ; wait for 2min
M190 R50 ; 
G4 S120 ; wait for 2min
M190 R49 ; 
G4 S120 ; wait for 2min
M190 R48 ; 
G4 S120 ; wait for 2min
M190 R47 ; 
G4 S120 ; wait for 2min
M190 R46 ; 
G4 S120 ; wait for 2min
M190 R45 ; 
G4 S120 ; wait for 2min
M190 R44 ; 
G4 S120 ; wait for 2min
M190 R43 ; 
G4 S120 ; wait for 2min
M190 R42 ; 
G4 S120 ; wait for 2min
M190 R41 ; 
G4 S120 ; wait for 2min
M190 R40 ; 
G4 S120 ; wait for 2min
M190 R39 ; 
G4 S120 ; wait for 2min
M190 R38 ; 
G4 S120 ; wait for 2min
M190 R37 ; 
G4 S120 ; wait for 2min
M190 R36 ; 
G4 S120 ; wait for 2min
M190 R35 ; 
G4 S120 ; wait for 2min
M190 R34 ; 
G4 S120 ; wait for 2min
M190 R33 ; 
G4 S120 ; wait for 2min
M190 R32 ; 
G4 S120 ; wait for 2min
M190 R31 ; 
G4 S120 ; wait for 2min
M190 R30 ; 
G4 S120 ; wait for 2min
M140 S0;
M106 S0
M84

I know not really creative, but this works ok. The problem is the to change the bed-temperature due to another filament. I have to adapt the script every time I change the the temperature. So is there a way to:

  1. read the actual target temperature
  2. set a new target temperature based on the old one -1° (M190 RX-1)
  3. wait 2min (G4 S120)
  4. and repeat until it hits 30°

Of course it would be great if I got a "custome gcode option" in my slicer Cura. But custom gcode can only be inserted in the pinter parameters. The Filament parameters don't have such an option and i couldn't find any plugin that allows me to do that.

Also related to this topic: Interrupt Cooldown:
How do I interrupt or skip the wait command if I don't need the cooldown? Sometimes it works to cancel the print via the dashboard, but this is not very reliable.

Thanks and regards
Kai

PS: Ender 3 V2, OctoPrint Version 1.4.2, Cura Version 4.7.1