classic question. I’ve read several topics. Most of them related to new old template formating. Most YT tutorials are in legacy as well. Its a mess. When you don’t know the syntaxis believe me this dual set of answers and tutorials are a nightmare.
My case, should everything be in new:
configuration.yaml
contains:
template: !include template.yaml
and
template.yaml
contains:
- sensor:
- name: Suma Energia a la Xarxa
device_class: energy
state_class: total_increasing
icon_template: mdi:LightningBolt
unit_of_measurement: 'kWh'
state: "{{ states('sensor.r_energy_returned') |float + states('sensor.s_energy_returned') |float + states('sensor.t_energy_returned') |float }}"
0 succes on getting the sensor appear in the list in developers tools.
afaik should be sensor.suma_energia_a_la_xarxa
I can make it work with the legacy format…
if, instead, include is:
sensor: !include sensors.yaml
sensors.yaml
- platform: template
sensors:
- 3em_sum_energy_to_grid:
friendly_name: Suma Energia a la Xarxa
icon_template: mdi:LightningBolt
unit_of_measurement: 'kWh'
value_template: "{{ states('sensor.r_energy_returned') |float + states('sensor.s_energy_returned') |float + states('sensor.t_energy_returned') |float }}"
Also I still don’t know which reboot is required to reload the settings: fast one, home assistant or system
Also, as this is an energy sensor you need all the source sensors to be available or the glitches will badly affect your statistics. For this you use an availability template.
availability: >
{{ states('sensor.r_energy_returned') |is_number and
states('sensor.s_energy_returned') |is_number and
states('sensor.t_energy_returned') |is_number }}
If you use it in the energy dashboard and you did not have an availability template it would behave like this:
Total → 0 → Total ( due to all your source sensors being momentarily unavailable and the float 0 defaults): adds the entire total to the energy dashboard. Not good.
Total → some lower total → Total (due to one source sensor being momentarily unavailable and the float default of 0): adds the missing sensor value to the energy dashboard. Also not good.
With an availability template in either of those scenarios:
Total → unavailable → Total: energy dashboard continues to count as if nothing happened. Yay!