Dashboard Button to Publish MQTT Payload

Hey Guys -

Aside from my other devices, I recently set up a Raspberry Pi Zero /w RF hardware which I programmed to send RF signals to control devices (replicating factory remote) in my office. I set it up to monitor an MQTT topic so that it will signal whatever matches the payload.

Example: Publishing the payload “fanlight” to the topic “/office/ceilingfan” turns the ceiling fan’s light on.

Unfortunately, I cannot find a way to get Home Assistant to add a button in a dashboard which would allow publishing to MQTT in this manner. I looked at creating an Automation where I could set triggers to monitor for MQTT, but the only option that exists for Actions is to publish via MQTT Service which doesn’t allow a custom payload.

Any suggestions on the best way to implement this?

Thanks

Hi,

Have a look to

The button’s tap_action can call a script. The script publishes a payload to a topic.

?
Not sure what made you come to that conclusion. You can use a template to generate whatever payload is needed. If the template requires extra data it can be passed to the script as a variable.

In this example, the button’s tap_action calls script.your_script and passes it a variable called whatever containing the value abc123.

    tap_action: 
      action: call-service
      service: script.your_script
      service_data:
        whatever: 'abc123'

The script can refer to the whatever variable. In this example it will publish the value of whatever to your/topic.

    - service: mqtt.publish
      data:
        topic: your/topic
        payload: "{{ whatever }}"