the only caveat is that those are exactly the way the files are written. They don’t have any actual sensor code in there at all, just the headings.
But it did pass the config check.
I assume it’s just like having multiple “automation:” or “script:” by adding another label after it to differentiate the two files/code. (“automation old:” or “script second:”)
it looks like the “template binary:” and “template triggered:” entries in configuration.yaml are completely ignored.
If I put any code in those files the files aren’t loaded. Nothing even in the logs about it
That seems like it should be an issue report to me.
It should work for the template integration just as it does for any other integration using the old “method 1” and “method 2” references. I can’t specifically find those references in the docs anymore but the concept is still discussed and should be valid. Or at least it should be made to work that way for consistency.
Sorry to dredge up this old thread, but this is exactly what I’m trying to do; migrate all my templates to the new format, and at the same time, split them off into a new templates.yaml file.
Without the workaround @123 suggested (adding his dummy triggered sensor to the beginning of the templates.yaml file) I get errors. Put that sensor back in and it passes the configuration test.
So, @tom_l, did you ever get it working without the triggered sensor, and if so, how?
This thread has already saved me a ton of time. This was driving me crazy until I found the trigger workaround. Thank you!!
Thanks, both of you, for the amazingly quick response!!!
I was going to use just one templates.yaml file, but two or more will work just as well.
Is this a bug? Should it be reported? There seem to be two workarounds now, so it’s not critical. I’m sure it will trip up other users going forward, as more people (hopefully) migrate to the new template method.
I wouldn’t characterize what tom_l and I have offered as being workarounds; they’re legitimate means of structuring the information in their own right. I don’t even know if what I suggested is immune to the reported glitch because I have not tried it without a trigger.yaml file (clearly tom_l’s suggestion isn’t affected by it).
However, to your point, it does feel like a bug because there should be no need to define at least one Trigger-based Template Sensor before others can be defined. If you know if still occurs in the latest release (I haven’t tested it), report it as an Issue in the GitHub Core repository.
I have a way to split the templates to different folders. I know OP wanted flat files, but i like to nest and have multiple files.
Folder structure:
.
└──
├── configuration.yaml
└── templates
├── binary_sensor
│ └──* place all template binary sensors in here *
├── sensor
│ └──* place all template sensors in here *
└── triggers
├──default_templates.yaml
└──* place all template triggers in here *
thnx man,
yes, that’s exactly what I’ll do but would it be possible to have various kinds of templates in one file such as a custom media_player template, a fan template and a light template?
if possible, how should I change the relevant code?
Can I just put all the different templates in a single template.yaml without chaning anything?
This is how they are in my configuration.yaml file.
where each subfolder may have other subfolders and so on.
Inside any folder (let it be “network/net/asus_ac68u”, for example) create as many yaml files as you want.
Every yaml file may have “sensor”, “template”, “input_boolean”, “automation”, “customize” etc sections (surely one same section per one file, i.e. one “sensor”, one “customize” etc).
The main idea is to structure a config by tasks (network devices, persons, weather, home climat, etc) - instead of piling all template sensors in one file.
Unfortunately, there is one limitation - you must use unique filenames.
I.e. you cannot have several “test.yaml” files in different folders - have to rename them to “test_router.yaml”, “test_waterpump.yaml” etc. Created this issue, missed a moment when it was closed.
Also, if you want to exclude some functionality (like “got rid of this router”) - just remove the whole “router xxx” folder form the structure. Alternatively - rename all yaml files in this folder, replace “yaml” extension by something llike “disabled” (I use “dis”).
If you have several HA installation (apartment, country house, test setup, …) and some router is moved from one place to another - just move it’s particular folder into another installation.
Secrets may also be stored on several levels (local secrets, global secrets).
What am I missing? My sensors never show up in states!
this is what I did using your expamples.
made a folder templates, in it folder sensors and binary_sensors in those folders I placed yaml files with a sensor for instance, when I make a typo in them or leave out the word sensor: I get an error when i update template entites so ha looks in those files, that works some how