Z-OFFSET Refinement

Has anyone delved into the code used by the Ender3 V3 KE for auto Z-OFFSET. I recently purchased this machine after owning a couple of first generation machines for 7 or 8 years. I found auto Z_OFFSET to be a real convenience with some limitations.
It works great for PLA at 0.2mm layer height. PETG expands when deposited so the nozzle would need to come up around 0.4mm. ASA seems to shrink. The Creality profile has extrusion at approx. 0.92 making matters worse. The nozzle needs to come down about 0.14mm.
I prefer not to make these adjustments on the front panel. I tried using SET_GCODE_OFFSET Z=-0.xx MOVE=0 in Orcaslicer>filament>advanced. It had no effect. I assume that the statement is applied too early in the gcode and is overwritten by the pre-printing calibration.
To add to my confusion, if I look in printer.cfg, I find the Z offset is something around +2.xx but when I look at the control panel on the machine, it is -2.xx, xx being considerably different. Inexplicable.
How are other people, who avoid the control panel doing this adjustment? Does anyone have a good method.
I am a pretty good Python programmer. If I understood the existing code, I could write a macro that would take a startup command something like SET_FILAMENT = PETG; and SET LAYER = THIN; and make the adjustment.
Thought? Suggestions?

I do not have any solid advice for you. If you have installed Fluidd, I would look at what it shows for offsets and config. That will give you a better idea of what is going on. Also, I often print from Orca, when I do that, it locks out the control screen. I think that means it’s bypassing at least some of the code Creality is appending to the start of a file. The Klipper and moonraker developer docs on GitHub may also be a big help to you.

I do have a question, since you said you’re decent with python. I’m working on an additional control panel for my printer. I’ll be using Python to code a program that that talks to my control.

How would you add a library and compile from the command line on the KE?

Mercifully, you don’t have to compile Python. It an interpreted language. If you can handle your project with gcode or existing Klipper commands you need to incude your macro in printer.cfg (ie. include mystuff.cfg). mystuff.cfg would incude your Klipper/gcode application. Here is a very elegant example. GitHub - kyleisah/Klipper-Adaptive-Meshing-Purging: A unique leveling solution for Klipper-enabled 3D printers!

If you really need Python, this developer has a method to add Python code in a very clean manner. Release v0.2 · droans/klipper_extras · GitHub It looks like it has not been maintained in 3 years. Scary. Still easier that paching Klipper manually.

I think my project could be accomplished by the first easier method. I need a better understanding of the existing code first.

I’m going to be polling an Arduino through the spi port, so my program will probably run separately from Klipper. I think that will save a lot of headache as well. I should still be able to use the libraries that Klipper has. I was planning on talking to Klipper/Moonraker through the API.

For what you’re trying to figure out. I don’t have a great understanding of Klipper. However, I think I would try and find the buffer that is being fed gcode and start moving upstream from there. The Klipper status documentation may help you if you haven’t seen it already.

You may already know this: the control panel on the KE is actually most of the control, it’s running Klipper and contains the SOC. I don’t know how all Creality differs from a standard RPi installation. There is Guppyscreen that replaces the Creality version. Not sure how deeply it replaces the Creality Klipper stuff, but it handles offsets and such. That might also be a fruitful place to look for info.