Help on templates: sensors do not appear

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

Look in the logs, and you’ll probably find a message that icon_template isn’t valid for modern format. It’s icon: Template - Home Assistant

In addition, you should provide defaults to float like this: |float(0).

One more thing: mdi:lightning-bolt.

Reload Template Entities under Developer Tools / YAML.

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 }}

It was the icon…, but I did not get any warning on the logs until I completely rebooted the machine (desperate move)

modified the icon, the float and the availability, I haven’t found in the documentation the behavour if any of them is unavailable.

ty all.

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!

1 Like