Make template sensor non volatile

UK energy calculation question:

I have a template sensor defined in templates.yaml that increments a standing charge over 24 hours.

- sensor:
  - name: "Electricity Standing Charge TP"
    unit_of_measurement: "kWh"
    device_class: energy
    state_class: total_increasing
    state: >-
      {{ (((now().timestamp() / 3600)-462595) | int) / 1000 }}
    attributes:         
      last_reset: '1970-01-01T00:00:00+00:00'

Is there a way to make Electricity Standing Charge TP non volatile?

This gets reset each time HA is restarted.

It should no t reset. It should be recalculated. Try removing the attribute, it is not required and may be messing things up.

Or if that does not work, make it a triggered template sensor. Triggered template sensors are restored (rather than recalculated) on restarting HA. e.g.

template:
  - trigger:
      - platform: time_pattern
        minutes: "/1"
        seconds: 0
    sensor:
      - name: "Electricity Standing Charge TP"
        unit_of_measurement: "kWh"
        device_class: energy
        state_class: total_increasing
        state: >
          {{ (((now().timestamp() / 3600)-462595) | int) / 1000 }}