How to calculate yearly energy costs with changing tariffs?

You could get the desired information from the statistics table in the recorder database with an sql-sensor.