Police made the discovery when they searched Jamie Gill’s home in Guiseley after finding £19,000 worth of the drug at the property.
Leeds Crown Court heard officers went to the house on Hallam Street on July 31 last year during an investigation into other matters.
Paul Nicholson, prosecuting, said police found just under two kilograms of skunk cannabis hidden in three plastic bags in a bedroom.
A small amount of the Class A drug MDMA was also found in his jacket pocket.
The prosecutor said the officer suspected there may be a cellar in the property.
They moved aside a washing basket and a clothes horse in the kitchen and found a trap door leading to a cellar..
It contained a cannabis farm which had been insulated to prevent noise and heat being detected.
A bag containing £1,000 was also found in the house.
Six plants were growing and the electricity supply had been bypassed.
Gill, 27, was arrested and initially claimed he had been growing the cannabis for his own use.
He pleaded guilty to producing cannabis, possession of cannabis with intent to supply and possession of MDMA.
Probation officer Malcolm Brown told the court that Gill had been “more realistic” about his offending when interviewed.
Mr Brown said Gill had admitted growing the cannabis to pay off a £2,500 debt he owed to someone after crashing a car.
The court heard Gill had a number of personal problems at the time of the offence.
He now has a job and a good relationship with his four-year-old son.
Gill’s employer provided a reference to the court describing the offending as out of character.
Gill was given an 18-month prison sentence, suspended for two years, and ordered to do 130 hours unpaid work.
Recorder Paul Greaney, QC, said: “You are being given a chance today. I hope it is a chance that you will take.”