Error with almost empty sensor file

Hello,

I’m trying to set up these sensors and I discover the new template syntax. So I write my older sensors wit the new syntax, only to get this error while validating the yaml:

Invalid config for [sensor]: required key not provided @ data['platform']. Got None. (See /config/configuration.yaml, line 9).

My configuration.yml includes the sensors.yml file. Following the documentation here I don’t see that the platform keyword is needed anymore in the new format, except for a few use cases. The sensors I copy don’t include this key either, so are a lot of references on the web.

So I’m confused. What is the error exactly ? I tried with an empty sensors.yml file, and validation is OK. I tried with a minimal file with the following content, which looks legit to me, and validation fails. Any help would be greatly appreciated! Thanks!

### Templates
template:
  - sensor:

    - name: lixee_zlinky_tic_metering_hc
      unit_of_measurement: "Wh"
      device_class: energy
      state_class: total_increasing
      state: unavailable

the template section does not go in sensors.yaml. It goes in configuration.yaml

Thanks for the hint. By copying the content in configuration.yaml, it’s working (or at least, it’s validating).

But then there’s something I don’t understand.

So it looks like the issue is coming from mixed configuration version. Before, the configuration was

...
sensor: !include sensors.yaml
...

From what I understand here, the template keyword is not under sensor. But we put sensors in it. And there’s still a sensor keyword, but where we can’t put templates inside.

The splitting configuration documentation is still talking about the sensor: !include sensors.yaml part.

So, should I define a template.yaml file with template: !include template.yaml ? But then, what is the difference between sensors that go under sensor, and sensors that go under template? Besides my templates, the sensor.yaml file is empty. Is it obsolete, but still documented since both old configuration and new configuration are managed by HA?

Thanks!

This is a reference for using an external file for your sensor integration.
The sensor integration is not the same as the template integration. The example you provided is for the template integration, so it cannot be under the sensor integration.

You can have something like this in your configuration,yaml, but hen you have to manually create a templates.yaml file and then have your code there:

template: !include templates.yaml

And then your templates.yaml will look like this:

  - sensor:

    - name: lixee_zlinky_tic_metering_hc
      unit_of_measurement: "Wh"
      device_class: energy
      state_class: total_increasing
      state: unavailable

Thanks for the confirmation. It’s still not really clear to me, the documentation is not helping much without examples.
But I get it: previously template sensors were part of sensors. Now template sensors are not part of sensors anymore, but part of template…

Thanks for the help, after a few issues, all is working fine now :slight_smile:

1 Like