I was able to do this with the free version of Alfred by
Forcing password on the screen saver in the OS settings (https://support.apple.com/en-us/HT204379)
Disabling Alfred from controlling the OS X Lock (optional)
Setting up Alfred to use lock or l (I use the latter) for controlling the screen saver
I understand this method won't work without Alfred, but ...
You could use a distance sensor. See related answer to related question:
A single distance sensor, properly placed, should be enough to detect
when you leave. That's the arduino part.
With python you can then use the serial over USB to read the output
from the arduino. And run the command to activate the screen lock,
according to your reading.
Which sensor could be used to detect that I left my seat?
There is no sensor in any Mac that can be used to detect if you left your seat.
Rhetorically speaking, how would this hypothetical sensor work? How would it differentiate between not being in your seat because you left and not being in your seat because you have a standing desk?
The answer is it ...