Including multiple sensor .yaml files?

Hi all,

I’m a complete noob to HA and honestly, I’m using it to monitor the toner and drum levels of the printers in my office at work. I got one printer’s status up and I started on a second, but I was thinking it would be nice to keep my sensors separate per machine. That said, I was wondering if there’s a way to separate my sensors into separate .yaml files per printer, or if they all have to be in one file. The only reason that I’d do this is purely for organization’s sake, of course! I tried making a “sensors” folder and then putting each file in there and just including them within the config.yaml ala “sensor: !include_dir_merge_named sensors” but that didn’t seem to work. It didn’t error out or anything, but I can’t call my sensors in my scripts for my cards anymore… Am I making this too complicated?

Thanks!
Mark

Welcome, this can be achieved via packages

1 Like

In configuration.yaml: make sure it’s the only sensor: key in the file:

sensor: !include_dir_merge_list sensors

Then put separate YAML files in sensors/. My sensors/heating.yaml starts with:

- platform: history_stats
  name: Heating Hours Today

and my sensors/bins.yaml with:

- platform: waste_collection_schedule
  name: Local bin collection
1 Like

Thank you both!

Okay - so in my configuration.yaml file, I do indeed only have one ‘sensor’ key, exactly like how you have it, @Troon (sorry, I can’t figure out how to format this as code…)

Then, within the folder, I have two .yaml files:
hs-b9100-sensors.yaml
hs-xe-colorsensors.yaml

I use all snmp sensors, so both files start out with:

-platform: snmp
name: ‘b9100_page_count’

and

-platform: snmp
name: ‘c600_page_count’

…and then both go into the other snmp oid’s that I found for each model.

Is that correct so far? I will say, it definitely worked when I had a single file (but I also had the single file in root directory, but I will admit that I didn’t check if the single file worked in the new folder before I created the second file).

Thanks again to both of you!

Single backtick around inline code, so`foo` becomes foo, and three around block code turns

```
bar
```

into

bar

You can have one or more sensors in each file, up to you how you split it:

- platform: snmp
  name: Printer 1
  ...

- platform: snmp
  name: Printer 2
  ...
1 Like

There are two methods:

  1. yaml file contains definition for ONE particular platform (or some subkey like “sensor”):

- sensor:
    - name: …
      …
    - name: …
      …
- binary_sensor:
    - name: …
      …
    - name: …
      …
  1. yaml file contains definition for several platforms:
input_boolean:
  …
template:
  …
automation:
  …

Here is how to implement the 2nd method.

1 Like

This clicked in my mind for me. Thank you!