@Ray11 you can see my whole config here: https://github.com/Duet3D/RRF-machine-config-files/tree/master/Creality_Ender_5/arhi-eth-centreZero-xrail-flex3drive/sys
so in config I do
M558 P1 C"zprobe.in" R2 H5 F1200 T3000 A3 S0.03 K0
G31 X0 Y0 Z0 P780
as config is not probing so I put some "low" value for P there (my probe never go below 780 so I use that but you can use P10)
then for homez:
https://github.com/Duet3D/RRF-machine-config-files/blob/master/Creality_Ender_5/arhi-eth-centreZero-xrail-flex3drive/sys/homez_orion.g
G90
G0 X0Y0 F3000 ; go to center of the bed, complain if X or Y not homed
G91 ; relative positioning
G0 Z5 F900 H2 ; drop bed for 5mm
G90 ; absolute positioning
G4S3 ; wait 3sec
G31 P{sensors.probes[0].value[0] + 8}
G30 ; Probe the bed at the current XY position.
; When the probe is triggered, set the Z coordinate
; to the probe trigger height.
So I set the trigger value dynamically just before I'm calling G30.
For mesh leveling bed.g is called when you call M32 so
https://github.com/Duet3D/RRF-machine-config-files/blob/master/Creality_Ender_5/arhi-eth-centreZero-xrail-flex3drive/sys/bed.g
G29 S2 ; delete compensations
M561 ; clear any bed transform
G31 P{sensors.probes[0].value[0] + 4}
G29 S0
Now, this is actually not ideal, it works for me most of the time but since I don't do mesh probing on every print but only from time to time it's acceptable.
What I plan to do when I get some spare time is to rewrite bed.g to not use G29S0 but to actually manually probe every point like is done in the sample here: https://duet3d.dozuki.com/Wiki/GCode_Meta_Commands (look at the example at the bottom) and I'd then do G31 P{sensor.probes[0].value[0]+4} before each G30. But as is now works and I have more pressing things to attend...