MQTT Device trigger
The MQTT Device trigger integrationIntegrations connect and integrate Home Assistant with your devices, services, and more. [Learn more] uses an MQTT message payload to generate device trigger events.
An MQTT device trigger is a better option than a binary sensor for buttons and remote controls.
Configuration
An MQTT device trigger can be set up in the following ways:
- Through device discovery, as a component with
"platform": "device_automation"(p) in the discovery payload of the device. - Through single component discovery, on the discovery topic
<discovery_prefix>/device_automation/[<node_id>/]<object_id>/config.
The configuration variables below apply to discovery. How the device information is set depends on the configuration method. See MQTT device configuration.
Manual setup through configuration.yamlThe configuration.yaml file is the main configuration file for Home Assistant. It lists the integrations to be loaded and their specific configurations. In some cases, the configuration needs to be edited manually directly in the configuration.yaml file. Most integrations can be configured in the UI. [Learn more] is not supported. Note that only one trigger may be defined per unique discovery topic. Also note that the combination of type and subtype should be unique for a device.
Configuration Variables
Must be device_automation. Only allowed and required in MQTT auto discovery device messages.
The maximum QoS level to be used when receiving and publishing messages.
The type of the trigger, for example, button_short_press. Entries supported by the frontend: button_short_press, button_short_release, button_long_press, button_long_release, button_double_press, button_triple_press, button_quadruple_press, button_quintuple_press. If set to an unsupported value, will render as subtype type, for example, button_1 spammed with type set to spammed and subtype set to button_1
The subtype of the trigger, for example, button_1. Entries supported by the frontend: turn_on, turn_off, button_1, button_2, button_3, button_4, button_5, button_6. If set to an unsupported value, will render as subtype type, for example, left_button pressed with type set to button_short_press and subtype set to left_button
Information about the device this device trigger is a part of, to tie it into the device registry. See MQTT device configuration for the device options and how to set them for each configuration method.
Example
This shows a complete example of defining a remote control type device with two triggers: “left arrow click” and “right arrow click”.
Note that it is not necessary to provide the full device information in each message, but the identifying information, identifier in the example, must be the same.
Left arrow click configuration
-
Discovery topic:
homeassistant/device_automation/0x90fd9ffffedf1266/action_arrow_left_click/config -
Discovery payload:
{ "automation_type": "trigger", "type": "action", "subtype": "arrow_left_click", "payload": "arrow_left_click", "topic": "zigbee2mqtt/0x90fd9ffffedf1266/action", "device": { "identifiers": [ "zigbee2mqtt_0x90fd9ffffedf1266" ], "name": "0x90fd9ffffedf1266", "sw_version": "Zigbee2MQTT 1.14.0", "model": "TRADFRI remote control (E1524/E1810)", "manufacturer": "IKEA" } } -
Trigger topic:
zigbee2mqtt/0x90fd9ffffedf1266/action -
Trigger payload:
arrow_left_click
Right arrow click configuration
-
Discovery topic:
homeassistant/device_automation/0x90fd9ffffedf1266/action_arrow_right_click/config -
Discovery payload:
{ "automation_type": "trigger", "type": "action", "subtype": "arrow_right_click", "payload": "arrow_right_click", "topic": "zigbee2mqtt/0x90fd9ffffedf1266/action", "device": { "identifiers": [ "zigbee2mqtt_0x90fd9ffffedf1266" ] } } -
Trigger topic:
zigbee2mqtt/0x90fd9ffffedf1266/action -
Trigger payload:
arrow_right_click