Sensor: !include sensor.yaml? issue

I’m tryin to make a sensor.yaml file,but when I try to use sensor: !include sensor.yaml I get an error duplicate.

I then saw I have a sensor: in the configuration.yaml that has a few other sensors in it.

Am I going to have to move the sensors under the sensor: to the sensors.yaml file before I will be able to use the sensor: !include sensor.yaml?

For example,the sensor: has this under it…
sensor:

  • platform: systemmonitor

    resources:

    • type: disk_use_percent

      arg: /home

    • type: memory_free

  • platform: time_date

    display_options:

    - "time"
    
    - "date"
    
    - "date_time"
    
    - "date_time_utc"
    
    - "date_time_iso"
    
    - "time_date"
    
    - "time_utc"
    
    - "beat"

Yes. Either have every sensor in the configuration.yaml or every sensor in you sensor.yaml. No ‘something here and something there and something everywhere’
This is a tidy smart home software! :wink:

And please use proper code tags to show us your code next time image

I think I have them everywhere.
I name the sensor, so first line would be sensor system:

I am not at my system, but I think it is like that.

Let me say in other words…

If you’re thinking about using a dedicated sensors.yaml you probably have not a nested folder structure with different sensor_thing_x.yaml for different integrations or something.

So you probably have your sensors in config without the ‘sensor:’ more than once and some accidentally all over the place which is - in my opinion - not the greatest idea.

As a suggestion, my config contains

sensor: !include_dir_merge_list sensors

I then have a directory called sensors and in there individual YAML files e.g.

sensors/season.yaml

Which contans

- platform: season
  type: astronomical

To answer your actual question, this is one of the benefits of YAML - grouping things under logical headers. Once you’ve specifed

cars:
  German:
    BMW
    VW
  French:
    Renault

Your program will know that VW is a German Car. The same thing happens in HA

sensor:
  this will be considered a sensor:
      - some attribute
  this is also a sensor:
      - an attribute
  yet another sensor:

Anything that appears under sensor: whether it’s like the example above or !include(d) will be considered a sensor.

You can do use an integrations multiple times. by using labels, for example


sensor garden: !include sensors_garden.yaml

From the documentation:
You can, as well, have multiple top-level !includes for a given integration, if you give a different label to each one:

light:
- platform: group
  name: "Bedside Lights"
  entities:
    - light.left_bedside_light
    - light.right_bedside_light

# define more light groups in a separate file
light groups: !include light-groups.yaml

# define some light switch mappings in a different file
light switches: !include light-switches.yaml
1 Like