import voluptuous as vol from esphomeyaml.components import esp32_ble_tracker, sensor from esphomeyaml.components.esp32_ble_tracker import CONF_ESP32_BLE_ID, ESP32BLETracker, \ make_address_array import esphomeyaml.config_validation as cv from esphomeyaml.const import CONF_BATTERY_LEVEL, CONF_HUMIDITY, CONF_MAC_ADDRESS, CONF_MAKE_ID, \ CONF_NAME, CONF_TEMPERATURE from esphomeyaml.cpp_generator import get_variable, Pvariable DEPENDENCIES = ['esp32_ble_tracker'] PLATFORM_SCHEMA = sensor.PLATFORM_SCHEMA.extend({ cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(esp32_ble_tracker.XiaomiDevice), cv.GenerateID(CONF_ESP32_BLE_ID): cv.use_variable_id(ESP32BLETracker), vol.Required(CONF_MAC_ADDRESS): cv.mac_address, vol.Optional(CONF_TEMPERATURE): cv.nameable(esp32_ble_tracker.XIAOMI_SENSOR_SCHEMA), vol.Optional(CONF_HUMIDITY): cv.nameable(esp32_ble_tracker.XIAOMI_SENSOR_SCHEMA), vol.Optional(CONF_BATTERY_LEVEL): cv.nameable(esp32_ble_tracker.XIAOMI_SENSOR_SCHEMA), }) def to_code(config): for hub in get_variable(config[CONF_ESP32_BLE_ID]): yield
import esphomeyaml.config_validation as cv from esphomeyaml.components import sensor from esphomeyaml.const import CONF_MAKE_ID, CONF_NAME, CONF_UPDATE_INTERVAL, ESP_PLATFORM_ESP32 from esphomeyaml.cpp_generator import variable from esphomeyaml.cpp_helpers import setup_component from esphomeyaml.cpp_types import Application, App ESP_PLATFORMS = [ESP_PLATFORM_ESP32] MakeESP32TemperatureSensor = Application.struct('MakeESP32TemperatureSensor') ESP32TemperatureSensor = sensor.sensor_ns.class_('ESP32TemperatureSensor', sensor.PollingSensorComponent) PLATFORM_SCHEMA = cv.nameable(sensor.SENSOR_PLATFORM_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(ESP32TemperatureSensor), cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(MakeESP32TemperatureSensor), vol.Optional(CONF_UPDATE_INTERVAL): cv.update_interval, }).extend(cv.COMPONENT_SCHEMA.schema)) def to_code(config): rhs = App.make_esp32_temperature_sensor(config[CONF_NAME], config.get(CONF_UPDATE_INTERVAL)) make = variable(config[CONF_MAKE_ID], rhs) sensor.setup_sensor(make.Phall, make.Pmqtt, config) setup_component(make.Phall, config) BUILD_FLAGS = '-DUSE_ESP32_TEMPERATURE_SENSOR'
from esphomeyaml import pins from esphomeyaml.components import output import esphomeyaml.config_validation as cv from esphomeyaml.const import (CONF_BIT_DEPTH, CONF_CLOCK_PIN, CONF_DATA_PIN, CONF_ID, CONF_NUM_CHANNELS, CONF_NUM_CHIPS, CONF_UPDATE_ON_BOOT) from esphomeyaml.cpp_generator import Pvariable, add from esphomeyaml.cpp_helpers import gpio_output_pin_expression, setup_component from esphomeyaml.cpp_types import App, Component MY9231OutputComponent = output.output_ns.class_('MY9231OutputComponent', Component) MULTI_CONF = True CONFIG_SCHEMA = vol.Schema({ cv.GenerateID(): cv.declare_variable_id(MY9231OutputComponent), vol.Required(CONF_DATA_PIN): pins.gpio_output_pin_schema, vol.Required(CONF_CLOCK_PIN): pins.gpio_output_pin_schema, vol.Optional(CONF_NUM_CHANNELS): vol.All(vol.Coerce(int), vol.Range(3, 1020)), vol.Optional(CONF_NUM_CHIPS): vol.All(vol.Coerce(int), vol.Range(1, 255)), vol.Optional(CONF_BIT_DEPTH): cv.one_of(8, 12, 14, 16, int=True), vol.Optional(CONF_UPDATE_ON_BOOT): vol.Coerce(bool), }).extend(cv.COMPONENT_SCHEMA.schema)
import voluptuous as vol import esphomeyaml.config_validation as cv from esphomeyaml.const import CONF_ID, CONF_MQTT_ID, CONF_OSCILLATION_COMMAND_TOPIC, \ CONF_OSCILLATION_STATE_TOPIC, CONF_SPEED_COMMAND_TOPIC, CONF_SPEED_STATE_TOPIC from esphomeyaml.helpers import Application, Pvariable, add, esphomelib_ns, setup_mqtt_component PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({}) FAN_SCHEMA = cv.MQTT_COMMAND_COMPONENT_SCHEMA.extend({ cv.GenerateID('fan'): cv.register_variable_id, cv.GenerateID('mqtt_fan', CONF_MQTT_ID): cv.register_variable_id, vol.Optional(CONF_OSCILLATION_STATE_TOPIC): cv.publish_topic, vol.Optional(CONF_OSCILLATION_COMMAND_TOPIC): cv.subscribe_topic, }) fan_ns = esphomelib_ns.namespace('fan') FanState = fan_ns.FanState MQTTFanComponent = fan_ns.MQTTFanComponent MakeFan = Application.MakeFan TurnOnAction = fan_ns.TurnOnAction TurnOffAction = fan_ns.TurnOffAction ToggleAction = fan_ns.ToggleAction FanSpeed = fan_ns.FanSpeed FAN_SPEED_OFF = fan_ns.FAN_SPEED_OFF FAN_SPEED_LOW = fan_ns.FAN_SPEED_LOW FAN_SPEED_MEDIUM = fan_ns.FAN_SPEED_MEDIUM
import voluptuous as vol import esphomeyaml.config_validation as cv from esphomeyaml.components import sensor from esphomeyaml.const import CONF_MAKE_ID, CONF_NAME, CONF_UPDATE_INTERVAL, ESP_PLATFORM_ESP32 from esphomeyaml.helpers import App, Application, variable ESP_PLATFORMS = [ESP_PLATFORM_ESP32] MakeESP32HallSensor = Application.MakeESP32HallSensor PLATFORM_SCHEMA = sensor.PLATFORM_SCHEMA.extend({ cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(MakeESP32HallSensor), vol.Optional(CONF_UPDATE_INTERVAL): cv.positive_time_period_milliseconds, }).extend(sensor.SENSOR_SCHEMA.schema) def to_code(config): rhs = App.make_esp32_hall_sensor(config[CONF_NAME], config.get(CONF_UPDATE_INTERVAL)) make = variable(config[CONF_MAKE_ID], rhs) sensor.setup_sensor(make.Phall, make.Pmqtt, config) BUILD_FLAGS = '-DUSE_ESP32_HALL_SENSOR'
import esphomeyaml.config_validation as cv from esphomeyaml.components import output from esphomeyaml.const import CONF_ADDRESS, CONF_FREQUENCY, CONF_ID, CONF_PHASE_BALANCER from esphomeyaml.helpers import App, HexIntLiteral, Pvariable, add DEPENDENCIES = ['i2c'] PCA9685OutputComponent = output.output_ns.namespace('PCA9685OutputComponent') PHASE_BALANCER_MESSAGE = ( "The phase_balancer option has been removed in version 1.5.0. " "esphomelib will now automatically choose a suitable phase balancer.") PCA9685_SCHEMA = vol.Schema({ cv.GenerateID('pca9685'): cv.register_variable_id, vol.Required(CONF_FREQUENCY): vol.All(cv.frequency, vol.Range(min=23.84, max=1525.88)), vol.Optional(CONF_ADDRESS): cv.i2c_address, vol.Optional(CONF_PHASE_BALANCER): cv.invalid(PHASE_BALANCER_MESSAGE), }) CONFIG_SCHEMA = vol.All(cv.ensure_list, [PCA9685_SCHEMA]) def to_code(config): for conf in config: rhs = App.make_pca9685_component(conf.get(CONF_FREQUENCY))
import voluptuous as vol import esphomeyaml.config_validation as cv from esphomeyaml.components import sensor from esphomeyaml.const import CONF_ADDRESS, CONF_MAKE_ID, CONF_NAME, CONF_PRESSURE, \ CONF_TEMPERATURE, CONF_UPDATE_INTERVAL from esphomeyaml.helpers import App, HexIntLiteral, add, variable, Application DEPENDENCIES = ['i2c'] PLATFORM_SCHEMA = sensor.PLATFORM_SCHEMA.extend({ cv.GenerateID('bmp085_sensor', CONF_MAKE_ID): cv.register_variable_id, vol.Required(CONF_TEMPERATURE): sensor.SENSOR_SCHEMA, vol.Required(CONF_PRESSURE): sensor.SENSOR_SCHEMA, vol.Optional(CONF_ADDRESS): cv.i2c_address, vol.Optional(CONF_UPDATE_INTERVAL): cv.positive_time_period_milliseconds, }) MakeBMP085Sensor = Application.MakeBMP085Sensor def to_code(config): rhs = App.make_bmp085_sensor(config[CONF_TEMPERATURE][CONF_NAME], config[CONF_PRESSURE][CONF_NAME], config.get(CONF_UPDATE_INTERVAL)) bmp = variable(MakeBMP085Sensor, config[CONF_MAKE_ID], rhs)
import voluptuous as vol import esphomeyaml.config_validation as cv from esphomeyaml import pins from esphomeyaml.const import CONF_FREQUENCY, CONF_SCL, CONF_SDA, CONF_SCAN, CONF_ID, \ CONF_RECEIVE_TIMEOUT from esphomeyaml.helpers import App, add, Pvariable, esphomelib_ns CONFIG_SCHEMA = vol.Schema({ cv.GenerateID('i2c'): cv.register_variable_id, vol.Required(CONF_SDA, default='SDA'): pins.input_output_pin, vol.Required(CONF_SCL, default='SCL'): pins.input_output_pin, vol.Optional(CONF_FREQUENCY): cv.positive_int, vol.Optional(CONF_RECEIVE_TIMEOUT): cv.positive_time_period_milliseconds, vol.Optional(CONF_SCAN): cv.boolean, }) I2CComponent = esphomelib_ns.I2CComponent def to_code(config): rhs = App.init_i2c(config[CONF_SDA], config[CONF_SCL], config.get(CONF_SCAN)) i2c = Pvariable(I2CComponent, config[CONF_ID], rhs) if CONF_FREQUENCY in config: add(i2c.set_frequency(config[CONF_FREQUENCY])) if CONF_RECEIVE_TIMEOUT in config: add(i2c.set_receive_timeout(config[CONF_RECEIVE_TIMEOUT])) BUILD_FLAGS = '-DUSE_I2C'
import voluptuous as vol from esphomeyaml import pins from esphomeyaml.components import switch import esphomeyaml.config_validation as cv from esphomeyaml.const import CONF_MAKE_ID, CONF_NAME, CONF_PIN from esphomeyaml.helpers import App, Application, gpio_output_pin_expression, variable, \ setup_component, Component MakeGPIOSwitch = Application.struct('MakeGPIOSwitch') GPIOSwitch = switch.switch_ns.class_('GPIOSwitch', switch.Switch, Component) PLATFORM_SCHEMA = cv.nameable(switch.SWITCH_PLATFORM_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(GPIOSwitch), cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(MakeGPIOSwitch), vol.Required(CONF_PIN): pins.gpio_output_pin_schema, }).extend(cv.COMPONENT_SCHEMA.schema)) def to_code(config): for pin in gpio_output_pin_expression(config[CONF_PIN]): yield rhs = App.make_gpio_switch(config[CONF_NAME], pin) make = variable(config[CONF_MAKE_ID], rhs) gpio = make.Pswitch_ switch.setup_switch(gpio, make.Pmqtt, config) setup_component(gpio, config) BUILD_FLAGS = '-DUSE_GPIO_SWITCH'
return cv.one_of(*GAIN)(value) def validate_mux(value): value = cv.string(value).upper() value = value.replace(' ', '_') return cv.one_of(*MUX)(value) PLATFORM_SCHEMA = cv.nameable( sensor.SENSOR_PLATFORM_SCHEMA.extend({ vol.Required(CONF_MULTIPLEXER): validate_mux, vol.Required(CONF_GAIN): validate_gain, cv.GenerateID(CONF_ADS1115_ID): cv.use_variable_id(ADS1115Component), vol.Optional(CONF_UPDATE_INTERVAL): cv.positive_time_period_milliseconds, })) def to_code(config): hub = None for hub in get_variable(config[CONF_ADS1115_ID]): yield mux = MUX[config[CONF_MULTIPLEXER]] gain = GAIN[config[CONF_GAIN]] rhs = hub.get_sensor(config[CONF_NAME], mux, gain, config.get(CONF_UPDATE_INTERVAL))
import voluptuous as vol import esphomeyaml.config_validation as cv from esphomeyaml.components import sensor from esphomeyaml.const import CONF_ADDRESS, CONF_ID, CONF_RATE from esphomeyaml.helpers import App, Pvariable DEPENDENCIES = ['i2c'] ADS1115Component = sensor.sensor_ns.ADS1115Component RATE_REMOVE_MESSAGE = """The rate option has been removed in 1.5.0 and is no longer required.""" ADS1115_SCHEMA = vol.Schema({ cv.GenerateID('ads1115'): cv.register_variable_id, vol.Required(CONF_ADDRESS): cv.i2c_address, vol.Optional(CONF_RATE): cv.invalid(RATE_REMOVE_MESSAGE) }) CONFIG_SCHEMA = vol.All(cv.ensure_list, [ADS1115_SCHEMA]) def to_code(config): for conf in config: rhs = App.make_ads1115_component(conf[CONF_ADDRESS]) Pvariable(ADS1115Component, conf[CONF_ID], rhs)
}), vol.Optional(CONF_RAW): vol.Any(validate_raw_data, vol.Schema({ vol.Required(CONF_DATA): validate_raw_data, vol.Optional(CONF_CARRIER_FREQUENCY): vol.All(cv.frequency, vol.Coerce(int)), })), vol.Optional(CONF_RC_SWITCH_RAW): RC_SWITCH_RAW_SCHEMA, vol.Optional(CONF_RC_SWITCH_TYPE_A): RC_SWITCH_TYPE_A_SCHEMA, vol.Optional(CONF_RC_SWITCH_TYPE_B): RC_SWITCH_TYPE_B_SCHEMA, vol.Optional(CONF_RC_SWITCH_TYPE_C): RC_SWITCH_TYPE_C_SCHEMA, vol.Optional(CONF_RC_SWITCH_TYPE_D): RC_SWITCH_TYPE_D_SCHEMA, vol.Optional(CONF_REPEAT): vol.Any(cv.positive_not_null_int, vol.Schema({ vol.Required(CONF_TIMES): cv.positive_not_null_int, vol.Required(CONF_WAIT_TIME): cv.positive_time_period_microseconds, })), cv.GenerateID(CONF_REMOTE_TRANSMITTER_ID): cv.use_variable_id(RemoteTransmitterComponent), cv.GenerateID(CONF_TRANSMITTER_ID): cv.declare_variable_id(RemoteTransmitter), vol.Optional(CONF_INVERTED): cv.invalid("Remote Transmitters do not support inverted mode!"), }), cv.has_exactly_one_key(*REMOTE_KEYS)) def transmitter_base(full_config): name = full_config[CONF_NAME] key, config = next((k, v) for k, v in full_config.items() if k in REMOTE_KEYS) if key == CONF_LG: return LGTransmitter.new(name, config[CONF_DATA], config[CONF_NBITS]) elif key == CONF_NEC: return NECTransmitter.new(name, config[CONF_ADDRESS], config[CONF_COMMAND]) elif key == CONF_PANASONIC: return PanasonicTransmitter.new(name, config[CONF_ADDRESS], config[CONF_COMMAND])
import voluptuous as vol from esphomeyaml import core import esphomeyaml.config_validation as cv from esphomeyaml.const import CONF_CSS_URL, CONF_ID, CONF_JS_URL, CONF_PORT, ESP_PLATFORM_ESP32 from esphomeyaml.helpers import App, Component, Pvariable, StoringController, add, esphomelib_ns, \ setup_component WebServer = esphomelib_ns.class_('WebServer', Component, StoringController) CONFIG_SCHEMA = vol.Schema({ cv.GenerateID(): cv.declare_variable_id(WebServer), vol.Optional(CONF_PORT): cv.port, vol.Optional(CONF_CSS_URL): cv.string, vol.Optional(CONF_JS_URL): cv.string, }).extend(cv.COMPONENT_SCHEMA.schema) def to_code(config): rhs = App.init_web_server(config.get(CONF_PORT)) web_server = Pvariable(config[CONF_ID], rhs) if CONF_CSS_URL in config: add(web_server.set_css_url(config[CONF_CSS_URL])) if CONF_JS_URL in config: add(web_server.set_js_url(config[CONF_JS_URL])) setup_component(web_server, config) BUILD_FLAGS = '-DUSE_WEB_SERVER'
from esphomeyaml.helpers import App, ArrayInitializer, MockObj, Pvariable, RawExpression, add, \ relative_path _LOGGER = logging.getLogger(__name__) DEPENDENCIES = ['display'] Image_ = display.display_ns.class_('Image') CONF_RAW_DATA_ID = 'raw_data_id' IMAGE_SCHEMA = vol.Schema({ vol.Required(CONF_ID): cv.declare_variable_id(Image_), vol.Required(CONF_FILE): cv.file_, vol.Optional(CONF_RESIZE): cv.dimensions, cv.GenerateID(CONF_RAW_DATA_ID): cv.declare_variable_id(None), }) CONFIG_SCHEMA = vol.All(font.validate_pillow_installed, cv.ensure_list, [IMAGE_SCHEMA]) def to_code(config): from PIL import Image for conf in config: path = relative_path(conf[CONF_FILE]) try: image = Image.open(path) except Exception as e: raise core.ESPHomeYAMLError(u"Could not load image file {}: {}".format(path, e))
import esphomeyaml.config_validation as cv from esphomeyaml.components import output from esphomeyaml.components.pca9685 import PCA9685OutputComponent from esphomeyaml.const import CONF_CHANNEL, CONF_ID, CONF_PCA9685_ID, CONF_POWER_SUPPLY from esphomeyaml.helpers import Pvariable, get_variable DEPENDENCIES = ['pca9685'] Channel = PCA9685OutputComponent.Channel PLATFORM_SCHEMA = output.FLOAT_OUTPUT_PLATFORM_SCHEMA.extend({ vol.Required(CONF_ID): cv.declare_variable_id(Channel), vol.Required(CONF_CHANNEL): vol.All(vol.Coerce(int), vol.Range(min=0, max=15)), cv.GenerateID(CONF_PCA9685_ID): cv.use_variable_id(PCA9685OutputComponent), }) def to_code(config): power_supply = None if CONF_POWER_SUPPLY in config: for power_supply in get_variable(config[CONF_POWER_SUPPLY]): yield pca9685 = None for pca9685 in get_variable(config[CONF_PCA9685_ID]): yield rhs = pca9685.create_channel(config[CONF_CHANNEL], power_supply) out = Pvariable(config[CONF_ID], rhs) output.setup_output_platform(out, config, skip_power_supply=True)
import voluptuous as vol import esphomeyaml.config_validation as cv from esphomeyaml import automation from esphomeyaml.components import cover from esphomeyaml.const import CONF_CLOSE_ACTION, CONF_LAMBDA, CONF_MAKE_ID, CONF_NAME, \ CONF_OPEN_ACTION, CONF_STOP_ACTION, CONF_OPTIMISTIC from esphomeyaml.cpp_generator import variable, process_lambda, add from esphomeyaml.cpp_helpers import setup_component from esphomeyaml.cpp_types import Application, App, optional, NoArg MakeTemplateCover = Application.struct('MakeTemplateCover') TemplateCover = cover.cover_ns.class_('TemplateCover', cover.Cover) PLATFORM_SCHEMA = cv.nameable(cover.COVER_PLATFORM_SCHEMA.extend({ cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(MakeTemplateCover), cv.GenerateID(): cv.declare_variable_id(TemplateCover), vol.Optional(CONF_LAMBDA): cv.lambda_, vol.Optional(CONF_OPTIMISTIC): cv.boolean, vol.Optional(CONF_OPEN_ACTION): automation.validate_automation(single=True), vol.Optional(CONF_CLOSE_ACTION): automation.validate_automation(single=True), vol.Optional(CONF_STOP_ACTION): automation.validate_automation(single=True), }).extend(cv.COMPONENT_SCHEMA.schema), cv.has_at_least_one_key(CONF_LAMBDA, CONF_OPTIMISTIC)) def to_code(config): rhs = App.make_template_cover(config[CONF_NAME]) make = variable(config[CONF_MAKE_ID], rhs) cover.setup_cover(make.Ptemplate_, make.Pmqtt, config) setup_component(make.Ptemplate_, config)
import voluptuous as vol import esphomeyaml.config_validation as cv from esphomeyaml.components import binary_sensor, uart from esphomeyaml.const import CONF_ID, CONF_UART_ID from esphomeyaml.helpers import App, Pvariable, get_variable, setup_component, Component DEPENDENCIES = ['uart'] RDM6300Component = binary_sensor.binary_sensor_ns.class_( 'RDM6300Component', Component, uart.UARTDevice) CONFIG_SCHEMA = vol.All(cv.ensure_list_not_empty, [ vol.Schema({ cv.GenerateID(): cv.declare_variable_id(RDM6300Component), cv.GenerateID(CONF_UART_ID): cv.use_variable_id(uart.UARTComponent), }).extend(cv.COMPONENT_SCHEMA.schema) ]) def to_code(config): for conf in config: for uart_ in get_variable(conf[CONF_UART_ID]): yield rhs = App.make_rdm6300_component(uart_) var = Pvariable(conf[CONF_ID], rhs) setup_component(var, conf)
from esphomeyaml.helpers import App, Pvariable, add, esphomelib_ns, setup_mqtt_component, \ TemplateArguments, get_variable, Nameable, Action PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({}) switch_ns = esphomelib_ns.namespace('switch_') Switch = switch_ns.class_('Switch', Nameable) MQTTSwitchComponent = switch_ns.class_('MQTTSwitchComponent', mqtt.MQTTComponent) ToggleAction = switch_ns.class_('ToggleAction', Action) TurnOffAction = switch_ns.class_('TurnOffAction', Action) TurnOnAction = switch_ns.class_('TurnOnAction', Action) SWITCH_SCHEMA = cv.MQTT_COMMAND_COMPONENT_SCHEMA.extend({ cv.GenerateID(CONF_MQTT_ID): cv.declare_variable_id(MQTTSwitchComponent), vol.Optional(CONF_ICON): cv.icon, vol.Optional(CONF_INVERTED): cv.boolean, }) SWITCH_PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(SWITCH_SCHEMA.schema) def setup_switch_core_(switch_var, mqtt_var, config): if CONF_INTERNAL in config: add(switch_var.set_internal(config[CONF_INTERNAL])) if CONF_ICON in config: add(switch_var.set_icon(config[CONF_ICON]))
import voluptuous as vol import esphomeyaml.config_validation as cv from esphomeyaml.components import fan from esphomeyaml.const import CONF_MAKE_ID, CONF_NAME, CONF_OSCILLATION_OUTPUT, CONF_OUTPUT from esphomeyaml.helpers import App, add, get_variable, variable PLATFORM_SCHEMA = fan.PLATFORM_SCHEMA.extend({ cv.GenerateID('binary_fan', CONF_MAKE_ID): cv.register_variable_id, vol.Required(CONF_OUTPUT): cv.variable_id, vol.Optional(CONF_OSCILLATION_OUTPUT): cv.variable_id, }).extend(fan.FAN_SCHEMA.schema) def to_code(config): output = get_variable(config[CONF_OUTPUT]) rhs = App.make_fan(config[CONF_NAME]) fan_struct = variable(fan.MakeFan, config[CONF_MAKE_ID], rhs) add(fan_struct.Poutput.set_binary(output)) if CONF_OSCILLATION_OUTPUT in config: oscillation_output = get_variable(config[CONF_OSCILLATION_OUTPUT]) add(fan_struct.Poutput.set_oscillation(oscillation_output)) fan.setup_fan(fan_struct.Pstate, fan_struct.Pmqtt, config)
import voluptuous as vol import esphomeyaml.config_validation as cv from esphomeyaml.components import sensor from esphomeyaml.components.esp32_ble_tracker import CONF_ESP32_BLE_ID, ESP32BLETracker, \ make_address_array from esphomeyaml.const import CONF_BATTERY_LEVEL, CONF_HUMIDITY, CONF_MAC_ADDRESS, CONF_MAKE_ID, \ CONF_NAME, CONF_TEMPERATURE from esphomeyaml.helpers import Pvariable, esphomelib_ns, get_variable DEPENDENCIES = ['esp32_ble_tracker'] XiaomiDevice = esphomelib_ns.XiaomiDevice PLATFORM_SCHEMA = sensor.PLATFORM_SCHEMA.extend({ cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(XiaomiDevice), cv.GenerateID(CONF_ESP32_BLE_ID): cv.use_variable_id(ESP32BLETracker), vol.Required(CONF_MAC_ADDRESS): cv.mac_address, vol.Optional(CONF_TEMPERATURE): cv.nameable(sensor.SENSOR_SCHEMA), vol.Optional(CONF_HUMIDITY): cv.nameable(sensor.SENSOR_SCHEMA), vol.Optional(CONF_BATTERY_LEVEL): cv.nameable(sensor.SENSOR_SCHEMA), }) def to_code(config): hub = None for hub in get_variable(config[CONF_ESP32_BLE_ID]): yield rhs = hub.make_xiaomi_device(make_address_array(config[CONF_MAC_ADDRESS])) dev = Pvariable(config[CONF_MAKE_ID], rhs) if CONF_TEMPERATURE in config:
cv.positive_time_period_milliseconds, vol.Optional(CONF_DELTA): vol.Coerce(float), vol.Optional(CONF_UNIQUE): None, vol.Optional(CONF_HEARTBEAT): cv.positive_time_period_milliseconds, vol.Optional(CONF_DEBOUNCE): cv.positive_time_period_milliseconds, vol.Optional(CONF_OR): validate_recursive_filter, }, cv.has_at_exactly_one_key(*FILTER_KEYS)) ]) SENSOR_SCHEMA = cv.MQTT_COMPONENT_SCHEMA.extend({ cv.GenerateID('mqtt_sensor', CONF_MQTT_ID): cv.register_variable_id, cv.GenerateID('sensor'): cv.register_variable_id, vol.Required(CONF_NAME): cv.string, vol.Optional(CONF_UNIT_OF_MEASUREMENT): cv.string_strict, vol.Optional(CONF_ICON): cv.icon, vol.Optional(CONF_ACCURACY_DECIMALS): vol.Coerce(int), vol.Optional(CONF_EXPIRE_AFTER): vol.Any(None, cv.positive_time_period_milliseconds), vol.Optional(CONF_FILTERS): FILTERS_SCHEMA,
CONF_TEMPERATURE, \ CONF_UPDATE_INTERVAL from esphomeyaml.helpers import App, Pvariable DEPENDENCIES = ['i2c'] CONF_ACCEL_X = 'accel_x' CONF_ACCEL_Y = 'accel_y' CONF_ACCEL_Z = 'accel_z' CONF_GYRO_X = 'gyro_x' CONF_GYRO_Y = 'gyro_y' CONF_GYRO_Z = 'gyro_z' PLATFORM_SCHEMA = vol.All( sensor.PLATFORM_SCHEMA.extend({ cv.GenerateID('mpu6050', CONF_MAKE_ID): cv.register_variable_id, vol.Optional(CONF_ADDRESS, default=0x68): cv.i2c_address, vol.Optional(CONF_ACCEL_X): sensor.SENSOR_SCHEMA, vol.Optional(CONF_ACCEL_Y): sensor.SENSOR_SCHEMA, vol.Optional(CONF_ACCEL_Z): sensor.SENSOR_SCHEMA, vol.Optional(CONF_GYRO_X): sensor.SENSOR_SCHEMA, vol.Optional(CONF_GYRO_Y): sensor.SENSOR_SCHEMA, vol.Optional(CONF_GYRO_Z): sensor.SENSOR_SCHEMA,
try: import pytz return convert_tz(pytz.timezone(value)) except Exception: # pylint: disable=broad-except return value TIME_PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Optional(CONF_TIMEZONE, default=detect_tz): validate_tz, vol.Optional(CONF_ON_TIME): automation.validate_automation( { cv.GenerateID(CONF_TRIGGER_ID): cv.declare_variable_id(CronTrigger), vol.Optional(CONF_SECONDS): validate_cron_seconds, vol.Optional(CONF_MINUTES): validate_cron_minutes, vol.Optional(CONF_HOURS): validate_cron_hours, vol.Optional(CONF_DAYS_OF_MONTH): validate_cron_days_of_month, vol.Optional(CONF_MONTHS): validate_cron_months, vol.Optional(CONF_DAYS_OF_WEEK): validate_cron_days_of_week, vol.Optional(CONF_CRON): validate_cron_raw, }, validate_cron_keys), }) def setup_time_core_(time_var, config): add(time_var.set_timezone(config[CONF_TIMEZONE]))
import voluptuous as vol import esphomeyaml.config_validation as cv from esphomeyaml.const import CONF_ICON, CONF_ID, CONF_NAME, CONF_MQTT_ID from esphomeyaml.helpers import App, Pvariable, add, setup_mqtt_component PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({ }) MQTT_SWITCH_SCHEMA = cv.MQTT_COMMAND_COMPONENT_SCHEMA.extend({ vol.Optional(CONF_ICON): cv.icon, }) MQTT_SWITCH_ID_SCHEMA = MQTT_SWITCH_SCHEMA.extend({ cv.GenerateID('mqtt_switch', CONF_MQTT_ID): cv.register_variable_id, }) def setup_mqtt_switch(obj, config): setup_mqtt_component(obj, config) def setup_switch(obj, config): if CONF_ICON in config: add(obj.set_icon(config[CONF_ICON])) def register_switch(var, config): setup_switch(var, config) rhs = App.register_switch(var)
import voluptuous as vol import esphomeyaml.config_validation as cv from esphomeyaml import pins from esphomeyaml.const import CONF_CLK_PIN, CONF_ID, CONF_MISO_PIN, CONF_MOSI_PIN from esphomeyaml.helpers import App, Pvariable, esphomelib_ns, gpio_input_pin_expression, \ gpio_output_pin_expression, add SPIComponent = esphomelib_ns.SPIComponent SPI_SCHEMA = vol.All( vol.Schema({ cv.GenerateID(): cv.declare_variable_id(SPIComponent), vol.Required(CONF_CLK_PIN): pins.gpio_output_pin_schema, vol.Optional(CONF_MISO_PIN): pins.gpio_input_pin_schema, vol.Optional(CONF_MOSI_PIN): pins.gpio_output_pin_schema, }), cv.has_at_least_one_key(CONF_MISO_PIN, CONF_MOSI_PIN)) CONFIG_SCHEMA = vol.All(cv.ensure_list, [SPI_SCHEMA]) def to_code(config): for conf in config: clk = None for clk in gpio_output_pin_expression(conf[CONF_CLK_PIN]): yield rhs = App.init_spi(clk) spi = Pvariable(conf[CONF_ID], rhs) if CONF_MISO_PIN in conf: for miso in gpio_input_pin_expression(conf[CONF_MISO_PIN]): yield
import voluptuous as vol import esphomeyaml.config_validation as cv from esphomeyaml.const import CONF_ADDRESS, CONF_FREQUENCY, CONF_ID, CONF_PHASE_BALANCER from esphomeyaml.helpers import App, HexIntLiteral, Pvariable, RawExpression, add DEPENDENCIES = ['i2c'] PHASE_BALANCERS = ['None', 'Linear', 'Weaved'] PCA9685_COMPONENT_TYPE = 'output::PCA9685OutputComponent' PCA9685_SCHEMA = vol.Schema({ cv.GenerateID('pca9685'): cv.register_variable_id, vol.Required(CONF_FREQUENCY): vol.All(cv.frequency, vol.Range(min=24, max=1526)), vol.Optional(CONF_PHASE_BALANCER): vol.All(vol.Title, vol.Any(*PHASE_BALANCERS)), vol.Optional(CONF_ADDRESS): cv.i2c_address, }) CONFIG_SCHEMA = vol.All(cv.ensure_list, [PCA9685_SCHEMA]) def to_code(config): for conf in config: rhs = App.make_pca9685_component(conf.get(CONF_FREQUENCY)) pca9685 = Pvariable(PCA9685_COMPONENT_TYPE, conf[CONF_ID], rhs) if CONF_ADDRESS in conf: add(pca9685.set_address(HexIntLiteral(conf[CONF_ADDRESS]))) if CONF_PHASE_BALANCER in conf: phase_balancer = RawExpression(u'PCA9685_PhaseBalancer_{}'.format(
IIR_FILTER_OPTIONS = { 'OFF': sensor.sensor_ns.BME280_IIR_FILTER_OFF, '2X': sensor.sensor_ns.BME280_IIR_FILTER_2X, '4X': sensor.sensor_ns.BME280_IIR_FILTER_4X, '8X': sensor.sensor_ns.BME280_IIR_FILTER_8X, '16X': sensor.sensor_ns.BME280_IIR_FILTER_16X, } BME280_OVERSAMPLING_SENSOR_SCHEMA = sensor.SENSOR_SCHEMA.extend({ vol.Optional(CONF_OVERSAMPLING): vol.All(vol.Upper, cv.one_of(*OVERSAMPLING_OPTIONS)), }) MakeBME280Sensor = Application.MakeBME280Sensor PLATFORM_SCHEMA = sensor.PLATFORM_SCHEMA.extend({ cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(MakeBME280Sensor), vol.Optional(CONF_ADDRESS, default=0x77): cv.i2c_address, vol.Required(CONF_TEMPERATURE): BME280_OVERSAMPLING_SENSOR_SCHEMA, vol.Required(CONF_PRESSURE): BME280_OVERSAMPLING_SENSOR_SCHEMA, vol.Required(CONF_HUMIDITY): BME280_OVERSAMPLING_SENSOR_SCHEMA, vol.Optional(CONF_IIR_FILTER): vol.All(vol.Upper, cv.one_of(*IIR_FILTER_OPTIONS)), vol.Optional(CONF_UPDATE_INTERVAL): cv.positive_time_period_milliseconds, }) def to_code(config): rhs = App.make_bme280_sensor(config[CONF_TEMPERATURE][CONF_NAME], config[CONF_PRESSURE][CONF_NAME], config[CONF_HUMIDITY][CONF_NAME], config[CONF_ADDRESS], config.get(CONF_UPDATE_INTERVAL))
import voluptuous as vol import esphomeyaml.config_validation as cv from esphomeyaml.components import light from esphomeyaml.const import CONF_DEFAULT_TRANSITION_LENGTH, CONF_GAMMA_CORRECT, CONF_MAKE_ID, \ CONF_NAME, CONF_OUTPUT from esphomeyaml.helpers import App, get_variable, variable PLATFORM_SCHEMA = cv.nameable(light.LIGHT_PLATFORM_SCHEMA.extend({ cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(light.MakeLight), vol.Required(CONF_OUTPUT): cv.use_variable_id(None), vol.Optional(CONF_GAMMA_CORRECT): cv.positive_float, vol.Optional(CONF_DEFAULT_TRANSITION_LENGTH): cv.positive_time_period_milliseconds, })) def to_code(config): output = None for output in get_variable(config[CONF_OUTPUT]): yield rhs = App.make_monochromatic_light(config[CONF_NAME], output) light_struct = variable(config[CONF_MAKE_ID], rhs) light.setup_light(light_struct.Pstate, light_struct.Pmqtt, config)
import voluptuous as vol import esphomeyaml.config_validation as cv from esphomeyaml import pins from esphomeyaml.components import sensor from esphomeyaml.const import CONF_MAKE_ID, CONF_NAME, CONF_PIN, CONF_UPDATE_INTERVAL from esphomeyaml.helpers import App, Application, gpio_input_pin_expression, variable MakeDutyCycleSensor = Application.MakeDutyCycleSensor PLATFORM_SCHEMA = cv.nameable( sensor.SENSOR_PLATFORM_SCHEMA.extend({ cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(MakeDutyCycleSensor), vol.Required(CONF_PIN): pins.internal_gpio_input_pin_schema, vol.Optional(CONF_UPDATE_INTERVAL): cv.update_interval, })) def to_code(config): pin = None for pin in gpio_input_pin_expression(config[CONF_PIN]): yield rhs = App.make_duty_cycle_sensor(config[CONF_NAME], pin, config.get(CONF_UPDATE_INTERVAL)) make = variable(config[CONF_MAKE_ID], rhs) sensor.setup_sensor(make.Pduty, make.Pmqtt, config)
from esphomeyaml.components import output from esphomeyaml.components.pca9685 import PCA9685OutputComponent import esphomeyaml.config_validation as cv from esphomeyaml.const import CONF_CHANNEL, CONF_ID, CONF_PCA9685_ID, CONF_POWER_SUPPLY from esphomeyaml.cpp_generator import Pvariable, get_variable DEPENDENCIES = ['pca9685'] Channel = PCA9685OutputComponent.class_('Channel', output.FloatOutput) PLATFORM_SCHEMA = output.FLOAT_OUTPUT_PLATFORM_SCHEMA.extend({ vol.Required(CONF_ID): cv.declare_variable_id(Channel), vol.Required(CONF_CHANNEL): vol.All(vol.Coerce(int), vol.Range(min=0, max=15)), cv.GenerateID(CONF_PCA9685_ID): cv.use_variable_id(PCA9685OutputComponent), }) def to_code(config): power_supply = None if CONF_POWER_SUPPLY in config: for power_supply in get_variable(config[CONF_POWER_SUPPLY]): yield for pca9685 in get_variable(config[CONF_PCA9685_ID]): yield rhs = pca9685.create_channel(config[CONF_CHANNEL], power_supply) out = Pvariable(config[CONF_ID], rhs) output.setup_output_platform(out, config, skip_power_supply=True)