Add docs for mqtt.on_connect / on_disconnect (#2105)

This commit is contained in:
jimtng 2022-06-03 11:51:54 +10:00 committed by GitHub
parent 2b3edea033
commit c34c62430d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 1 deletions

View File

@ -89,6 +89,10 @@ Configuration variables:
- **keepalive** (*Optional*, :ref:`config-time`): The time
to keep the MQTT socket alive, decreasing this can help with overall stability due to more
WiFi traffic with more pings. Defaults to 15 seconds.
- **on_connect** (*Optional*, :ref:`Automation <automation>`): An action to be performed when a connection
to the broker is established.
- **on_disconnect** (*Optional*, :ref:`Automation <automation>`): An action to be performed when the connection
to the broker is dropped.
- **on_message** (*Optional*, :ref:`Automation <automation>`): An action to be
performed when a message on a specific MQTT topic is received. See :ref:`mqtt-on_message`.
- **on_json_message** (*Optional*, :ref:`Automation <automation>`): An action to be
@ -368,6 +372,22 @@ Configuration variables:
When changing these options and you're using MQTT discovery, you will need to restart Home Assistant.
This is because Home Assistant only discovers a device once in every Home Assistant start.
.. _mqtt-on_connect_disconnect:
``on_connect`` / ``on_disconnect`` Trigger
------------------------------------------
This trigger is activated when a connection to the MQTT broker is established or dropped.
.. code-block:: yaml
mqtt:
# ...
on_connect:
- switch.turn_on: switch1
on_disconnect:
- switch.turn_off: switch1
.. _mqtt-on_message:
``on_message`` Trigger

View File

@ -330,7 +330,8 @@ All Triggers
- :ref:`light.on_turn_on / light.on_turn_off <light-on_turn_on_off_trigger>`
- :ref:`logger.on_message <logger-on_message>`
- :ref:`time.on_time <time-on_time>` / - :ref:`time.on_time_sync <time-on_time_sync>`
- :ref:`mqtt.on_message <mqtt-on_message>` / :ref:`mqtt.on_json_message <mqtt-on_json_message>`
- :ref:`mqtt.on_message <mqtt-on_message>` / :ref:`mqtt.on_json_message <mqtt-on_json_message>` /
:ref:`mqtt.on_connect / mqtt.on_disconnect <mqtt-on_connect_disconnect>`
- :ref:`pn532.on_tag <pn532-on_tag>` / :ref:`rdm6300.on_tag <rdm6300-on_tag>`
- :ref:`interval.interval <interval>`
- :ref:`switch.on_turn_on / switch.on_turn_off <switch-on_turn_on_off_trigger>`