2018-10-17 20:44:37 +02:00
|
|
|
MQTT Subscribe Text Sensor
|
|
|
|
==========================
|
|
|
|
|
2018-11-14 22:12:27 +01:00
|
|
|
.. seo::
|
|
|
|
:description: Instructions for setting up MQTT Subscribe text sensors that show the content of a MQTT message as their state.
|
|
|
|
:image: mqtt.png
|
|
|
|
:keywords: MQTT
|
|
|
|
|
2019-02-16 23:25:23 +01:00
|
|
|
The ``mqtt_subscribe`` text sensor platform allows you to get external data into ESPHome.
|
2018-10-17 20:44:37 +02:00
|
|
|
The sensor will subscribe to messages on the given MQTT topic and save the most recent value
|
2019-01-13 15:49:06 +01:00
|
|
|
in its ``id(mysensor).state``.
|
2018-10-17 20:44:37 +02:00
|
|
|
|
2018-11-19 18:32:16 +01:00
|
|
|
.. code-block:: yaml
|
2018-10-17 20:44:37 +02:00
|
|
|
|
|
|
|
# Example configuration entry
|
|
|
|
text_sensor:
|
|
|
|
- platform: mqtt_subscribe
|
|
|
|
name: "Data from topic"
|
|
|
|
id: mysensor
|
|
|
|
topic: the/topic
|
|
|
|
|
|
|
|
Configuration variables:
|
|
|
|
------------------------
|
|
|
|
|
|
|
|
- **name** (**Required**, string): The name of the text sensor.
|
2022-06-21 05:57:56 +02:00
|
|
|
- **topic** (**Required**, string): The MQTT topic to listen for string data.
|
2018-10-17 20:44:37 +02:00
|
|
|
- **qos** (*Optional*, int): The MQTT QoS to subscribe with. Defaults to ``0``.
|
|
|
|
- **id** (*Optional*, :ref:`config-id`): Manually specify the ID used for code generation.
|
2019-02-17 12:28:17 +01:00
|
|
|
- All other options from :ref:`Text Sensor <config-text_sensor>`.
|
2018-10-17 20:44:37 +02:00
|
|
|
|
|
|
|
Example Usage for Displays
|
|
|
|
--------------------------
|
|
|
|
|
|
|
|
This integration is especially useful for displays, to show external data on the display.
|
2018-10-26 22:27:01 +02:00
|
|
|
Please note you have to use the ``.c_str()`` method on the ``.state`` object together with the ``%s`` format
|
2018-10-17 20:44:37 +02:00
|
|
|
to use it in ``printf`` expressions.
|
|
|
|
|
2018-11-19 18:32:16 +01:00
|
|
|
.. code-block:: yaml
|
2018-10-17 20:44:37 +02:00
|
|
|
|
|
|
|
# Example configuration entry
|
|
|
|
text_sensor:
|
|
|
|
- platform: mqtt_subscribe
|
|
|
|
name: "Data from topic"
|
|
|
|
id: mysensor
|
|
|
|
topic: the/topic
|
|
|
|
|
|
|
|
display:
|
|
|
|
- platform: ...
|
|
|
|
# ...
|
|
|
|
lambda: |-
|
2018-10-26 22:27:01 +02:00
|
|
|
it.printf(0, 0, id(font), "The data is: %s", id(mysensor).state.c_str());
|
2018-10-17 20:44:37 +02:00
|
|
|
|
|
|
|
See Also
|
|
|
|
--------
|
|
|
|
|
2019-05-12 22:44:59 +02:00
|
|
|
- :apiref:`mqtt_subscribe/text_sensor/mqtt_subscribe_text_sensor.h`
|
2019-02-07 13:54:45 +01:00
|
|
|
- :ghedit:`Edit`
|