Help on template sensors and unavailable after restart

Hi, need a little help on templates.

I have a template I only update daily, at midnight. I then use this number in other calculations. It works as expected, however I have the problem that after a restart the sensor is shown as “unavailable” until next midnight.

Here is the template sensor

- trigger:  ## Daily at midnight
  - platform: time
      - "00:00:01"
  - name: "Utility El usage Day increasingtotal temp-number"
    state: >
      {{ states('sensor.develco_zhemi101_f21a021b_smartenergy_metering_summation_delivered') }}

I have tried to find a way to update a helper from the sensor, as this will keep the state after a reboot, however can not figure out how

I have tried with a template that also update at restart. It works, however the number will be wrong, as it is not from midnight (will show the number from restart time)

I have tried using a utility sensor, and have the number comming form “laststate”. This works, however takes up a lot of space in the DB, for only this one small number (utility sensor will update every time the original entity updates, which is a lot)

Ideas? I can not figure out how to do this in a simple way

Easiest solution would be a automation updating a “helper”. However I can not figure out how.

Solved: The solution is like this. With great instiration from this discussion. Not sure why I did not finde that right away.

so the solution looks like this,

alias: AA Test float
description: ''
  - platform: time_pattern
    minutes: /1
condition: []
  - service: input_number.set_value
      entity_id: input_number.aa_test_float
      value: >
mode: single

Your proposed solution doesn’t work the same way as your original Trigger-based Template Sensor.

  • The Template Sensor updates once a day (at one minute past midnight).
  • The automation uses a Time Pattern Trigger that updates every minute (1440 times a day).

If you want it to work the same way, replace the Time Pattern Trigger with a Time Trigger identical to the one you used in the Trigger-based Template Sensor.

Hi Taras,

Im aware, it was just my test automation, set for 1 minute to see the effect.

I should have mentioned to ensure others would not use time on making a reply. I will remenber next time.

Thanks for your input, and all the other input from you. It was your reply in the other thread that gave me the insight to solve this one.