Variable syntax help require for "TOPIC"

Hi Guys,
I have a simple MQTT automation and need to chage the mqtt TOPIC: values but cannot get the syntax order correct.
This works well
topic: “cmnd/sonoff_53/color” and will send the MQTT to my Sonoff_53
but I wont to replace the sonoff_53 in the middle to a variable that is stored in ‘input_select.bulb_selector’
something like this ( which does not work )
Topic: “cmnd/{{ input_select.bulb_selector }} /color”

Any help on formatting this line would be great
Thanks Dave

Which does not work where?

Are you trying to set the command_topic of an MQTT component or is this part of an automation’s action (mqtt.publish) or what is it?

Sorry, Should have included a little more info. New to this forum , so just getting my head around its use…

This is part of the automation section and I am using the mqtt.publish
################################################################################

Change LED Bulb Color with Input Select

################################################################################

  • alias: Led Color Automation
    trigger:
    platform: state
    entity_id: input_number.slider_red, input_number.slider_green, input_number.slider_blue, input_number.slider_white
    action:
    • service: mqtt.publish
      data_template:
      topic: “cmnd/sonoff_53/color”
      payload: ‘{{ states.input_number.slider_red.state | int }},{{ states.input_number.slider_green.state | int }},{{ states.input_number.slider_blue.state | int }},{{ states.input_number.slider_white.state | int }}’

This snippit above works as it should by would like to change the sonoff_53 in the middle of the topic to a value that is stored in “input_select.bulb_selector”

This will do the trick:

topic: "{{ 'cmnd/' + states('input_select.bulb_selector') + '/color' }}"

Here it is in a formatted version of your automation:

  - alias: Led Color Automation
    trigger:
      platform: state
      entity_id: input_number.slider_red, input_number.slider_green, input_number.slider_blue, input_number.slider_white
    action:
      service: mqtt.publish
      data_template:
        topic: "{{ 'cmnd/' + states('input_select.bulb_selector') + '/color' }}"
        payload: '{{ states.input_number.slider_red.state | int }},{{ states.input_number.slider_green.state | int }},{{ states.input_number.slider_blue.state | int }},{{ states.input_number.slider_white.state | int }}'

Hi 123
Worked like a charm, once I sorted my silly entity change errors, reboot modem which stopped sending any wifi and changed the bulbs back to the correct ones.
Now all I got to do is get my head around exactly whats going on with that line. I think Ive got the idea but have to admit it would have taken me a long time to work that one out.
Thanks Dave ( Happy Days )