The situation seems to be under control
The lua script works and worked fine with the knobster encoder.
My stupid mistake was with incorrectly assigning a command to the AP disconnect button - "Disco servos, yaw damp, and trim any side".
This meant that once the trimmer was turned off, it would never be activated in AP mode again. Even after the flight is reset. Only restarting XP helped.
Now I assigned the command "Disco servos, fit dir" and everything is probably OK.