Skip to content

Commit

Permalink
feat(MQTT): Add enable, disable and enable_on_boot (#4408)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rapsssito authored Nov 6, 2024
1 parent 0194102 commit b2cad90
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions components/mqtt.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Configuration variables:
------------------------

- **broker** (**Required**, string): The host of your MQTT broker.
- **enable_on_boot** (*Optional*, boolean): If enabled, MQTT will be enabled on boot. Defaults to ``true``.
- **port** (*Optional*, int): The port to connect to. Defaults to 1883.
- **username** (*Optional*, string): The username to use for
authentication. Empty (the default) means no authentication.
Expand Down Expand Up @@ -733,6 +734,57 @@ Configuration options:
root["something"] = id(my_sensor).state;
});
``mqtt.disable`` Action
-----------------------

This action turns off the MQTT component on demand.

.. code-block:: yaml
on_...:
then:
- mqtt.disable:
.. note::

The configuration option ``enable_on_boot`` can be set to ``false`` if you do not want MQTT to be enabled on boot.


``mqtt.enable`` Action
----------------------

This action turns on the MQTT component on demand.

.. code-block:: yaml
on_...:
then:
- mqtt.enable:
.. note::

The configuration option ``enable_on_boot`` can be set to ``false`` if you do not want MQTT to be enabled on boot.
``mqtt.enable`` can be useful for custom setups. For example, if the broker name is negotiated dynamically and saved in a global variable.

.. code-block:: yaml
mqtt:
id: mqtt_id
broker: ""
enable_on_boot: False
globals:
- id: broker_address
type: std::string
restore_value: yes
max_restore_data_length: 24
initial_value: '"192.168.1.2"'
on_...:
then:
- lambda: !lambda id(mqtt_id).set_broker_address(id(broker_address));
- mqtt.enable:
.. _mqtt-connected_condition:

``mqtt.connected`` Condition
Expand Down

0 comments on commit b2cad90

Please sign in to comment.