How to concat a string with number in YAML for a MQTT topic?

I am trying to send an MQTT payload with this YAML code:

action:
  - service: mqtt.publish
    data:
      payload: z1Ofor{{input_number.irrigationzone1_tmr}}
      topic: IrrigationInTopic

The payload text sytax is like this:

  • z1 is an irrigation zone
  • O is to turn it ON
  • The ‘for’ is to set the time in minutes the zone will turn ON
  • input_number.irrigationzone1_tmr is a Helper Number
  • If input_number.irrigationzone1_tmr was 5 then the payload I want is “z1Ofor5”.

So, really my problem is how do I concatenate a string, “z1Ofor” with a number, input_number.irrigationzone1_tmr.

Like this:

payload: "z1Ofor{{ states('input_number.irrigationzone1_tmr')|int(0) }}"

Awesome, thank you! That works perfectly.

I’m a totally new to YAML and I’m struggling a bit with it.

Templates are made with Jinja, not YAML.

Here’s a good read on YAML for beginners:

http://thomasloven.com/blog/2018/08/YAML-For-Nonprogrammers/

HA templating documents:

Jinja documentation:

https://jinja.palletsprojects.com/en/3.1.x/api/#basics