That's exactly what I'm trying to get my head around now! Haven't quite cracked it as the machine returns an error when it first hits the upper Z switch as the first step of the homing cycle. I'll post back here if/when I manage to implement it - wish me luck!