In the small town of Gräfenhainichen in East Germany, you can now dance on abandoned coal mines, with retired machines serving as the backdrop for occasional music festivals. These machines will never operate again, a casualty of Germany's effort to move away from coal and transition to a low-carbon economy.

Since the 1990s, successive German governments have set ambitious goals to go fossil fuel free. The country currently gets more than 26 percent of its electricity from renewable sources like wind, solar, biomass, and hydropower. By 2050, it aims to bump that ratio up to 80 percent. Making this task even more challenging, Germany wants to get there without relying on nuclear power. After the 2011 Fukushima disaster in Japan, the country reiterated its commitment to phasing out all its existing reactors.

German politicians speak enthusiastically about this ongoing green revolution, dubbed the Energiewende (or "energy transformation"), as a model for tackling climate change. The country is sometimes held up as a template for President Obama's own efforts to reduce coal-fired power and green the US electricity supply.

What gets less attention, however, is how frustrating and difficult Germany's energy turnaround has been in practice. The country offers a cautionary tale on why going green isn't always as smooth a ride as thought, and its Energiewende can offer some valuable lessons for the United States.

Germany has grand plans to phase out fossil fuels

Germany's efforts to wean itself off fossil fuels and shift toward cleaner forms of energy date back to the late 1990s, when the Green Party came into the government for the first time and worked with Social Democrats to introduce a series of taxes on oil and other forms of energy (though coal was notably exempted).

Over time, these policies expanded. When Angela Merkel, the country's former environment minister, became chancellor in 2005, she made climate change a signature issue. And in 2011, after the Fukushima reactor meltdown in Japan, the clean energy push gained renewed momentum. The government vowed to phase out the country's 17 existing nuclear reactors (which at the time provided nearly 23 percent of electricity) by 2022, all the while ramping up renewable electricity and cutting the country's greenhouse gas emissions.

This Energiewende includes a variety of policies, but at the center are generous subsidies for renewables — including a policy known as "feed-in tariffs." Anyone who installs solar panels or wind turbines is guaranteed a fixed, above-market price for each kilowatt-hour of electricity they feed into the grid. (That subsidy shrinks over time, to drive cost reductions in the industry.) What's more, by law, utilities must draw on renewable sources for electricity before resorting to coal, gas, or nuclear.

These policies had a massive effect on the wind and solar industry, with installations quadrupling since 2000, when the feed-in tariffs began:

At this point there are 25,800 wind turbines in Germany, with an additional 1,000 being installed each year. The country is currently planning 1,800 miles of additional power lines to accommodate all this renewable growth. The government has also poured billions into R&D for modern energy technologies, as well as financial support for things like electric cars or home retrofits.

As renewables have matured, the German government has made plans to shut down its fossil fuel and nuclear plants. By 2019, the last state-subsidized hard coal plant is supposed to close (lignite coal plants will persist for longer). By 2022, the last German nuclear plant is supposed to shut down.

These clean energy policies haven't come cheaply. The subsidies for renewables are paid for by a surcharge on German electricity bills, which currently come to around $240 per household per year, according to a report by the German Association of Energy and Water Resources. German electricity rates are still among the highest in Europe, although efficiency programs have kept overall household bills roughly flat as a share of household income.

Still, the cost of green energy isn't the biggest hurdle in Germany's transition — wind and solar remain quite popular nationwide. The bigger challenge is getting rid of coal.

Germany's coal industry has refused to disappear without a fight.

The crucial part of Germany's energy transition was supposed to be phasing out coal, a major contributor to climate change. But that turned out to be much harder than anyone thought.

Coal still provides 43 percent of Germany's electricity, with 25 percent coming from lignite (known as "brown coal") and 18 percent from hard coal. Lignite is dirtier from a climate change perspective, producing about one-third more carbon dioxide than hard coal, but Germany has ample domestic lignite reserves and can mine it cheaply. The hard coal mostly gets imported from abroad, from Russia, Colombia, and the United States.

Both types of coal have proven difficult for Germany to give up. In 2013, Germany was burning more lignite than at any point since 1991. Those numbers have since gone down slightly in subsequent years, but phasing out coal has been stubbornly slow:

There are a couple of reasons for that. Hard coal is still cheaper than most alternatives, and unlike solar or wind can provide a reliable source of electricity for Germany's factories and heavy industry. Christian Schwägerl, an energy analyst in Berlin, has argued that Germany's industrial sector is particularly reluctant to give up its reliance on coal: "Germany is Europe's largest economy, and its wealth depends heavily on exporting industrial goods made with cheap electricity," he writes.

Meanwhile, many Germans are opposed to abandoning lignite, or brown coal, any time soon. The country is the world's largest lignite producer, and the prospect of job losses in mining regions is a looming concern.

"Many companies here, and people whose jobs depend on the industry, want to keep the coal," says Ottmar Edenhofer, who directs the German Mercator Research Institute on Global Commons and Climate Change. His institute is based near the Lausitz region, which is highly dependent on lignite mining.

These fears aren't unfounded — all people have to do is look at what happened to coal regions that declined sharply in the 1990s. After the fall of the Berlin Wall and the collapse of industry in East Germany, a number of mines had to close. The number of people employed by the mining industry fell from roughly 300,000 in 1990 to around 40,000 today.

Driving around former mining regions in Germany today can be a depressing experience. Some industrial cities have never recovered. "Of course we notice the effects in retail business, gastronomy, and service. People just have less money," says Karl-Friedrich Schulte-Uebbing, director of the local chamber of commerce in the town of Marl, which has seen major mining-related job losses.

Meanwhile, there's another much-debated factor behind coal's stubborn persistence. Many analysts have argued that it's impossible for Germany to phase out nuclear power and reduce its reliance on coal at the same time. If you shut down reactors, as Germany has been doing, coal will just fill in the gap. Edenhofer, for his part, doesn't buy this explanation. He argues that the reduction in nuclear power has largely been supplanted by faster-than-expected renewable growth.

Instead, he points to problems with Europe's emission trading system, or ETS. This program sets an overall cap on the continent's greenhouse gas emissions and allows companies to buy and sell pollution credits. This is effectively a price on polluting carbon dioxide.

The problem is that permit prices under this system have fallen to ridiculously low levels in recent years. In 2008, it cost $50 to emit one ton of carbon dioxide. After the financial crisis, that plummeted to $7 per ton. That gave a boost to Germany's coal plants, which were no longer at quite as much of a disadvantage compared with cleaner natural gas plants. "The decline of CO2 prices in Europe has meant that modern gas power stations are now unprofitable, and old coal power plants are now profitable," Edenhofer explains.

Indeed, those low permit prices have also raised demand in other countries for German coal-fired electricity. As the think tank Agora Energiewende explains, German electricity exports have been surging in recent years, much of it coal-fired.

While EU officials have suggested modifying the cap-and-trade system to make it stricter, reforms aren't likely to come about until 2018 at the earliest. And in the meantime, coal is hanging on in Germany. "We're experiencing a renaissance of coal power," says Edenhofer.

Germany is now in danger of missing its climate targets

The recent coal boom has put Germany's plans to tackle global warming in danger. The country is currently aiming for a 40 percent reduction in greenhouse gas emissions below 1990 levels by 2020. But Germany may not hit that target, according to a McKinsey study and several other analyses.

Since 1990, Germany has only seen a few periods when emissions dropped drastically. The first came after the fall of the Berlin Wall, in part because of the collapse of East German heavy industry. The second came in 2009, after the global financial crisis.

But in 2012 and 2013, overall emissions rose again — despite the push for green energy. And although there was another drop in emissions in 2014, even Germany's environment minister, Barbara Hendricks, conceded that this was mainly due to unusually warm weather that reduced the need for heating. So emissions have been bouncing about, rather than exhibiting a clear and sustained downward trend.

"I am very skeptical that we are currently experiencing a clear downward trend for carbon emissions," says Edenhofer. He says the 2020 climate target "is still feasible, but it's a daunting task. It will only happen with fundamental changes."

And right now, it's not clear that those fundamental changes are imminent. If anything, the government seems to be softening its stance on coal. The elections of 2013 saw a new coalition government formed with support from mining regions. Its platform argues that lignite will be "indispensable for the foreseeable future."

Then, over the summer, the government gave the coal industry another reprieve. Back in 2014, the economic ministry had proposed a levy on the oldest and dirtiest coal plants that would spur operators to cut 22 million tons of carbon dioxide. But that proposal sparked widespread protests. Unions cited concerns about job losses. Manufacturers worried about the loss of cheap electricity.

Faced with such opposition, Merkel's government backpedaled slightly. In July 2015, it unveiled a new proposal to save just 12.5 million tons of carbon dioxide by closing five old coal-fired plants by 2020 — and compensate affected companies to the tune of $260 million annually. "The decision means the coal industry lives on," commented Nick Butler in the Financial Times. "Coal will remain a major, and probably the largest, fuel source for power generation for another decade and perhaps longer."

What the US can learn from Germany's war on coal

The United States and Germany are in different situations, energy-wise. For one, the United States has had a relatively easier time phasing out coal in recent years due to the availability of a bridge fuel — cheap natural gas.

From a carbon dioxide perspective, natural gas is only about half as dirty as coal (though still dirtier than renewables or nuclear; plus there are concerns about methane leaks). And natural gas plants don't suffer from the intermittency problems that wind and solar farms do. So, in theory, gas should be a good candidate to reduce emissions and aid the transition to a carbon-free system.

Since the mid-2000s, the United States has developed ample domestic supplies of cheap natural gas thanks to improvements in fracking and horizontal drilling techniques. Today, gas supplies about 33 percent of the country's electricity, and it's a major reason for the decline in coal-fired power. Germany, by contrast, doesn't have large domestic supplies. It has to get much of its natural gas from Russia, an unreliable source. As a result, the country gets just 9.5 percent of its electricity from gas. That's made the transition much, much harder.

Yet despite the differences, there are at least two big lessons the United States can take from Germany's experience as it, too, tries to shift to cleaner energy.

The first is to be careful about optimistic cost projections. Back in the early 2000s, one Green Party politician promised that Germany's energy turnaround wouldn't cost households more than "a scoop of ice cream." That has turned out to be wrong, which in turn has fostered a degree of skepticism about the Energiewende. A few years ago, 56 percent of Germany's consumers said they were willing to take higher electricity costs for the support of renewables, according to a survey. That's since dropped to 46 percent.

The other lesson is not to underestimate the resistance from fossil fuel incumbents. Most environmentalists are already aware of this. Coal may be dying in the United States, but coal state lawmakers have been disproportionately influential in energy policy, lobbying hard against President Obama's plans to reduce power plant emissions. If Germany is any guide, this opposition is only likely to get more fierce — not less — as clean energy advances, and fossil fuels can sometimes end up making a surprising comeback along the way.