Need help to divide a value in a sensor

Hi,

I’m new with homeassistant (i used jeedom).
I read a lot, but i’m still lost with entities, template, sensor… After reading pages and pages, I still don’t understand the difference between all that kind of things.

Now, I have a mysensors device, whcich give me energy information.
What I want to to is configure the energy dashboard. I need an energy sensor, and can chose it, but it’s not the right Unit. The value must be divided by 1000 to obtain Wh

I have create a sensors.yaml file (which I include in configuration.yaml.)

I put this inside sensors.yaml, but I still can’t use it in energy dashboard :

What am I doing wrong ?


# Example configuration entry
sensor:
  platform : template
  sensors :
  - name : Conso Totale Perso
    device_class: energy
    state_class: total_increasing
    unit_of_measurement: 'Wh'
    value_template: "{{states('sensor.energie_active_soutiree')|float / 1000}}"

Thank you.

Should not have spaces before the colons. If it’s in sensors.yaml, you don’t need the first line.

If you’re not comfortable with YAML, you can create this sensor in the UI, under Helpers.

Ok, I managed to do it with helpers. Thank you very much. But It would be great if I could understand the sensors.yaml structure.

It’s still very confusing to migrate from jeedom to Home assistant.

Start here:

You were trying to set up a legacy format (old) template sensor. It would still be valid, but modern format is recommended.

Modern format, as per the doc, is under the template: header, not under sensor:. You can put the code directly in configuration.yaml or you can reference another file with:

template: !include templates.yaml

If you do that, your templates.yaml file will start with (for example):

- sensor:
    - name: my sensor

You don’t need the template: header because it’s already in the line above.

Because you defined the Template Sensor using what is known as legacy format which doesn’t support the inclusion of the state_class attribute in its configuration.

May I ask why you didn’t choose to configure the Template Sensor using the first format that is described in the documentation? The legacy format you used is buried near the very end of the documentation.