Add MQTT Subscribe sensor (#175)

This commit is contained in:
Otto Winter 2018-10-14 18:45:13 +02:00 committed by GitHub
parent 6a24145be6
commit 6f54afec00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 2 deletions

View 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'

View File

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