How does the HOTP dynamic truncation function generalize to longer hashes?
I managed to find it out by reproducing the test vectors.

TL;DR: The standard assumes that you use the low 4 bits of the last byte of the hash, regardless of its length. So replace 19 in the original DT definition with 31 for SHA-256 or 63 for SHA-512 and you are good to go.



Finding this out wasn't completely straightforward, as the standard only has a single test secret listed:


  The test token shared secret uses the ASCII string value
     "12345678901234567890".  With Time Step X = 30, and the Unix epoch as
     the initial value to count time steps, where T0 = 0, the TOTP
     algorithm will display the following values for specified modes and
     timestamps.


If fact, to reproduce the test vector values for SHA-256 and SHA-512 you have to extend that secret to 32/64 characters. I.e. use the ASCII strings "12345678901234567890123456789012" and "1234567890123456789012345678901234567890123456789012345678901234" instead.