Rather than using the new Energy dashboard, I would like to display today’s cost (as presented in the energy-sources-table card) in a separate lovelace view. I have tried to setup a new template sensor based on the autogenerated “sensor._cost” but w/o success.
It was my noobie solution to the problem that the _cost state goes to zero upon every restart of HA, so in order to track today’s cost I tried to accumulate sensor values over today. Great if I could access this value directly by _cost[ NOW ] - _cost[period start time] or similar. Is that possible?
Hi, I use this to get all sources consumption price (snippet taken from Dev tools):
{% set ns = namespace(states=[]) %}
{% for s in states.sensor %}{% if s.object_id.endswith('_cost') %}
{% set ns.states = ns.states + [ s.state | float(default=0) ] %}
{% endif %}
{% endfor %}
{{ ns.states | sum | round(2,default=0)}}
It works OK as template sensor but does not persist HA reboots
Tried to add state_class: total_increasing to all _cost sensors but last_reset indicates last restart time/date and result is of course ZERO
Is there a way to make a sensor which value will survive reboots?
Best, JR