The 20-time Grand Slam champion decided to miss the clay-court season, as he did last year, in order to be fully prepared for Wimbledon, where he won a record eighth title last season.
The week-long Stuttgart event starts on June 11, the day after the men's French Open final at Roland Garros.
"On grass, my expectations are naturally high, so, I'm looking forward to once again playing in Stuttgart," Federer said in a statement on his website.
The 36-year-old also played the 2017 tournament, where he suffered a surprise loss in his first match to German veteran Tommy Haas, who has since retired.
The Swiss is currently second in the world rankings behind Rafael Nadal, but depending on his long-term rival's results on clay over the next six weeks, could arrive in Germany as the world number one.