Calculate difference with a previous value, from statistics?

Would it be possible to calculate the difference between the value an entity has today with the value it had yesterday? This data is available, since its statistics-enabled template-sensor, but I just don’t know how to access the data using a template.

For one who wants to know, I’m setting this entity to the heating-meter (in GJ), daily, using AppDaemon. Of course I could calculate the difference in AppDaemon, but I’d rather keep that interface simple and do any further manipulations in HA.

No one?
I’ve tried this in AppDaemon but I’ve not been able to figure that out either, because the entity just disappears after reboot.