What I need is to start putting templates into their own directory. Is there a format like above to direct HA where to locate templates? I’m trying to add some entity cards for weather, but the entities are in meters/sec. These templates convert meters/sec to MPH, and I would like to reference these entities so they can display imperial units instead.
I added template: !include_dir_merge_list ../entities/templates and placed the template file there but that did not add the sensor. I had to change the code, then move it into the Integrations directory which is where packages are stored (packages: !include_dir_named integrations).
Now, it appears I can only have one sensor per yaml file. Otherwise, none of the sensors load. Is there a way I can add multiple conversion sensors into one file? Here is the single sensor that now works in the “integrations” folder:
You are trying to put the legacy template sensor config into the “template:” domain key. And you are also mixing up the syntax. Modern template sensors don’t use “value_template”. they use “state” instead.
in the first example above you have:
template:
- sensor:
.
.
that is the modern format template sensor syntax.
in the example you just posted you are using the legacy template syntax:
sensor:
- platform: template
sensors:
.
.
the reason it works in the packages is because packages allow every top level key to be used in the package. So “sensor:” works there. You could have also put your (syntax corrected) “template:” sensor version there and it would have worked there as well.
Never understood an intention to store entities dependently on their domains.
i.e. templates in one folder, command_line in another.
Suggest to organize your config for “tasks” instead of domains. Like here.
For instance - “audi_q7.yaml” keeps all entities & automations related to your car.
Or (better in some cases) - a folder “audi_q7” has files “audi_q7_xxxx.yaml” && “audi_q7_yyyy.yaml” with a similar approach for separate tasks.
Easy, organized, manageable.
Moved Audi Q7 to another household - just move the whole folder to another HA setup.
So therein lies the problem. I pasted your code into a new file under /config/entities/templates, and I lose the sensors again. Pasting it into the template editor, Jinja says its ok, and its returns the correct values:
But the sensors/entities don’t load. Using the modern format, I changed the code as such. This does not work:
It doesn’t matter if I have the file in the /config/entities/templates folder or the /config/integrations folder. It seems if value_template isn’t used, and when placed in the Integrations (packages) directory, neither sensor loads. Reverting the code like this, coupled with moving the file back into the Integrations directory, both sensors then load.
It’s really hard to know exactly what the problem is since you aren’t putting in all the details of where exactly you put the code listed above. and what your file structure really looks like. And what the !include command looks like.
however the (or at least one ) issue with the code you posted is that I steered you wrong so I’m sorry for that. It is putting hyphens (-) in places where it shouldn’t. You had those in your code above and unfortunately I just copy/pasted them without realizing it (I did it when I was half asleep. )
the issue with that is that the code you put into the TEMPLATE editor isn’t a template. and it’s not Jinja. It’s yaml. So the template editor won’t tell you anything about the code being correct.
it works in packages with the legacy format because that is the correct syntax for that type of sensor in a package.
@finity thank you for the adjusted code. Both of the sensors work if I have it in the Integrations folder. So, for now, I think I’ll stick with keeping it there. The idea was to keep adding on as needed, and it looks like I can do that now.
I started separating by domain because a few enthusiasts I follow also worked in this way, and it was easier for me to mimic that format pulling from github to implement some of their ideas. It quickly became too labor-intensive to try (and fail) to translate it into what I had.
The structure I have is:
Automations: /automations
Binary Sensors: /entities/binary_sensors
Device Trackers: /entities/device_trackers
Groups: /entities/groups
Notify: /entities/notify
Packages: /integrations
Scenes: /scenes
Scripts: /scripts
Themes: /themes
Sticking with your current structure format you should be able to create a folder called “templates” under your “entities” folder (so /entities/templates).
then in that folder create some yaml file (we’ll call it “weather.yaml”).
then in your configuration.yaml add an !include to that folder:
The second entity shows as “unavailable” because I don’t have the “sensor.wind_gust” anywhere in my config. If I did it would work just like the first one.