logo elektroda
logo elektroda
X
logo elektroda

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

p.kaczmarek2 5364 1
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • 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.

    Cool? Ranking DIY
    Helpful post? Buy me a coffee.
    About Author
    p.kaczmarek2
    Moderator Smart Home
    Offline 
    p.kaczmarek2 wrote 11846 posts with rating 9941, helped 566 times. Been with us since 2014 year.
  • ADVERTISEMENT
  • #2 20820556
    ro-x
    Level 14  
    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 are also fired here.
ADVERTISEMENT