That can be the state template for a template sensor which you can set from the UI, under Helpers.
states(entity_id) returns the state of the entity, which is always a string. You need to turn that into a number before doing maths with it, which is what the |float does. The (0) in the float call is the default value, returned if the state cannot be converted to a number (if it’s unknown, for example).
Well another simple math question that I can’t find out…
I want to have a sensor that shows me the power usage of my hown every day.
I believe I need the Energy Import from my P1 meter (sensor.stroommeter_totaal_verbruik) minus the Energy Export from my P1 meter (sensor.stroommeter_totaal_teruglevering).
Using the Utility Meter (Utility Meter - Home Assistant) I can reset that amount every 24h and with that information I can create a graph that shows me the usage every day.