MIAMI — Derrick Williams knows his decision in late June to opt out of the final year of his Knicks contract, worth $4.5 million, doesn’t look great now.

After signing a modest one-year Heat pact equivalent to his prior Knicks deal, Williams has played in just 11 of 20 games for the struggling Heat (7-13), who host the Knicks on Tuesday at AmericanAirlines Arena. But just wait, Williams says. The high-flying forward came to Miami for a reason — to improve his defense. And Williams says he has “by far’’ the best coach he’s ever had to teach him in Erik Spoelstra.

Nevertheless, Williams figured the Knicks would want him back when he became a free agent July 1. But he said he never heard from Phil Jackson and never got a single phone call from Knicks coach Jeff Hornacek after he was hired in May.

“For sure it was a tough decision,’’ Williams told The Post on Monday. “I love my time in New York. Being one of the fan favorites, leaving a place where I felt I could keep getting better, keep growing. But ultimately I feel it was the right decision. It might not seem that way right now. But I’m getting better each day. Even though I may not be on the court right now, this is for the second half of the season.”

After playing in 80 games last season as the Knicks’ most athletic player, the former No. 2 pick hasn’t found a permanent rotation spot.

“He’s been good, but that’s where we want to temper any kind of timeline or expectations with Derrick,’’ Spoelstra said. “He’s coming into a new system. He’s embraced our work [ethic], got in terrific shape, lost a lot of body fat. He’s learning our emphasis on our defensive system.’’

Williams started nine straight games in November with Justise Winslow out with a wrist sprain. Winslow is still out, but Williams has not played in three straight contests. With Miami’s James Johnson questionable with a sprained shoulder, Williams could get revenge on the Knicks.

“I’ll be ready,’’ he said.

“I didn’t talk to the Knicks after July 1,” Williams added. “I don’t know if they thought I was leaving. I was a little surprised there was not a lot of noise with them.’’

The Knicks could regret not monitoring Williams’ situation. They allocated their cap-space money to bring back reserve Lance Thomas, who’s been bothered by lingering plantar fasciitis. They also signed popular European rookie Mindaugas Kuzminskas, who at 27 is three years older than Williams.

“This is the best fit for my career,’’ Williams said. “Really having a coach to teach me the right ways to play defense. He really gets you in a defensive mode, with offense second. That’s what I needed in my career. I’m not worried if I’m playing this game or that game. S–t, last season I played 80 games. I’m not worried about it. I’m worried about playing the right way.”

After four forgettable seasons in Minnesota and Sacramento, Williams admits he had found a niche, living in Manhattan.

“I liked being that fan-favorite guy last season and be noticed out there,’’ Williams said. “That was the biggest thing in my career. A big spark for me, seeing fans embrace myself for the first time in my career. I thought it was awesome, man.”

You won’t get him to admit to “regret.”

“At the end of the day, it was my decision — sometimes you don’t have the full decision when traded,’’ Williams said. “I was the one who opted out and made the decision to leave. I loved playing there last season, some really good chemistry. This is where I want to be.’’