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.
blueprint:
name: Octoprint_Additional_Buttons_Helper- 2023-04-12
author: SirGoodenough
description: 'This is Blueprint is provided as a helper for people using the
Octoprint Plugin called OctoPrint-HomeAssistant. What this does is add 8 buttons,
4 of which you as the user can set your own G-Codes to for customizing.
Also adds safe shutdown and presentation functions along with
Change Filament and Load Filament.
The first thing to remember is ANYTIME you make ANY changes to this Blueprint,
you MUST restart the server so that the button entities can rebuild in the
configuration you have selected. If you don''t restart OctoPrint,
the change may not be seen and you will wonder why and what is happening.
To use this you will need the [OctoPrint-MQTT](https://plugins.octoprint.org/plugins/mqtt/) plug-in installed
along with the [OctoPrint-HomeAssistant](https://github.com/cmroche/OctoPrint-HomeAssistant) plugin.
You will also need to be connected to an MQTT Broker that your Home Assistant
instance is also connected to. Set-up for all that is covered within those
This file has been truncated. show original