feat(MQTT): Add enable, disable and enable_on_boot (#4408)

This commit is contained in:
Rodrigo Martín 2024-11-06 01:56:51 +01:00 committed by GitHub
parent 0194102de1
commit b2cad90fee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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.
@ -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