Help with templating binary sensors

I have created a reasonably complicated binary sensor entity for a PWM dimmer

I now want to create 8 of these attached to different LEDC PWM output channels

Obviously I don’t want to copy/ maintain 8 copies of the code

It sounds like templating should enable me to do this but I am struggling to find worked examples of using templating to create multiple entities like I want to do

Clearly I am looking in the wrong places…

Thanks

Templates are a completely different thing really, a template binary switch is just one that can include code to determine the state.

You probably need to read about substitutions, packages etc - although I am not sure if that will achieve what you want:

Thank-you!

Funnily enough, I woke today with a different search query in my head that found the same Configuration Types article. “Packages as Templates” works perfectly

I logged in to post this solution but found your post :slight_smile:

  dimmer_1: !include
    file: packages/dimmer.yaml
    vars:
      switch_no: 1
      switch_pin_no: 5
      pwm_pin_no: 6

Thanks again

2 Likes