Easy template help please

I’m not sure why this is such a struggle for me but I have a variable which I want to use as a value for one of the parameters to setting up a call to a Zigbee device in an automation. The variable is called var.1. The parameter is called melody. So I have tried this

service: mqtt.publish data: topic: zigbee2mqtt/Office - noisemaker/set payload: null retain: false payload_template: "\"melody\":\"{{ states ('var.1') }}\"" enabled: true

and any number of variants. The problem is I can’t get the syntax right in the payload_template line. The first bit prior to the colon is correct as far as I can tell!!

How shoudl it look please?

service: mqtt.publish
data:
  topic: zigbee2mqtt/Office - noisemaker/set
  payload: null
  retain: false
  payload_template: "\"melody\":\"{{ states ('var.1') }}\""
enabled: true

Rename your variable to var_1 Then try this:

payload_template: >
  "melody":{{ var_1 }}

Unless of course 1 is actually an attribute of your variable var.

Thanks @tom_l , that has got me past that point.

I would have said I’d used that construct in my testing but I must just have been close, but not close enough!! Thanks again.