I made a bash script that does this with a smoother animation
It uses brightnessctl so you don’t have to run it with sudo
brightnessctl