How to create a button that issue a mosquitto_pub command

I’ve installed on my RPi5 a Mosquitto Broker and all works fine.
Anyway I’d need to associate a command like this to an Home Assistant button so that , every time it is pressed, issue the comand:

mosquitto_pub -t home/OpenMQTTGateway/commands/MQTTtoBT -m '{
  "immediate":true }

Is it possible?
Thanks in advance

what doesn’t mqtt.publish do that you want?

example from the docs (MQTT - Home Assistant):

service: mqtt.publish
  topic: homeassistant/sensor/Acurite-986-1R-51778/config
  payload: >-
    {"device_class": "temperature",
    "unit_of_measurement": "\u00b0C",
    "value_template": "{{ value|float }}",
    "state_topic": "rtl_433/rtl433/devices/Acurite-986/1R/51778/temperature_C",
    "unique_id": "Acurite-986-1R-51778-T",
    "device": {
    "identifiers": "Acurite-986-1R-51778",
    "name": "Bathroom",
    "model": "Acurite-986",
    "manufacturer": "rtl_433" }
1 Like

Hi armedad.
Thanks for your reply.
I’ll try