Your one unsuccessful experience doesn’t invalidate the entire approach which has been used successfully in numerous examples throughout the forum.
Here’s a functional example I provided over 2 years ago and it’s nearly identical to what Didgeridrew proposed.
Here’s an example specifically meant for storing/deleting values via actions.
Here’s another one that keeps track of the last 5 songs that were played.
All these examples rely on a Trigger-based Template Sensor’s support for triggers that can initiate actions to modify its value(s). Not, like CoPilot suggested, via an automation.
Regarding Didgeridrew’s example, its behavior is entirely dependent on the behavior of the two sensor
entities it’s monitoring.
sensor.homewizard_accu_1_laadpercentage
sensor.homewizard_accu_2_laadpercentage
How often do their values change, are they normally numeric, have they recently reported non-numeric values and what were they? (none
, unavailable
, unknown
, something else?)