Value_template sensor for energy dashboard

Hi

I am trying to get a value_template sensor into the energy dashboard.
But it is not showing in the dropdown?

Does anyone have an idea of what I am doing wrong ?

- platform: template
  sensors:
    battery_charged:
      friendly_name: "Battery charged"
      unit_of_measurement: 'kWh'
      value_template: >-
        {% set charged = states('sensor.victron_battery_charged') %}
        {{ charged| multiply(0.01) | round(2) }}

The sensor is working perfect in lovelace.

Martin

Try setting device_class: energy

Still nothing :frowning:

- platform: template
  sensors:
    battery_charged:
      friendly_name: "Battery charged"
      unit_of_measurement: 'kWh'
      value_template: >-
        {% set charged = states('sensor.victron_battery_charged') %}
        {{ charged| multiply(0.01) | round(2) }}
      device_class: energy

Found a solution :slight_smile:

Add the following to configuration.yaml

homeassistant:
  customize:
    sensor.battery_charged:
      device_class: energy
      state_class: total_increasing

Use new template style

template:
  - sensor:
    - name: "EB3 Import"
      state: >-
        {% if states('sensor.eb3_0x0016') is defined %}
          {% set x = states('sensor.eb3_0x0016').split(',')[0] | float %}
          {{ (x / 1000) | round(1) }}
        {% else %}
          {{ states('sensor.eb3_import') }}
        {% endif %}
      unit_of_measurement: "kWh"
      device_class: energy
      state_class: total_increasing

That is even better :slight_smile:

Tanks a lot!

hi i am having same issue

here is my sensor i cannot get this into the engery dashboard ,if i add state_class:total_increasing it will work unti HA refreshes then it removes state_class and the dashboard errors ,please help me make this into a new template sensor ,thank you


    electricity_usage_total:

      friendly_name: 'Total Electricity Used'

      value_template: "{{ state_attr('sensor.geo_energy_usage_total','totalConsumptionList') | selectattr('commodityType', 'equalto', 'ELECTRICITY') | map(attribute='totalConsumption') | first }}"

      device_class: energy

      unit_of_measurement: "kWh"  ```

No matter what I try, I cannot get this template sensor to load. Any suggestions? Also, what file do I put this in other than customize.yaml? template.yaml or sensor.yaml?

Note that my template statement evaluates perfectly in Dev tools.

template:
  - sensor:
    - name: "Sum of all Battery Current draw"
      value_template: >-
         {{ states('sensor.battery_current') | float + states('sensor.inverter_2_battery_current') | float + states('sensor.inverter_3_battery_current') | float }}
      unit_of_measurement: "A"
      device_class: energy
```

This is my sensor working OK:

    -  platform: template
       sensors:
       
         consumo_coche_coste_horario:
           friendly_name: "Coste horario coche"
           unit_of_measurement: '€'
           unique_id: "coste_horario_coche_kwh"
           value_template: "
           {%set termino_cons = (states('sensor.blitzwolf_1_hourly_energy') | float) * (states('sensor.mqtt_sensor_test') | float)  %}
           {%set total = termino_cons / 10 %}
           {{ total | round(1) }}"