Template sensor with last good value stored in attribute

Hi,

Try looking at a guide I wrote subsequently. It uses a slightly updated version of this template which can also subtract sensor changes: