Input Replacement in Script

I want to create a blueprint for a script that accepts an input and uses that in a few places in a MQTT service call.

So essentially I want to replace {{XXX}} here with a user input

  - service: mqtt.publish
    data:
      topic: homeassistant/sensor/smart_meter_electricity_export/config
      payload: >-
        {
        "name": "Smart Meter Electricity: Export",
        "unique_id": "smart_meter_electricity_export",
        "state_topic": "glow/{{XXX}}/SENSOR/electricitymeter",
        "device_class": "energy",
        "unit_of_measurement": "kWh",
        "state_class": "total_increasing",
        "value_template": "{% raw %}{{ value_json['electricitymeter']['energy']['export']['cumulative'] }}{% endraw %}",
        "icon": "mdi:flash",
        "device": {
            "identifiers": "Smart Electricity Meter via IHD",
            "name": "smart_electricty_meter_{{XXX}}",
            "model": "Smart Electricity Meter via IHD",
            "manufacturer": "Hildebrand"
        }
        }
      retain: true

and repeat that for lots of entities (all using the same input).

I can get the input

blueprint:
  name: Add Hildebrand IHD Entities
  description: Create devices and entities using MQTT discovery
  domain: script
  input:
    ihdMAC:
      name: MAC Address
      description: "MAC address of IHD (without :s)"
      default: ""

and I can reference

!input ihdMAC

as a standalone value but I cannot for the life of me work out how (or if) I can use it as part of the string that I need to pass

Thanks to WhatWeAreFixing.Today on Discord I figured it out so posting here incase anyone come across this looking for the same.

You simply need to convert the input to a variable to use it in templates (which it turns out is documented Blueprint schema - Home Assistant … albeit in a slightly odd place).

Here I can

blueprint:
  name: Add Hildebrand IHD Entities
  description: Create devices and entities using MQTT discovery
  domain: script
  input:
    ihdMAC:
      name: MAC Address
      description: "MAC address of IHD (without :s)"
      default: ""

variables:
  myVar: !input ihdMAC

  - service: mqtt.publish
    data:
      topic: homeassistant/sensor/smart_meter_electricity_export/config
      payload: >-
        {
        "name": "Smart Meter Electricity: Export",
        "unique_id": "smart_meter_electricity_export",
        "state_topic": "glow/{{myVar}}/SENSOR/electricitymeter",

and this seems to work fine

1 Like

I was just going to pop in and help, but I see I already did. I am WhatAreWeFixing.today as well.
I hope all is well.
I have since did a BP with lots of MQTT Discovery, in case it gives you more ideas.