HAMILTON HEIGHTS — He hit the housing lottery.

For more than six years, Ramon Hernandez had no idea his frigid, rat-plagued, crumbling apartment would turn out to be a gold mine.

Last summer, the state awarded him $112,000 after he contested his rent and discovered he was being overcharged more than $1,000 a month.

“It feels great,” Hernandez, 55, said in Spanish. “It’s like the landlord is being punished for years of bad service.”

In 2006, when he and his family moved to 701 Saint Nicholas Ave., he thought $1,300 for a four-bedroom was a fair deal, even with rats in the building and holes in the kitchen floor, he said.

It wasn’t until 2012, when a neighbor put him in touch with a tenant advocacy group, Pa'Lante, that he looked into the apartment’s rent history and discovered that the legal rent of the apartment was actually $233 a month.

He reported the landlord to the state's Division of Housing and Community Renewal (DHCR) and asked officials there to open an investigation into how much he was owed for back rent.

It turned out that in 1993, former tenant Carl Brown complained about broken doors, windows and kitchen appliances. The state froze Brown's rent at $233 until the landlord resolved the issues, records show.

When Brown moved out in 2001, the landlord still had not fixed the issues, yet the rent was jacked up to $900 a month. The next tenant, Wendy Ramirez, who lived there until 2006 and saw her rent increase to $1,000, never challenged the rate, records show.

In June 2014, DHCR awarded Hernandez $112,000 for the rent overcharge. The building owner, Nevei Bais, has appealed the decision, records show.

“People need to wake up because they all have their eyes closed like I did,” Hernandez said. “People don’t pay attention to anything beyond whether their walls are painted or bathrooms work.”

► RELATED: HOW TO FIND OUT IF YOUR MARKET-RATE APARTMENT SHOULD BE RENT-STABILIZED

Hernandez, who neighbors now call “The Lawyer” because of the knapsack he uses to carry his legal documents, is still trying to collect the overpayment.

Officials with Tamrak Management Corp. said they should not have to pay it because they were unaware of the overlooked "clerical matter."

“It’s like he won the jackpot,” said David, a Tamrak representative who declined to give his last name. “It’s not fair to the landlord or the management company that didn’t know the rent was frozen over 20 years ago. He moved in 15 years after the rent was frozen for repairs.”

An employee at Nevei Bais Inc. declined to comment, claiming the company no longer owns the building, despite property records showing it does. David, from Tamrak Management, said Nevei Bais still owns the building.

Hernandez claims his landlord tried to pressure him into dropping the rent-overcharge issue by taking him to housing court. In 2013, he hurt his back while working construction and couldn’t pay his rent, he said.

His landlord tried to evict him for nonpayment. The suit was a bargaining chip that the landlords used to try to get him to drop the rent overcharge issue, Hernandez said.

They even offered him money to drop the investigation.

“One of the owners, right outside the courtroom in the hallway, offered me $50,000,” he said. “He asked me if I wanted it in cash or a check.”

The landlords tried to settle out of court, said David, who did not recall the exact amount of money offered.

During the eviction suit, the landlords repaired the problems that led to Brown's initial 1993 complaint. The current rent is $1,500 — $100 less than what Hernandez was being charged last year.

He said he isn’t fighting to restore the $233 monthly rent, but is pressing for the $112,000 refund the state determined he is owed.

A housing judge dismissed the eviction case based on the pending HCR investigation.

Because the landlord is appealing the state’s ruling, Hernandez hasn’t banked any the overpaid rent. Still, he said he's confident he will win the appeal and considers the money a savings account he can't yet access.

The money would go toward his retirement, and help pay for his daughter’s education, he added.

He said he pays the rent with disability checks and income from his wife and daughter's jobs.

“If I had the money," he said, "I would be able to live more at ease."