The above template.yamlpasses config check. However, when inside `/config/entities/templates/template_trigger/justatest.yaml, I insert-
trigger:
- platform: time_pattern
# This will update every night
hours: 0
minutes: 0
sensor:
# Keep track how many days have past since a date
- name: This is just a test
state: ""
unit_of_measurement: "Days"
Resulting in- Invalid config for [template]: expected a dictionary. Got [OrderedDict([('trigger', [OrderedDict([('platform', 'time_pattern'), ('hours', 0), ('minutes', 0)])]), ('sensor', [OrderedDict([('name', 'This is just a test'), ('state', ''), ('unit_of_measurement', 'Days')])])])]. (See ?, line ?).
I donât know with yours, but it does not work with packages like mine.
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.
Create ANY tree structure in the âconfâ folder:
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).