Re use same template for multiple sensors

Hi all,

I have been trying to figure out how I could ease the use or templating sensors ect for my self.

I’m using a frenck style layout for my config and am partially a Siemens s7 plc programmer for my job.

Wy I wrote about the s7 part is as follows:
Within Siemens programming you are able to built a function block and “call” this several times in your program. At that call you also specify witch inputs, outputs and settings you would like to use. It’s realy useful in an object oriented way of programming.
Siemens is calling this multiple instance.

I would love to do this also with my templates in my HA. So let’s say you write the Template for a window sensor. This sensor is used for multiple windows. So I want to call the template multiple times with each time an other sensor specified.

Hope i write it in an way it’s understandable.

Advice would be really appreciated!

This is applicable to all yaml, not just Lovelace.

1 Like

Wonderful! Will look in to that!

I’m not 100% getting how I should configure it wit anchors to achieve what I would like.

The nicest would be to make the template in an separate yaml. And call that yaml when you specify a sensor.

Then it would become some ting like:

Referencing specifications of sensor

Then import template

1 Like

See the answer given here:

Old thread, but exactly what I am looking for. In DELPHI you could just create a function() and pass a parameter. The function takes it apart and returns a value. So basically pass a sensor and get something in return. Can be used for multible sensors…

Any news on this?

Yes. Reusable templates were introduced in 2023.4. Release notes:

And documentation:

1 Like

“Reusing Templates” are the way to go, so cool and exactly what I was looking for. Thank you.