MQTT Subscribe 文本传感器
mqtt_subscribe 文本传感器平台允许你将外部数据引入 ESPHome。
传感器将订阅给定 MQTT 主题上的消息,并将其最新值保存在
id(mysensor).state 中。
# 示例配置条目text_sensor: - platform: mqtt_subscribe name: "Data from topic" id: mysensor topic: the/topic- topic(必选,string):要监听字符串数据的 MQTT 主题。
- qos(可选,int):订阅时使用的 MQTT QoS。默认为
0。 - 来自 Text Sensor 的所有其他选项。
显示器的示例用法
Section titled “显示器的示例用法”此组件对显示器特别有用,可以在显示器上显示外部数据。
请注意,你需要在 .state 对象上使用 .c_str() 方法,并结合 %s 格式
在 printf 表达式中使用它。
# 示例配置条目text_sensor: - platform: mqtt_subscribe name: "Data from topic" id: mysensor topic: the/topic
display: - platform: ... # ... lambda: |- it.printf(0, 0, id(font), "The data is: %s", id(mysensor).state.c_str());