Is there a way to automatically turn off wifi? I have an LG P990, and I recently upgraded it to ICS. Since that, the charging is much slower and energy consumption is much faster. I could live with it, I charged it at work and at home too.

Yesterday however it went from 85% to empty in one night. 49% of the energy consumption is Wifi according to Battery usage.

I want to know how to periodically turns WiFi on, and after a few minutes off. Every program I was able to find did the first part, but when it found a known network, left it on indefinitely. 

In the settings I have "Keep wifi on during sleep" set on "Never", but it does not help.
Before doing so, I'd consider two more things:
Finding the real cause
High WiFi usage is not caused by WiFi itself (standby), but most likely by another app constantly requesting it to &quot;stay awake&quot;. So first check How to deal with (orphaned) WakeLocks? -- which also deals with this.
Checking your WiFi standby policy
In Settings→Wireless &amp; Networks→WiFi, when pressing the menu button, an item named &quot;Advanced&quot; appears. Tap that to go into the advanced settings and check the Wifi Standby Policy. There are 3 options available:

Always: WiFi stays awake even when the display is turned off. Useful if you're streaming music.
Only when connected: Only when a power source is connected (i.e. the device is charging) -- as in that case the &quot;battery consumption&quot; usually is not an issue.
Never: WiFi goes to standby as soon as the display is turned off.

WiFi managing tools
If this requirement still is present after thoroughly checking above two points, there are multiple options available in this section -- enough to fill at least a small book. First, there are tools like e.g. JuiceDefender or GreenPower, dealing not only with WiFi and mobile networks, but covering a lot more energy saving stuff. Other interesting tools might include WifiBatt and many others -- just check the related apps on their playstore pages, or use Mapsaurus to find similar apps.