mirror of
https://github.com/esphome/esphome.git
synced 2024-11-29 12:55:46 +01:00
Add MQTT Subscribe sensor (#175)
This commit is contained in:
parent
6a24145be6
commit
6f54afec00
29
esphomeyaml/components/sensor/mqtt_subscribe.py
Normal file
29
esphomeyaml/components/sensor/mqtt_subscribe.py
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
import voluptuous as vol
|
||||||
|
|
||||||
|
from esphomeyaml.components import sensor
|
||||||
|
import esphomeyaml.config_validation as cv
|
||||||
|
from esphomeyaml.const import CONF_MAKE_ID, CONF_NAME, CONF_QOS, CONF_TOPIC
|
||||||
|
from esphomeyaml.helpers import App, Application, add, variable
|
||||||
|
|
||||||
|
DEPENDENCIES = ['mqtt']
|
||||||
|
|
||||||
|
MakeMQTTSubscribeSensor = Application.MakeMQTTSubscribeSensor
|
||||||
|
|
||||||
|
PLATFORM_SCHEMA = cv.nameable(sensor.SENSOR_PLATFORM_SCHEMA.extend({
|
||||||
|
cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(MakeMQTTSubscribeSensor),
|
||||||
|
vol.Required(CONF_TOPIC): cv.subscribe_topic,
|
||||||
|
vol.Optional(CONF_QOS): cv.mqtt_qos,
|
||||||
|
}))
|
||||||
|
|
||||||
|
|
||||||
|
def to_code(config):
|
||||||
|
rhs = App.make_mqtt_subscribe_sensor(config[CONF_NAME], config[CONF_TOPIC])
|
||||||
|
make = variable(config[CONF_MAKE_ID], rhs)
|
||||||
|
|
||||||
|
if CONF_QOS in config:
|
||||||
|
add(make.Psensor.set_qos(config[CONF_QOS]))
|
||||||
|
|
||||||
|
sensor.setup_sensor(make.Psensor, make.Pmqtt, config)
|
||||||
|
|
||||||
|
|
||||||
|
BUILD_FLAGS = '-DUSE_MQTT_SUBSCRIBE_SENSOR'
|
@ -1,5 +1,5 @@
|
|||||||
esphomeyaml:
|
esphomeyaml:
|
||||||
name: test1
|
name: test2
|
||||||
platform: ESP32
|
platform: ESP32
|
||||||
board: nodemcu-32s
|
board: nodemcu-32s
|
||||||
# Use latest upstream esphomelib git version.
|
# Use latest upstream esphomelib git version.
|
||||||
@ -73,7 +73,10 @@ sensor:
|
|||||||
name: "Xiaomi MiJia Humidity"
|
name: "Xiaomi MiJia Humidity"
|
||||||
battery_level:
|
battery_level:
|
||||||
name: "Xiaomi MiJia Battery Level"
|
name: "Xiaomi MiJia Battery Level"
|
||||||
|
- platform: mqtt_subscribe
|
||||||
|
name: "MQTT Subscribe Sensor 1"
|
||||||
|
topic: "mqtt/topic"
|
||||||
|
qos: 2
|
||||||
|
|
||||||
esp32_touch:
|
esp32_touch:
|
||||||
setup_mode: True
|
setup_mode: True
|
||||||
|
Loading…
Reference in New Issue
Block a user