Gary Walker, of Commonside, Hanging Heaton, was seen in the doorway of his home by the passer-by on June 18 last year.
The 41-year-old, who was under a sexual offences prevention order at the time for a previous offence, was standing in the doorway wearing only a T-shirt.
Prosecuting, Duncan Ritchie said: “A group of children aged five or six were playing on a grassed area. A group of girls were also leaving a nearby mosque.”
Mr Ritchie told Leeds Crown Court that Walker had his T-shirt tucked under his chin and was smacking his stomach with his hand.
He said it was believed Walker was slapping himself to attract the attention of the children, but they did not appear to notice.
The dog walker called the police and Walker was arrested later that day, but denied he had exposed himself.
The court heard Walker was given probation for exposing himself on two consecutive days in 1998 and in 2012 was made the subject of a sexual offences prevention order for an offence in front of a six-year-old girl.
Mitigating, Brendan O’Leary said although Walker had no explanation to why he exposed himself, he was making genuine progress while working with a mental health team.
Mr O’Leary said: “He is meeting with a volunteer two days a week to discuss his issues.
“The probation service feel he is someone who they can work with and make progress with.”
Walker admitted indecent exposure and was given a 10 weeks’ prison sentence suspended for two years with supervision and a high level activity requirement.
He was ordered to register as a sex offender for seven years and ordered to pay a victim surcharge of £80.
Walker was also made the subject of a new sexual offences prevention order.
Judge Christopher Batty told Walker sending him to prison would undermine the progress the mental health team had made.
He said: “The problem is you serve half of it and come out. Then the work done so far is finished. There would be little or no protection for children and the future motivation would not be addressed.
“The work will continue but also it will be made to see if there are other ways that are more beneficial to you and the public. If you do anything like this in next two years then you will come back to see me.”