It’s a “dam” good plan to keep New York waterways clean. In an unprecedented move, the city has set up two inflatable rubber dams within two of Brooklyn’s largest sewer lines, the Post has learned. The goal: easing the longtime stinky problem of sewage and storm water overflowing into the East River during heavy rain. The $15.7 million project in Williamsburg and Red Hook is the city’s first attempt at using the synthetic-rubber systems, which have been big hits overseas and other parts of the country. The underground dams include controlled mechanisms and automated sensors that cause the dams to inflate when it rains, keeping storm water within sewer lines so it could later be pumped to nearby wastewater treatment plants. Vincent Sapienza, deputy commissioner for the Department of Environmental Protection, said both dams have been big successes since recently getting installed and that they’re expected to prevent four million gallons of sewage from reaching the East River per rainstorm – or 100 million gallons a year. “This is really the next generation of our wastewater treatment program,” said Sapienza, adding the city is considering installing the dams in sewer lines by other polluted waterways like Brooklyn’s Gowanus Canal and Queens’ Flushing Bay. He also said the dams are far cheaper options for limiting wastewater flow to waterways than building massive retention plants like a $404 million facility that opened last year at Paerdegat Basin in Canarsie. Evan Thies, a Williamsburg/Greenpoint activist, called the inflatable dams “an encouraging step” but said the city “is still far” from delivering on commitments made during the area’s 2005 rezoning “to spend vastly more for infrastructure, including sewer improvements.” “We’ve added tens of thousands of new residents since then, and our infrastructure needs have gone from critical to crisis,” he said. The dams cover sewer lines that extend about 8 to 10 feet wide. They include “fail switches” to prevent sewage from backing up to street level. The dams are part of the NYC Green Infrastructure Plan, which calls for investing $2.4 billion over the next 20 years to help reduce combined sewer overflows.