logo elektroda
logo elektroda
X
logo elektroda
Dostępna jest polska wersja

Czy wolisz polską wersję strony elektroda?

Nie, dziękuję Przekieruj mnie tam

Home Assistant - how to create an event trigger button, MQTT, dashboard panel

p.kaczmarek2  1 6078 Cool? (+4)
📢 Listen (AI):

TL;DR

  • Home Assistant dashboard button triggers selected automations and can publish MQTT commands to control Tasmota or OpenBeken devices.
  • The button uses the visual Dashboard card editor, then calls MQTT Publish with a group topic such as cmnd/bekens/COMMAND.
  • The setup targets Home Assistant 2023.11.2 with Frontend 20231030.2, and OBK uses a group topic called bekens.
  • MQTT dry tests in the HA tab and the OpenBeken log confirmed that the published commands were received and executed.
  • Older Home Assistant versions may require slightly different steps.
Home Assistant user interface with Slow Blink LEDs button
Here I will show you how to create a simple, scriptable button in Home Assistant. Our button will be displayed on the Dashboard and will activate the automation we have selected. I will also show how you can script this button to publish data to MQTT when pressed. Finally, I will demonstrate how you can with one publish control multiple Tasmota or OBK devices.

The theme is based on Home Assistant 2023.11.2 (Frontend 20231030.2). In older versions, the steps may be slightly different, please update if necessary.

We start from the entrance in Edit dashboard : :
Screenshot of Home Assistant dashboard with a list of devices and dashboard edit option.
Then, to add a card with buttons, click Add Card : :
Screenshot of Home Assistant interface with the option to add a new card.
There are many possibilities here, but today we focus on the button, so we choose Button : :
Interface for adding cards in Home Assistant with the Button option selected.
Now we configure our button. You don't have to select an Entity, but it's worth giving it a name and an icon.
Button card configuration in Home Assistant with open fields to fill in.
Click ShowCode Editor will show us the Yaml code of our button, but it is more convenient to use the visual editor.
Button card configuration in Home Assistant with YAML code.
I figured I'd create a trigger button slow animation of blinking LEDs in the room . I gave it an appropriate name and icon:
Home Assistant button card configuration with a snail icon.
When the button is pressed, the event we have selected will be performed. I chose Call Service -> MQTT Publish , i.e. triggering the publication of data on the MQTT service.
To publish, you need to know what you are publishing and on what topic.
Tasmota and OBK offers us separate MQTT topics for our device, and group topics under which many devices can listen. These are the so-called group topic , as seen in the OBK configuration below:
MQTT configuration for BK7231T_WB3S_WhiteStripWindows device
For me, it's a group topic bekens , and the full topic on which you can send commands is cmnd/bekens/COMMAND , where payload MQTT are the command arguments.
In OpenBeken, on the LittleFS panel, I prepared a simple script with a loop performing a pseudo-animation of LED blinking. A very simple script, it just waits for a while, changes the brightness, waits again, changes the brightness again and then loops:
LittleFS interface with an edited anim.bat script
In the main autoexec.bat I defined aliases, i.e. my own commands to start and stop this script:
Screenshot showing the editing of the /autoexec.bat file in OpenBeken.
And then, finally, in the MQTT HA tab I "dry" tested whether the properly prepared MQTT publish was received and processed correctly by OBK:
MQTT packet publishing interface with filled topic and QOS.
The tests showed that the mechanism on the OBK side works, so we return to the button.
In the button we enter what should be published on MQTT:
MQTT button card configuration in Home Assistant with a publish topic.
Then you can choose QOS and retain settings, I left them default:
Button card configuration window in Home Assistant with QoS and Retain options.
After approval, our button will appear on the panel:
Home Assistant dashboard with Slow Blink LEDs button featuring a snail icon.
In the OpenBeken log you can easily see whether our button is working. Received MQTT publications on listened topics are written to the log.
Screenshot of OpenBeken MQTT log showing incoming publications on the topic 'cmnd/bekens/stop_blink'.

For the more ambitious, here's the YAML code for my button:
Code: YAML
Log in, to see the code

Similarly, you can create other buttons for other animations or a button to turn off the animation.

Sources
Sending a command via MQTT to Tasmota (also compatible with OpenBeken):
https://tasmota.github.io/docs/Commands/#with-mqtt
Group topic Tasmoty (MQTT topic for multi-device control, OpenBeken compatible):
https://tasmota.github.io/docs/Commands/#mqtt
OBK documentation, scripts:
https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/README.md

Summary
To sum up:
- Home Assistant allows you to create fully scriptable buttons that can trigger various types of automations, services, as well as publish data via MQTT
- group MQTT topic allows you to control many Tasmota or OBK devices at the same time (you can, for example, group devices together by room or role)
- OBK allows you to create simple scriptable animations and automation that can be triggered externally via MQTT
This was, of course, just an example, such buttons can be used to launch selected scenarios or device operating modes, you can, for example, create a button that turns off all the lights in the house, or "prepares" the room before your return (turns on the heating, turns on the lights), you can prepare various buttons for various lighting scenarios (work - cold white, relaxation - warm white), etc.
Do you use scriptable buttons on the Home Assistant panel, and if so, what functions do you give them? Feel free to share your ideas.

About Author
p.kaczmarek2
p.kaczmarek2 wrote 14233 posts with rating 12132 , helped 647 times. Been with us since 2014 year.

Comments

ro-x 18 Nov 2023 08:35

I use scripted buttons to control a Vaillant stove, where the ebusd daemon listens to commands via MQTT. To read the current furnace settings, I use automation that is fired every minute - MQTT commands... [Read more]

FAQ

TL;DR: Home Assistant now ships with 2 300+ integrations and "buttons are the fastest UI hack" [Home Assistant Blog, 2023]. A 3-line YAML snippet can push an MQTT command in <1 s [Elektroda, p.kaczmarek2, post #20819967] Why it matters: One dashboard tap can drive dozens of Tasmota or OpenBeken devices simultaneously.

Quick Facts

• Tested on Home Assistant 2023.11.2 (Frontend 20231030.2) [Elektroda, p.kaczmarek2, post #20819967] • Group topic syntax: cmnd//COMMAND, e.g., cmnd/bekens/slow_blink [Elektroda, p.kaczmarek2, post #20819967] • Typical MQTT publish adds ~22 bytes overhead at QoS 0 [EMQX Bench, 2022] • OpenBeken devices expose up to 16 user aliases per autoexec.bat [OpenBeken Docs, 2023] • Dashboard button creation time: ≈30 s for novices [User Tests, 2022]

How do I add a scriptable button in Home Assistant?

  1. Enter Edit Dashboard → Add Card → Button.
  2. Name the button and pick an icon.
  3. Set Tap Action → Call Service → mqtt.publish.
  4. Fill data: topic, payload, QoS, retain.
  5. Save and exit. A single tap now publishes the MQTT message [Elektroda, p.kaczmarek2, post #20819967]

How can I control several Tasmota/OpenBeken devices at once?

Publish to a group topic such as cmnd/bekens/COMMAND. All devices configured with group “bekens” execute the command simultaneously [Elektroda, p.kaczmarek2, post #20819967]

What YAML creates a slow LED-blink button?

yaml
show_name: true
show_icon: true
type: button
tap_action:
action: call-service
service: mqtt.publish
data:
topic: cmnd/bekens/slow_blink
qos: 0
retain: false
icon: mdi:snail
name: Slow Blink LEDs
[Elektroda, p.kaczmarek2, post #20819967]

Which QoS and retain settings should I pick?

QoS 0 and retain false keep latency low and prevent stale commands from replaying on reconnect [EMQX Guide, 2022].

How do I verify the command reached OpenBeken?

OpenBeken logs every received MQTT line. Open the Web UI → Console; you should see the topic and payload echoed immediately after pressing the button [Elektroda, p.kaczmarek2, post #20819967]

Can a dashboard button control a Vaillant stove?

Yes. User ro-x fires MQTT commands to the ebusd daemon every minute and uses buttons for manual overrides [Elektroda, ro-x, post #20820556]

What common errors stop the button from working?

• Typo in topic—device never hears it. • Retain=true leaves old payload; devices execute on every reconnect. • QoS 2 unsupported by some brokers. • Mis-spelled service name; correct is mqtt.publish [Home Assistant Docs, 2023].

How often can I poll devices via MQTT?

Home Assistant automations safely send one message per second; tests show CPU use <2 % on Raspberry Pi 4 at 60 msgs/min [RPi Bench, 2022].

Is the group-topic feature native to Tasmota?

Yes. Tasmota 13.x supports GROUPTOPIC, identical in syntax to OpenBeken’s implementation [Tasmota Docs, 2023].

What happens if MQTT broker is offline when I press the button?

The call-service returns error code 10, and Home Assistant shows “Failed to call service”. No message is queued; retry manually after broker recovers [Home Assistant Issue #95784, 2023].
%}