Skip to content

Commit 34bf180

Browse files
authored
Document MQTT button (home-assistant#20219)
1 parent 7b1eaae commit 34bf180

File tree

2 files changed

+187
-0
lines changed

2 files changed

+187
-0
lines changed

source/_docs/mqtt/discovery.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Supported by MQTT discovery:
1010

1111
- [Alarm control panels](/integrations/alarm_control_panel.mqtt/)
1212
- [Binary sensors](/integrations/binary_sensor.mqtt/)
13+
- [Buttons](/integrations/button.mqtt/)
1314
- [Cameras](/integrations/camera.mqtt/)
1415
- [Covers](/integrations/cover.mqtt/)
1516
- [Device Trackers](/integrations/device_tracker.mqtt/)
Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
---
2+
title: "MQTT Button"
3+
description: "Instructions on how to integrate MQTT buttons into Home Assistant."
4+
ha_category:
5+
- Button
6+
ha_release: 2021.12
7+
ha_iot_class: Configurable
8+
ha_domain: mqtt
9+
---
10+
11+
The `mqtt` button platform lets you send an MQTT message when the button is pressed in the frontend or the button press service is called. This can be used to expose some service of a remote device, for example reboot.
12+
13+
## Configuration
14+
15+
```yaml
16+
# Example configuration.yaml entry
17+
button:
18+
- platform: mqtt
19+
command_topic: "home/bedroom/switch1/reboot"
20+
```
21+
22+
{% configuration %}
23+
availability:
24+
description: A list of MQTT topics subscribed to receive availability (online/offline) updates. Must not be used together with `availability_topic`.
25+
required: false
26+
type: list
27+
keys:
28+
payload_available:
29+
description: The payload that represents the available state.
30+
required: false
31+
type: string
32+
default: online
33+
payload_not_available:
34+
description: The payload that represents the unavailable state.
35+
required: false
36+
type: string
37+
default: offline
38+
topic:
39+
description: An MQTT topic subscribed to receive availability (online/offline) updates.
40+
required: true
41+
type: string
42+
availability_mode:
43+
description: When `availability` is configured, this controls the conditions needed to set the entity to `available`. Valid entries are `all`, `any`, and `latest`. If set to `all`, `payload_available` must be received on all configured availability topics before the entity is marked as online. If set to `any`, `payload_available` must be received on at least one configured availability topic before the entity is marked as online. If set to `latest`, the last `payload_available` or `payload_not_available` received on any configured availability topic controls the availability.
44+
required: false
45+
type: string
46+
default: latest
47+
availability_topic:
48+
description: The MQTT topic subscribed to receive availability (online/offline) updates. Must not be used together with `availability`.
49+
required: false
50+
type: string
51+
command_topic:
52+
description: The MQTT topic to publish commands to trigger the button.
53+
required: false
54+
type: string
55+
device:
56+
description: "Information about the device this button is a part of to tie it into the [device registry](https://developers.home-assistant.io/docs/en/device_registry_index.html). Only works through [MQTT discovery](/docs/mqtt/discovery/) and when [`unique_id`](#unique_id) is set. At least one of identifiers or connections must be present to identify the device."
57+
required: false
58+
type: map
59+
keys:
60+
configuration_url:
61+
description: 'A link to the webpage that can manage the configuration of this device. Can be either an HTTP or HTTPS link.'
62+
required: false
63+
type: string
64+
connections:
65+
description: 'A list of connections of the device to the outside world as a list of tuples `[connection_type, connection_identifier]`. For example the MAC address of a network interface: `"connections": [["mac", "02:5b:26:a8:dc:12"]]`.'
66+
required: false
67+
type: list
68+
identifiers:
69+
description: A list of IDs that uniquely identify the device. For example a serial number.
70+
required: false
71+
type: [string, list]
72+
manufacturer:
73+
description: The manufacturer of the device.
74+
required: false
75+
type: string
76+
model:
77+
description: The model of the device.
78+
required: false
79+
type: string
80+
name:
81+
description: The name of the device.
82+
required: false
83+
type: string
84+
suggested_area:
85+
description: 'Suggest an area if the device isn’t in one yet.'
86+
required: false
87+
type: string
88+
sw_version:
89+
description: The firmware version of the device.
90+
required: false
91+
type: string
92+
via_device:
93+
description: 'Identifier of a device that routes messages between this device and Home Assistant. Examples of such devices are hubs, or parent devices of a sub-device. This is used to show device topology in Home Assistant.'
94+
required: false
95+
type: string
96+
enabled_by_default:
97+
description: Flag which defines if the entity should be enabled when first added.
98+
required: false
99+
type: boolean
100+
default: true
101+
entity_category:
102+
description: The [category](https://developers.home-assistant.io/docs/core/entity#generic-properties) of the entity.
103+
required: false
104+
type: string
105+
default: None
106+
icon:
107+
description: "[Icon](/docs/configuration/customizing-devices/#icon) for the entity."
108+
required: false
109+
type: icon
110+
json_attributes_template:
111+
description: "Defines a [template](/docs/configuration/templating/#processing-incoming-data) to extract the JSON dictionary from messages received on the `json_attributes_topic`. Usage example can be found in [MQTT sensor](/integrations/sensor.mqtt/#json-attributes-template-configuration) documentation."
112+
required: false
113+
type: template
114+
json_attributes_topic:
115+
description: The MQTT topic subscribed to receive a JSON dictionary payload and then set as sensor attributes. Usage example can be found in [MQTT sensor](/integrations/sensor.mqtt/#json-attributes-topic-configuration) documentation.
116+
required: false
117+
type: string
118+
name:
119+
description: The name to use when displaying this button.
120+
required: false
121+
type: string
122+
default: MQTT Button
123+
object_id:
124+
description: Used instead of `name` for automatic generation of `entity_id`
125+
required: false
126+
type: string
127+
payload_available:
128+
description: The payload that represents the available state.
129+
required: false
130+
type: string
131+
default: online
132+
payload_not_available:
133+
description: The payload that represents the unavailable state.
134+
required: false
135+
type: string
136+
default: offline
137+
payload_press:
138+
description: The payload To send to trigger the button.
139+
required: false
140+
type: string
141+
default: "PRESS"
142+
qos:
143+
description: The maximum QoS level of the state topic. Default is 0 and will also be used to publishing messages.
144+
required: false
145+
type: integer
146+
default: 0
147+
retain:
148+
description: If the published message should have the retain flag on or not.
149+
required: false
150+
type: boolean
151+
default: false
152+
unique_id:
153+
description: An ID that uniquely identifies this button entity. If two buttons have the same unique ID, Home Assistant will raise an exception.
154+
required: false
155+
type: string
156+
{% endconfiguration %}
157+
158+
<div class='note warning'>
159+
160+
Make sure that your topic matches exactly. `some-topic/` and `some-topic` are different topics.
161+
162+
</div>
163+
164+
## Examples
165+
166+
In this section, you will find some real-life examples of how to use this feature.
167+
168+
### Full configuration
169+
170+
The example below shows a full configuration for a switch.
171+
172+
```yaml
173+
# Example configuration.yaml entry
174+
switch:
175+
- platform: mqtt
176+
unique_id: bedroom_switch_reboot_btn
177+
name: "Reboot Bedroom Switch"
178+
state_topic: "home/bedroom/switch1"
179+
command_topic: "home/bedroom/switch1/commands"
180+
availability:
181+
- topic: "home/bedroom/switch1/available"
182+
payload_press: "reboot"
183+
qos: 0
184+
retain: false
185+
entity_category: "config"
186+
```

0 commit comments

Comments
 (0)