Do something if lock is locked with code

This is the app @jhamstead is referring to.

If you do decide to use note that it does not need a custom DH but works with the stock ST DH for standard feature like programming user codes and running routines etc when a user unlocks using their codes.

There is a custom DH available also if to allow for enhanced features which a lock may provide like alarms/sensors and one touch locking using codes (and running custom routines / actions etc). But for what you’re asking the stock DH will suit it fine.

There is an alternative version of the app available if you don’t want to program codes remotely and only monitor and execute actions when users use the lock.

I believe you can also use CoRE to achieve then same (execute actions when users unlock the door) but I would recommend that if you have a few users. When the list grows its helps to have a dedicated user management and user monitoring app.