Z offset rest after every print and nozzle gets closer to the print bed, restarting everything fixes the issue, please help!

Basic Information:

Printer Model: Ender3 pro
MCU / Printerboard: SKR MINI E3 V3
klippy.log

logs and print.cfg attached

printer.cfg (14.2 KB)
klippy.log (5.1 MB)

Issue: Z offset rest after every print and the nozzle gets closer to the print bed, restarting everything fixes the issue, please help!

[include fluidd.cfg]
# This file contains common pin mappings for the BIGTREETECH SKR mini
# E3 v3.0. To use this config, the firmware should be compiled for the
# STM32G0B1 with a "8KiB bootloader" and USB communication.

# The "make flash" command does not work on the SKR mini E3. Instead,
# after running "make", copy the generated "out/klipper.bin" file to a
# file named "firmware.bin" on an SD card and then restart the SKR
# mini E3 with that SD card.

# See docs/Config_Reference.md for a description of parameters.

#[delayed_gcode bed_mesh_init]
#initial_duration: .01
#gcode:
#  BED_MESH_PROFILE LOAD=default

[stepper_x]
step_pin: PB13
dir_pin: !PB12
enable_pin: !PB14
microsteps: 16
rotation_distance: 40
#rotation_distance = <full_steps_per_rotation> * <microsteps> / <steps_per_mm>
endstop_pin: ^PC0
position_endstop: 0
position_max: 245
#position_min: -2
homing_speed: 50

[tmc2209 stepper_x]
uart_pin: PC11
tx_pin: PC10
uart_address: 0
run_current: 0.580
stealthchop_threshold: 999999

[stepper_y]
step_pin: PB10
dir_pin: !PB2
enable_pin: !PB11
microsteps: 16
rotation_distance: 40
endstop_pin: ^PC1
position_endstop: 0
position_max: 229
#position_max: 235
#position_min: -6
homing_speed: 50

[tmc2209 stepper_y]
uart_pin: PC11
tx_pin: PC10
uart_address: 2
run_current: 0.580
stealthchop_threshold: 999999

[stepper_z]
step_pin: PB0
dir_pin: PC5
enable_pin: !PB1
microsteps: 16
rotation_distance: 8
#endstop_pin: ^PC2
#position_endstop: 0.0
endstop_pin: probe:z_virtual_endstop
position_max: 250
position_min: -8

[safe_z_home]
home_xy_position: 151,115   # Nozzle coordinates
speed: 250
z_hop: 15
z_hop_speed: 5

[tmc2209 stepper_z]
uart_pin: PC11
tx_pin: PC10
uart_address: 1
run_current: 0.580
hold_current: 0.500
stealthchop_threshold: 999999

[extruder]
step_pin: PB3
dir_pin: PB4
enable_pin: !PD1
microsteps: 16
#rotation_distance: 22.45
nozzle_diameter: 0.400
filament_diameter: 1.750
heater_pin: PC8
#sensor_type: EPCOS 100K B57560G104F
sensor_type: ATC Semitec 104NT-4-R025H42G
sensor_pin: PA0
control: pid
pid_Kp: 21.527
pid_Ki: 1.063
pid_Kd: 108.982
min_temp: 0
max_temp: 280
#pressure_advance = 0.16
#microsteps: 16
full_steps_per_rotation: 200
rotation_distance: 4.637
#nozzle_diameter: x.xx                              #define nozzle diameter
#filament_diameter: 1.750
max_extrude_only_distance: 500
max_extrude_only_velocity: 120
pressure_advance: 0.068        
#pressure_advance: 0.025                    #to be calibrated
pressure_advance_smooth_time: 0.040     #to be calibrated
##13.6mm high with the cube of that setting 0 + 13.6mm * .005



[tmc2209 extruder]
uart_pin: PC11
tx_pin: PC10
uart_address: 3
#run_current: 0.650
#stealthchop_threshold: 999999
interpolate: true
run_current: 0.85 #**
hold_current: 0.100
#sense_resistor: 0.11 #**
stealthchop_threshold: 0
driver_TBL: 0
driver_HEND: 6
driver_HSTRT: 7
driver_TOFF: 4

[heater_bed]
heater_pin: PC9
sensor_type: ATC Semitec 104GT-2
sensor_pin: PC4
control: pid
pid_Kp: 54.027
pid_Ki: 0.770
pid_Kd: 948.182
min_temp: 0
max_temp: 130

#Part cooling fan
[fan]
pin: PC6

#Heatsink cooling fan
[heater_fan heatsink_fan]
pin: PC7

#Motherboard controler fan
[controller_fan motherboard_fan]
pin: PB15

[mcu]
serial: /dev/serial/by-id/usb-Klipper_stm32g0b1xx_2A004A000650434E37343120-if00

[printer]
kinematics: cartesian
max_velocity: 300
max_accel: 3000
max_z_velocity: 5
max_z_accel: 100

[board_pins]
aliases:
    # EXP1 header
    EXP1_1=PB5,  EXP1_3=PA9,   EXP1_5=PA10, EXP1_7=PB8, EXP1_9=<GND>,
    EXP1_2=PA15, EXP1_4=<RST>, EXP1_6=PB9,  EXP1_8=PD6, EXP1_10=<5V>

# See the sample-lcd.cfg file for definitions of common LCD displays.

[bed_mesh]
speed: 120
horizontal_move_z: 5
mesh_min: 3.3,16
#mesh_max: 175,202
mesh_max: 192.3,215
probe_count: 6,6
#algorithm: bicubic
#mesh_pps: 2, 2
#bicubic_tension: .2

[bltouch]
sensor_pin: PC14
control_pin: PA1
x_offset: -52.7
y_offset: -14
#x_offset: -46
#y_offset: -6
z_offset = 0.800
#speed:

######################################################################
#  BigTreeTech TFT TouchScreen emulated 12864 mode
######################################################################

[display]
lcd_type: emulated_st7920
spi_software_miso_pin: PD8 # status led, Virtual MISO
spi_software_mosi_pin: PD6
spi_software_sclk_pin: PB9
en_pin: PB8
encoder_pins: ^PA10, ^PA9
click_pin: ^!PA15

[output_pin beeper]
pin: PB5

[virtual_sdcard]
path: /home/biqu/printer_data/gcodes

[display_status]

[pause_resume]

[virtual_sdcard]
path: /home/pi/printer_data/gcodes

#[gcode_macro START_PRINT]
#gcode:
#    {% set BED_TEMP = params.BED_TEMP|default(60)|float %}
#    {% set EXTRUDER_TEMP = params.EXTRUDER_TEMP|default(200)|float %}
    # Start bed heating
#    M140 S{BED_TEMP}  # Use absolute coordinates
#    G90 # Reset the G-Code Z offset (adjust Z offset if needed)
#    SET_GCODE_OFFSET Z=0.17 # Home the printer
#    G28 # Move the nozzle near the bed
#    BED_MESH_PROFILE LOAD=default # Load mesh
#    G1 Z5 F3000 # Move the nozzle very close to the bed
#    G1 Z0.15 F300 # Wait for bed to reach temperature
#    M190 S{BED_TEMP} # Set and wait for nozzle to reach temperature
#    M109 S{EXTRUDER_TEMP}

[gcode_macro START_PRINT]
gcode:
  {% set BED_TEMP = params.BED_TEMP|default(60)|float %}
  {% set EXTRUDER_TEMP = params.EXTRUDER_TEMP|default(200)|float %}
  LED_STARTING
  G90 ; use absolute coordinates
  M83 ; extruder relative mode
  M106 S50 ; Fan on approx. 20% to protect cooling ducts
  M140 S{BED_TEMPERATURE} ; set bed temp
  M104 S{EXTRUDER_STANDBY_TEMPERATURE} ; set standby extruder temp
  M190 S{BED_TEMPERATURE} ; wait for bed temp
  ; M109 S170 ; wait for extruder temp
  G28 ; home all
  BED_MESH_PROFILE LOAD=default # Load mesh
  M104 S{EXTRUDER_TEMPERATURE} ; set first layer extruder temp
  M109 S{EXTRUDER_TEMPERATURE} ; wait for extruder temp
  G1 Z2 F240
  G1 X2 Y10 F3000
  G1 Z0.28 F240
  G92 E0.0
  G1 Y210 E16.0 F1500.0 ; intro line
  G1 X2.3 F5000
  G1 Y10 E20 F1200.0 ; intro line
  G92 E0.0
  LED_PRINTING

[gcode_macro END_PRINT]
gcode:
    # Move nozzle away from print while retracting
    G91
    # Raise nozzle and retract
    G1 E-2 F1800
    G1 Z5 F3000
    # Move to absolute position
    G90
    G1 X10 Y200 F2000
    # Turn off bed, extruder, and fan
    M140 S0
    M104 S0
    M106 S0
    # Disable steppers
    M84
    M117 Print complete
    
#[gcode_macro END_PRINT]
#gcode:
    # Turn off bed, extruder, and fan
#    M140 S0
#    M104 S0
#    M106 S0
    # Move nozzle away from print while retracting
#    G91
#    G1 X-2 Y-2 E-3 F300
    # Raise nozzle by 10mm
#    G1 Z10 F3000
#    G90
    # Disable steppers
#    M84

[gcode_macro PAUSE]
description: Pause the actual running print
rename_existing: PAUSE_BASE
# change this if you need more or less extrusion
variable_extrude: 1.0
gcode:
  ##### read E from pause macro #####
  {% set E = printer["gcode_macro PAUSE"].extrude|float %}
  ##### set park positon for x and y #####
  # default is your max posion from your printer.cfg
  {% set x_park = printer.toolhead.axis_maximum.x|float - 5.0 %}
  {% set y_park = printer.toolhead.axis_maximum.y|float - 5.0 %}
  ##### calculate save lift position #####
  {% set max_z = printer.toolhead.axis_maximum.z|float %}
  {% set act_z = printer.toolhead.position.z|float %}
  {% if act_z < (max_z - 2.0) %}
      {% set z_safe = 2.0 %}
  {% else %}
      {% set z_safe = max_z - act_z %}
  {% endif %}
  ##### end of definitions #####
  PAUSE_BASE
  G91
  {% if printer.extruder.can_extrude|lower == 'true' %}
    G1 E-{E} F2100
  {% else %}
    {action_respond_info("Extruder not hot enough")}
  {% endif %}
  {% if "xyz" in printer.toolhead.homed_axes %}
    G1 Z{z_safe} F900
    G90
    G1 X{x_park} Y{y_park} F6000
  {% else %}
    {action_respond_info("Printer not homed")}
  {% endif %} 

[gcode_macro RESUME]
description: Resume the actual running print
rename_existing: RESUME_BASE
gcode:
  ##### read E from pause macro #####
  {% set E = printer["gcode_macro PAUSE"].extrude|float %}
  #### get VELOCITY parameter if specified ####
  {% if 'VELOCITY' in params|upper %}
    {% set get_params = ('VELOCITY=' + params.VELOCITY)  %}
  {%else %}
    {% set get_params = "" %}
  {% endif %}
  ##### end of definitions #####
  {% if printer.extruder.can_extrude|lower == 'true' %}
    G91
    G1 E{E} F2100
  {% else %}
    {action_respond_info("Extruder not hot enough")}
  {% endif %}  
  RESUME_BASE {get_params}

#[gcode_macro CANCEL_PRINT]
#rename_existing: BASE_CANCEL_PRINT
#gcode:
#    TURN_OFF_HEATERS
#    CLEAR_PAUSE
#    SDCARD_RESET_FILE
#    BASE_CANCEL_PRINT

[gcode_macro CANCEL_PRINT]
description: Cancel the actual running print
rename_existing: CANCEL_PRINT_BASE
gcode:
    TURN_OFF_HEATERS
    CANCEL_PRINT_BASE
    G91
    G1 z50 F600
    G90
    

[screws_tilt_adjust]
screw1: 74,47
screw1_name: front left screw
screw2: 245, 47
screw2_name: front right screw
screw3: 245, 217
screw3_name: rear right screw
screw4: 74,217
screw4_name: rear left screw
screw_thread: CW-M4

[gcode_macro M600]
gcode:
    {% set X = params.X|default(50)|float %}
    {% set Y = params.Y|default(0)|float %}
    {% set Z = params.Z|default(10)|float %}
    SAVE_GCODE_STATE NAME=M600_state
    PAUSE
    G91
    G1 E-.8 F2700
    G1 Z{Z}
    G90
    G1 X{X} Y{Y} F3000
    G91
    G1 E-50 F1000
    RESTORE_GCODE_STATE NAME=M600_state
    
#[bed_mesh]
#speed: 120
#horizontal_move_z: 10
#mesh_min: 10, 10
#mesh_max: 190, 190
#probe_count: 5, 5
#mesh_pps: 2, 2
#algorithm: bicubic
#fade_start: 1
##fade_target: 0


[gcode_macro BED_MESH_CALIBRATE]
rename_existing: BED_MESH_CALIBRATE_BASE
; gcode parameters
variable_parameter_AREA_START : 0,0
variable_parameter_AREA_END : 0,0
; the clearance between print area and probe area 
variable_mesh_area_offset : 5.0
; number of sample per probe point
variable_probe_samples : 2
; minimum probe count
variable_min_probe_count : 3
; scale up the probe count, should be 1.0 ~ < variable_max_probe_count/variable_min_probe_count
variable_probe_count_scale_factor : 1.0
gcode:
    {% if params.AREA_START and params.AREA_END %}
        {% set bedMeshConfig = printer["configfile"].config["bed_mesh"] %}
        {% set safe_min_x = bedMeshConfig.mesh_min.split(",")[0]|float %}
        {% set safe_min_y = bedMeshConfig.mesh_min.split(",")[1]|float %}
        {% set safe_max_x = bedMeshConfig.mesh_max.split(",")[0]|float %}
        {% set safe_max_y = bedMeshConfig.mesh_max.split(",")[1]|float %}

        {% set area_min_x = params.AREA_START.split(",")[0]|float %}
    {% set area_min_y = params.AREA_START.split(",")[1]|float %}
    {% set area_max_x = params.AREA_END.split(",")[0]|float %}
    {% set area_max_y = params.AREA_END.split(",")[1]|float %}

        {% set meshPointX = bedMeshConfig.probe_count.split(",")[0]|int %}
        {% set meshPointY = bedMeshConfig.probe_count.split(",")[1]|int %}
    
    {% set meshMaxPointX = meshPointX %}
    {% set meshMaxPointY = meshPointY %}


        {% if (area_min_x < area_max_x) and (area_min_y < area_max_y) %}
            {% if area_min_x - mesh_area_offset >=  safe_min_x %}
                {% set area_min_x = area_min_x - mesh_area_offset %}
            {% else %}
                {% set area_min_x = safe_min_x %}
            {% endif %}

            {% if area_min_y - mesh_area_offset >=  safe_min_y %}
                {% set area_min_y = area_min_y - mesh_area_offset %}
            {% else %}
                {% set area_min_y = safe_min_y %}
            {% endif %}

            {% if area_max_x + mesh_area_offset <=  safe_max_x %}
                {% set area_max_x = area_max_x + mesh_area_offset %}
            {% else %}
                {% set area_max_x = safe_max_x %}
            {% endif %}

            {% if area_max_y + mesh_area_offset <=  safe_max_y %}
                {% set area_max_y = area_max_y + mesh_area_offset %}
            {% else %}
                {% set area_max_y = safe_max_y %}
            {% endif %}

            {% set meshPointX = (meshPointX * (area_max_x - area_min_x) / (safe_max_x - safe_min_x) * probe_count_scale_factor)|round(0)|int %}
            {% if meshPointX < min_probe_count %}
                {% set meshPointX = min_probe_count %}
            {% endif %}
        {% if meshPointX > meshMaxPointX %}
                {% set meshPointX = meshMaxPointX %}
            {% endif %}

            {% set meshPointY = (meshPointY * (area_max_y -area_min_y ) / (safe_max_y - safe_min_y) * probe_count_scale_factor )|round(0)|int %}
            {% if meshPointY < min_probe_count %}
                {% set meshPointY = min_probe_count %}
            {% endif %}
        {% if meshPointY > meshMaxPointY %}
                {% set meshPointY = meshMaxPointY %}
            {% endif %}

            BED_MESH_CALIBRATE_BASE mesh_min={area_min_x},{area_min_y} mesh_max={area_max_x},{area_max_y} probe_count={meshPointX},{meshPointY} samples={probe_samples|int}
        {% else %}
            BED_MESH_CALIBRATE_BASE
        {% endif %}
    {% else %}
        BED_MESH_CALIBRATE_BASE
    {% endif %}


[gcode_macro LOAD_FILAMENT]
gcode:
   M83                            ; set extruder to relative
   G1 E30 F300                    ; load
   G1 E15 F150                    ; prime nozzle with filament
   M82

[gcode_macro UNLOAD_FILAMENT]
gcode:
   M83                            ; set extruder to relative
   G1 X125 Y50 Z80                ; move to servicing position
   G1 E10 F300                    ; extrude a little to soften tip
   G1 E-10 F3000                  ; jerk the filament out of the melt zone
   G1 E-50 F1800                  ; retract the rest of the way
   G1 E-10 F900                   ; retract the rest of the way
   M82

#*# <---------------------- SAVE_CONFIG ---------------------->
#*# DO NOT EDIT THIS BLOCK OR BELOW. The contents are auto-generated.
#*#
#*# [bed_mesh default]
#*# version = 1
#*# points =
#*# 	  -0.195000, -0.255000, -0.220000, -0.215000, -0.087500, 0.060000
#*# 	  -0.047500, -0.132500, -0.095000, -0.090000, -0.002500, 0.070000
#*# 	  0.010000, -0.110000, -0.095000, -0.092500, -0.032500, 0.010000
#*# 	  0.017500, -0.102500, -0.095000, -0.115000, -0.037500, -0.002500
#*# 	  0.000000, -0.132500, -0.122500, -0.130000, -0.070000, -0.025000
#*# 	  -0.017500, -0.127500, -0.127500, -0.147500, -0.082500, -0.035000
#*# x_count = 6
#*# y_count = 6
#*# mesh_x_pps = 2
#*# mesh_y_pps = 2
#*# algo = lagrange
#*# tension = 0.2
#*# min_x = 3.299999999999997
#*# max_x = 192.25
#*# min_y = 16.0
#*# max_y = 214.95