Old vs new sensor template

Hey. Some time a go the way we code the sensors has changed. I’m trying to implement the new method but I have some problems:( I can’t fing the clear and full explanation how to…
So previously I had:

sensor:
platform: template
sensors:
fronius_house_load_pos:
value_template: “{{ (states(‘sensor.fronius_house_load’) | float) | abs | round(2) }}”
unit_of_measurement: ‘kW’

After second ‘sensors’ in this example, I could put more of them…
Then I had this:

platform: integration
source: sensor.fronius_house_load_positive
name: house_energy_used_hour
unit_time: h
unit: kWh
round: 2
method: left

And this way I had energy consumption in kWh (for this example)using two platforms (template and integration/Reinman sum)… All clear…

But now, the new method is advised:

template:

sensor:
    name: fronius_house_load_positive
    state: >
    {{ (states(‘sensor.solarnet_power_load’) | float) | abs | round(2) }}
    unit_of_measurement: ‘kW’
    friendly_name: ‘Zużycie bieżące’

This works fine, but using this method, the second part of code above is not working (the one using platform:integration)… So how to make it working again ? I know the Reinman sum / utility meter, can be done from GUI but this is just an example to show what this is about… Can anyone help?

Please, format your code consistently. Making sense of what you posted is hard because you’ve skipped the formatting for some, formatted some that you’ve stripped all the indenting out of, and then marked up the second half of the final one.

Or, if the integration one is indented as you wrote it then that’s your problem.

1 Like

OK so I’m not total idiot :slight_smile: At least I hope. It looks like this and it was working fine before I started to change the ‘template’ part :frowning:
Sorry for that - formatting was lost during posting on the forum

sensor:
  - platform: integration
    source: sensor.fronius_house_load_positive
    name: house_energy_used_hour
    unit_time: h
    unit: kWh
    round: 2
    method: left

That’s the “modern” configuration format for Template Sensors.

You can’t put the configuration of an Integration Sensor into the same place as the modern configuration of a Template Sensor.

Keep them separate.

sensor:
  - platform: integration
    source: sensor.fronius_house_load_positive
    name: house_energy_used_hour
    unit_time: h
    unit: kWh
    round: 2
    method: left

template:
  - sensor:
      - name: fronius_house_load_positive
        state: >
          {{ (states('sensor.solarnet_power_load') | float) | abs | round(2) }}
        unit_of_measurement: kW

Be advised that the modern format of Template Sensor configuration does not support the legacy format’s friendly_name option.