2018-04-07 01:23:03 +02:00
|
|
|
import voluptuous as vol
|
|
|
|
|
|
|
|
import esphomeyaml.config_validation as cv
|
|
|
|
from esphomeyaml.components import sensor
|
2018-05-20 12:41:52 +02:00
|
|
|
from esphomeyaml.const import CONF_HUMIDITY, CONF_MAKE_ID, CONF_MODEL, CONF_NAME, CONF_PIN, \
|
2018-04-07 01:23:03 +02:00
|
|
|
CONF_TEMPERATURE, CONF_UPDATE_INTERVAL
|
2018-05-20 12:41:52 +02:00
|
|
|
from esphomeyaml.helpers import App, Application, add, gpio_output_pin_expression, variable
|
2018-05-14 11:50:56 +02:00
|
|
|
from esphomeyaml.pins import GPIO_OUTPUT_PIN_SCHEMA
|
2018-04-07 01:23:03 +02:00
|
|
|
|
2018-05-14 11:50:56 +02:00
|
|
|
DHT_MODELS = {
|
2018-05-20 12:41:52 +02:00
|
|
|
'AUTO_DETECT': sensor.sensor_ns.DHT_MODEL_AUTO_DETECT,
|
|
|
|
'DHT11': sensor.sensor_ns.DHT_MODEL_DHT11,
|
|
|
|
'DHT22': sensor.sensor_ns.DHT_MODEL_DHT22,
|
|
|
|
'AM2302': sensor.sensor_ns.DHT_MODEL_AM2302,
|
|
|
|
'RHT03': sensor.sensor_ns.DHT_MODEL_RHT03,
|
2018-05-14 11:50:56 +02:00
|
|
|
}
|
2018-04-07 01:23:03 +02:00
|
|
|
|
2018-06-02 22:22:20 +02:00
|
|
|
MakeDHTSensor = Application.MakeDHTSensor
|
|
|
|
|
2018-04-07 01:23:03 +02:00
|
|
|
PLATFORM_SCHEMA = sensor.PLATFORM_SCHEMA.extend({
|
2018-06-02 22:22:20 +02:00
|
|
|
cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(MakeDHTSensor),
|
2018-05-14 11:50:56 +02:00
|
|
|
vol.Required(CONF_PIN): GPIO_OUTPUT_PIN_SCHEMA,
|
2018-05-20 12:41:52 +02:00
|
|
|
vol.Required(CONF_TEMPERATURE): sensor.SENSOR_SCHEMA,
|
|
|
|
vol.Required(CONF_HUMIDITY): sensor.SENSOR_SCHEMA,
|
|
|
|
vol.Optional(CONF_MODEL): vol.All(vol.Upper, cv.one_of(*DHT_MODELS)),
|
2018-05-14 11:50:56 +02:00
|
|
|
vol.Optional(CONF_UPDATE_INTERVAL): cv.positive_time_period_milliseconds,
|
2018-04-07 01:23:03 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
def to_code(config):
|
2018-06-02 22:22:20 +02:00
|
|
|
pin = None
|
|
|
|
for pin in gpio_output_pin_expression(config[CONF_PIN]):
|
|
|
|
yield
|
2018-04-18 18:43:13 +02:00
|
|
|
rhs = App.make_dht_sensor(config[CONF_TEMPERATURE][CONF_NAME],
|
|
|
|
config[CONF_HUMIDITY][CONF_NAME],
|
2018-05-14 11:50:56 +02:00
|
|
|
pin, config.get(CONF_UPDATE_INTERVAL))
|
2018-06-02 22:22:20 +02:00
|
|
|
dht = variable(config[CONF_MAKE_ID], rhs)
|
2018-04-07 01:23:03 +02:00
|
|
|
if CONF_MODEL in config:
|
2018-05-14 11:50:56 +02:00
|
|
|
constant = DHT_MODELS[config[CONF_MODEL]]
|
2018-05-20 12:41:52 +02:00
|
|
|
add(dht.Pdht.set_dht_model(constant))
|
|
|
|
|
2018-06-02 22:22:20 +02:00
|
|
|
for _ in sensor.setup_sensor(dht.Pdht.Pget_temperature_sensor(),
|
|
|
|
dht.Pmqtt_temperature, config[CONF_TEMPERATURE]):
|
|
|
|
yield
|
|
|
|
for _ in sensor.setup_sensor(dht.Pdht.Pget_humidity_sensor(),
|
|
|
|
dht.Pmqtt_humidity, config[CONF_HUMIDITY]):
|
|
|
|
yield
|
2018-04-18 18:43:13 +02:00
|
|
|
|
|
|
|
|
2018-05-06 15:56:12 +02:00
|
|
|
BUILD_FLAGS = '-DUSE_DHT_SENSOR'
|