That’s not possible with template sensors.
Template sensors require entity_id’s to listen to. If you use dynamic entity_ids, the system doesn’t know when to create a ‘listener’, so you end up with no listeners.
You’ll always need to manually add an item to the template sensor.
But you could add sensor.time to the template sensor and it will update once a minute.
That would look like this:
sensor:
- platform: date_time
display_options:
- 'time'
- platform: template
sensors:
total_daily_energy:
friendly_name: Total Daily Energy
entity_id: sensor.time
value_template: >
{% set ns = namespace(states=[]) %}
{% for s in states.sensor %}
{% if s.object_id.startswith('daily_') and s.object_id.endswith('_energy') %}
{% set ns.states = ns.states + [ s.state | float ] %}
{% endif %}
{% endfor %}
{{ ns.states | sum }}