In the spirit of DRY (Don’t repeat yourself), I’m looking to build a resusable sensor template. My suspicion is that this needs to be a custom component, but before I go down that route I want to ensure there isn’t another way.
I have the following repeated four times in my config, once for each member of the family. The only bit that changes is the proximity sensor (in this case proximity.ali_travel). Essentially, the sensor shows how far someone is from home, and changes the icon depending on at home, moving (away/towards home) or parked away from home.
So can this be packaged in such a way that it can be reused by just passing in the proximity sensor?
I realise that, that was why I was seeing if this could be moved into it’s own template somehow. I’m thinking my only option is to build a custom component.
Sure it would be updating a sensor with an automation and not templating.
But there’s actually no integrates way to avoid repetition.
With repetitive configuration file, when there’s no way to avoid repetition I tend to generate my config file with a script, therefore even if the code repeat itself I do not repeat myself and edits are way faster.
So you can use dedicated yalm file generated programmatically
The request is for a method to easily create multiple instances of a single Template Sensor configuration, each with only minor differences. Effectively, a means of templating YAML. There’s no native facility for that purpose.
Thanks for this! This was exactly what I was looking for. I was able to create a macro with functions that determine the amount of days remaining until my plants need water by passing the last watered date for each plant as a variable. Then I call the function in a template card on my dashboard.
Came here sadly because I wanted an answer for this specific thing, too. I need to template a light because I’ve got a physical light that doesn’t respond well to specific parameters, so I need to swap it out for a virtual copy that eats the bad parameters. So I was hoping to be able to do something like this, but I cannot find any way there.
But, i do have an answer for some situations, such as the original poster here:
You could make a helper string or enum or number or whatever to contain status, and then create a blueprint automation that adjusts helper.X based on proxmity.Y .
At least for that case, that’d probably be a perfectly fine situation. Unfortunately, for mine, it doesn’t solve my problem, because I need to intercept the commands before they go out (i can automate fixing them after the fact if they come in from other sources this way, but i want to make sure that HA never sends out the bad commands)…
If templates are not reusable, I don’t understand why they are named Templates.
it’s because they can use template code inside them. not because they are reusable themselves, sadly.
yep, but copying a single template light many times for many devices is less than desireable … for one, it is fine, but i’ve got a whole case of these lights …