it needs to be -trigger: not template_trigger: and each triggered sensor/binary sensor has to start with -trigger:
EDIT: ayup,
Logger: homeassistant.config
Source: config.py:445
First occurred: 01:13:43 (1 occurrences)
Last logged: 01:13:43
Invalid config for [template]: [template_trigger] is an invalid option for [template]. Check: template->template_trigger. (See /config/configuration.yaml, line 162).
I don’t see any way to do the template triggered sensors.
Pretty sure that will generate a duplicate template: key error.
I don’t actually use triggered sensors as I find automations that publish retained mqtt messages and mqtt sensors initialise better after a restart. So I might just skip them.
In the off chance that I ever do need one I can bung it in configuration.yaml.
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: Test
state: 'unavailable'
unit_of_measurement: "Days"
All sensors shows up fine including the trigger template.
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 *