HAButton class

class HAButton : public HABaseDeviceType

HAButton represents a button that’s displayed in the Home Assistant panel and triggers some logic on your Arduino/ESP device once clicked.

Note

You can find more information about this entity in the Home Assistant documentation: https://www.home-assistant.io/integrations/button.mqtt/

Public Functions

HAButton(const char *uniqueId)
Parameters

uniqueId – The unique ID of the button. It needs to be unique in a scope of your device.

inline void setDeviceClass(const char *deviceClass)

Sets class of the device. You can find list of available values here: https://www.home-assistant.io/integrations/button/#device-class

Parameters

deviceClass – The class name.

inline void setIcon(const char *icon)

Sets icon of the button. Any icon from MaterialDesignIcons.com (for example: mdi:home).

Parameters

icon – The icon name.

inline void setRetain(const bool retain)

Sets retain flag for the button’s command. If set to true the command produced by Home Assistant will be retained.

Parameters

retain

inline void onCommand(void (*callback)(HAButton *sender))

Registers callback that will be called each time the press command from HA is received. Please note that it’s not possible to register multiple callbacks for the same button.

Parameters

callback

Protected Functions

virtual void buildSerializer() override
virtual void onMqttConnected() override
virtual void onMqttMessage(const char *topic, const uint8_t *payload, const uint16_t length) override

Private Members

const char *_class

The device class. It can be nullptr.

const char *_icon

The icon of the button. It can be nullptr.

bool _retain

The retain flag for the HA commands.

void (*_commandCallback)(HAButton *sender)

The command callback that will be called once clicking the button in HA panel.