Invalid config for [sensor]: required key not provided @ data['platform']. Got None when creating a sensor

Hello all. I’ve searched around for a solution for my problem, but so far I don’t understand what exactly the issue is.

I use the utility integration to get daily power consumption data from the peak and off-peak power consumption data that I retrieve through the DSMR integration. Now I want to add those two values together in a sensor (at least, from what I read that’s the place to do it) so I know the total consumption.

So in my configuration.yaml file I’ve included a sensor.yaml file:

sensor: !include sensor.yaml

And then in sensor.yaml I’ve added the sensor config:

template:
  - sensor:
    - name: "Elektra dagelijks totaal"
      unit_of_measurement: "kWh"
      state: "{{ ((states('sensor.elektra_dagelijks_dal') | float | round(2)) + (states('sensor.elektra_dagelijks_normaal') | float | round(2))) }}"

When I validate the code with the template function in developer tools I get the correct output:

template:
  - sensor:
    - name: "Elektra dagelijks totaal"
      unit_of_measurement: "kWh"
      state: "3.14"

But when I try to validate the config I get this error:
Invalid config for [sensor]: required key not provided @ data[‘platform’]. Got None.

And don’t understand the platform message. What does it want me to add and where should I add it?

Thanks in advance!

That does not go in sensor.yaml.

Put it in configuration.yaml

Because template is an integration of it’s own, just like you can’t stick switches in with lights.

template: !include template.yaml

template.yaml:

  - sensor:
      - name: "Elektra dagelijks totaal"
        unit_of_measurement: "kWh"
        state: "{{ ((states('sensor.elektra_dagelijks_dal') | float | round(2)) + (states('sensor.elektra_dagelijks_normaal') | float | round(2))) }}"

Should do it.

Thanks all for the swift replies and the elaboration, makes sense on the integration bit! It’s working now :slight_smile: