Are there configuration templates?

Hello everyone,

I have several devices which configuration follows the same template:

  - platform: mqtt
    name: "radio1"
    state_topic: "radio/tele/maison/radio1/RESULT"
    command_topic: "radio/cmnd/maison/radio1/POWER"
    availability_topic: "radio/tele/maison/radio1/LWT"
    qos: 1
    payload_on: 'On'
    payload_off:  'Off'
    payload_available: "Online"
    payload_not_available: "Offline"
    retain: true

  - platform: mqtt
    name: "radio2"
    state_topic: "radio/tele/maison/radio2/RESULT"
    command_topic: "radio/cmnd/maison/radio2/POWER"
    availability_topic: "radio/tele/maison/radio2/LWT"
    qos: 1
    payload_on: 'On'
    payload_off:  'Off'
    payload_available: "Online"
    payload_not_available: "Offline"
    retain: true

They only differ by the number next to radio.

Is there a way to combine them into one templated block, which would then be populated with some predefined entries (a loop or an array)?

write a little python script that replaces the number 2 and auto generate the lines of code:

thestring = """  - platform: mqtt
    name: "radio{}"
    state_topic: "radio/tele/maison/radio{}/RESULT"
    command_topic: "radio/cmnd/maison/radio{}/POWER"
    availability_topic: "radio/tele/maison/radio{}/LWT"
    qos: 1
    payload_on: 'On'
    payload_off:  'Off'
    payload_available: 'Online'
    payload_not_available: 'Offline'
    retain: true"""

for i in range(1, 10):
    print thestring.format(i, i, i, i)

super lazy but works. Then just copy and paste the print. If you’re feeling up to it, write it to a file.

This is what I am doing now - by using a jinja2 template. I was hoping this would be built-in in HA. Thanks!

I don’t think it is built in. I could be wrong, but I haven’t come accross any ‘configuration template’. That doesn’t mean it’s non-existent. Your best option to find something is backing out to google, and search from there using ‘site:home-assistant.io’ at the end of every search. It will limit your searches to this entire site and it works 1000x better than using the searches on this site.