How to define an external entity for varying energy prices

Hi,

I need an entity for the varying price of my used energy. The tariff is about to change 2 times in the near future and I want to have a “by code” or “by automation” definition for that, where I can set up the date for the change as well as the new price after that date.

This entity must end up in HAs long term statistics and so in my influx db. Having grafana I want to be able to have a separate series for the price per kWh to correctly calculate energy cost and savings from solar panels.

Any ideas how to archieve that? Code examples would be nice, as I am still learning HA.

Thx.