Application

The Application class has two objectives: 1. handle all of your Component s and 2. provide helper methods to simplify creating a component.

In itself, an Application instance doesn’t do and store very much. It mostly only keeps track of all Components (using an internal std::vector() containing pointers), so that when the user calls the setup() or loop() methods, it can relay those calls to the components.

In order for the Application to know about your components, each one of them should be registered using the register_component() call. And for subclasses of MQTTComponent, register_mqtt_component() shall be used.

Apart from the helpers, only one function is really necessary for setting up the Application instance: set_name(). The name provided by this is used throughout the code base to construct various strings such as MQTT topics or WiFi hostnames. Additionally, some one-time-setup components such as MQTT or WiFi can be initialized with the init_ calls. Next, this class provides a bunch of helper methods to create and register components easily using the make_ calls.

Each component can tell the Application with which priority it wishes to be called using the get_loop_priority() and get_setup_priority() overrides. The Application will then automatically order the components before execution.

API Reference

class Application

This is the class that combines all components.

Public Functions

void set_name(const std::string &name)

Set the name of the item that is running this app.

Note: This will automatically be converted to lowercase_underscore.

Parameters
  • name: The name of your app.

LogComponent *init_log(uint32_t baud_rate = 115200, size_t tx_buffer_size = 512)

Initialize the logging engine.

Return
The created and initialized LogComponent.
Parameters
  • baud_rate: The serial baud rate. Set to 0 to disable UART debugging.
  • tx_buffer_size: The size of the printf buffer.

WiFiComponent *init_wifi(const std::string &ssid, const std::string &password = "")

Initialize the WiFi engine in client mode.

Note: for advanced options, such as manual ip, use the return value.

Return
The WiFiComponent.
Parameters
  • ssid: The ssid of the network you want to connect to.
  • password: The password of your network. Leave empty for no password

WiFiComponent *init_wifi()

Initialize the WiFi engine with no initial mode. Use this if you just want an Access Point.

OTAComponent *init_ota()

Initialize Over-the-Air updates.

Return
The OTAComponent. Use this to set advanced settings.

MQTTClientComponent *init_mqtt(const std::string &address, uint16_t port, const std::string &username, const std::string &password)

Initialize the MQTT client.

Return
The MQTTClient. Use this to set advanced settings.
Parameters
  • address: The address of your server.
  • port: The port of your server.
  • username: The username.
  • password: The password. Empty for no password.

MQTTClientComponent *init_mqtt(const std::string &address, const std::string &username, const std::string &password)

Initialize the MQTT client.

Return
The MQTTClient. Use this to set advanced settings.
Parameters
  • address: The address of your server.
  • username: The username.
  • password: The password. Empty for no password.

I2CComponent *init_i2c(uint8_t sda_pin = SDA, uint8_t scl_pin = SCL, bool scan = false)

Initialize the i2c bus on the provided SDA and SCL pins for use with other components.

SDA/SCL pins default to the values defined by the Arduino framework and are usually GPIO4 and GPIO5 on the ESP8266 (D2 and D1 on NodeMCU). And for the ESP32 it defaults to GPIO21 and GPIO22 for SDA and SCL, respectively.

Parameters
  • sda_pin: The SDA pin the i2c bus is connected to.
  • scl_pin: The SCL pin the i2c bus is connected to.
  • scan: If a scan of connected i2c devices should be done at startup.

UARTComponent *init_uart(int8_t tx_pin, int8_t rx_pin, uint32_t baud_rate = 9600)
SPIComponent *init_spi(const GPIOOutputPin &clk, const GPIOInputPin &miso, const GPIOOutputPin &mosi)
SPIComponent *init_spi(const GPIOOutputPin &clk)
WebServer *init_web_server(uint16_t port = 80)

Initialize the web server.

Note that this will take up quite a bit of flash space and RAM of the node. Especially on ESP8266 boards this can quickly cause memory problems.

Return
The WebServer object, use this for advanced settings.
Parameters
  • port: The port of the web server, defaults to 80.

ESP32BLETracker *make_esp32_ble_tracker()

Setup an ESP32 BLE Tracker Hub.

Only one of these should be created. Individual sensors can be created using make_device() on the return value.

Note that this component is currently not completely stable (probably due to some issues in the esp-idf core that are being worked on). Enabling this integration will increase the created binary size by up to 500kB, can cause seemingly random reboots/resets and only can discover a small number of devices at the moment.

Return
An ESP32BLETracker instance, use this to create individual trackers as binary sensors.

ESP32BLEBeacon *make_esp32_ble_beacon(const std::array<uint8_t, 16> &uuid)
StatusLEDComponent *make_status_led(const GPIOOutputPin &pin)
display::Font *make_font(std::vector<display::Glyph> &&glyphs, int baseline, int bottom)
display::Image *make_image(const uint8_t *data_start, int width, int height)
display::MAX7219Component *make_max7219(SPIComponent *parent, const GPIOOutputPin &cs, uint32_t update_interval = 1000)
display::PCF8574LCDDisplay *make_pcf8574_lcd_display(uint8_t columns, uint8_t rows, uint8_t address = 0x3F, uint32_t update_interval = 1000)
display::GPIOLCDDisplay *make_gpio_lcd_display(uint8_t columns, uint8_t rows, uint32_t update_interval = 1000)
display::SPISSD1306 *make_spi_ssd1306(SPIComponent *parent, const GPIOOutputPin &cs, const GPIOOutputPin &dc, uint32_t update_interval = 5000)
display::I2CSSD1306 *make_i2c_ssd1306(uint32_t update_interval = 5000)
display::WaveshareEPaperTypeA *make_waveshare_epaper_type_a(SPIComponent *parent, const GPIOOutputPin &cs, const GPIOOutputPin &dc_pin, display::WaveshareEPaperTypeAModel model, uint32_t update_interval = 10000)
display::WaveshareEPaper *make_waveshare_epaper_type_b(SPIComponent *parent, const GPIOOutputPin &cs, const GPIOOutputPin &dc_pin, display::WaveshareEPaperTypeBModel model, uint32_t update_interval = 10000)
display::Nextion *make_nextion(UARTComponent *parent, uint32_t update_interval = 5000)
template <typename T>
GlobalVariableComponent<T> *make_global_variable()
template <typename T>
GlobalVariableComponent<T> *make_global_variable(T initial_value)
template <typename T>
Automation<T> *make_automation(Trigger<T> *trigger)
mqtt::MQTTMessageTrigger *make_mqtt_message_trigger(const std::string &topic, uint8_t qos = 0)
StartupTrigger *make_startup_trigger()
ShutdownTrigger *make_shutdown_trigger()
MQTTBinarySensorComponent *register_binary_sensor(binary_sensor::BinarySensor *binary_sensor)

Register a binary sensor and set it up for the front-end.

Application::MakeGPIOBinarySensor make_gpio_binary_sensor(const std::string &friendly_name, const GPIOInputPin &pin, const std::string &device_class = "")

Create a simple GPIO binary sensor.

Note: advanced options such as inverted input are available in the return value.

Parameters
  • friendly_name: The friendly name that should be advertised. Leave empty for no automatic discovery.
  • pin: The GPIO pin.
  • device_class: The Home Assistant device_class.

Application::MakeStatusBinarySensor make_status_binary_sensor(const std::string &friendly_name)

Create a simple binary sensor that reports the online/offline state of the node.

Uses the MQTT last will and birth message feature. If the values for these features are custom, you need to override them using the return value of this function.

Return
A MQTTBinarySensorComponent. Use this to set custom status messages.
Parameters
  • friendly_name: The friendly name advertised via MQTT discovery.

ESP32TouchComponent *make_esp32_touch_component()

Setup an ESP32TouchComponent to detect touches on certain pins of the ESP32 using the built-in touch peripheral.

First set up the global hub using this method. Then create individual binary sensors using the make_touch_pad function on the return type.

Return
The new ESP32TouchComponent. Use this to create the binary sensors.

Application::MakeTemplateBinarySensor make_template_binary_sensor(const std::string &name)
remote::RemoteReceiverComponent *make_remote_receiver_component(const GPIOInputPin &output)
PN532Component *make_pn532_component(SPIComponent *parent, const GPIOOutputPin &cs, uint32_t update_interval = 1000)
binary_sensor::RDM6300Component *make_rdm6300_component(UARTComponent *parent)
sensor::MQTTSensorComponent *register_sensor(sensor::Sensor *sensor)

Register a sensor and create a MQTT Sensor if the MQTT client is set up.

text_sensor::MQTTTextSensor *register_text_sensor(text_sensor::TextSensor *sensor)

Register a text sensor and create a MQTT Sensor if the MQTT client is set up.

Application::MakeDHTSensor make_dht_sensor(const std::string &temperature_friendly_name, const std::string &humidity_friendly_name, const GPIOOutputPin &pin, uint32_t update_interval = 15000)

Create a DHT sensor component.

Note: This method automatically applies a SlidingWindowMovingAverageFilter.

Return
The components. Use this for advanced settings.
Parameters
  • temperature_friendly_name: The name the temperature sensor should be advertised as. Leave empty for no automatic discovery.
  • humidity_friendly_name: The name the humidity sensor should be advertised as. Leave empty for no automatic discovery.
  • pin: The pin the DHT sensor is connected to.
  • update_interval: The interval (in ms) the sensor should be checked.

DallasComponent *make_dallas_component(ESPOneWire *one_wire, uint32_t update_interval = 15000)
DallasComponent *make_dallas_component(const GPIOOutputPin &pin, uint32_t update_interval = 15000)
Application::MakePulseCounterSensor make_pulse_counter_sensor(const std::string &friendly_name, const GPIOInputPin &pin, uint32_t update_interval = 15000)

Create an ESP32 Pulse Counter component.

The pulse counter peripheral will automatically all pulses on pin in the background. Every check_interval ms the amount of pulses will be retrieved and the difference to the last value will be reported via MQTT as a sensor.

Return
The components. Use this for advanced settings.
Parameters
  • pin: The pin the pulse counter should count pulses on.
  • friendly_name: The name the sensor should be advertised as.
  • update_interval: The interval in ms the sensor should be checked.

Application::MakeADCSensor make_adc_sensor(const std::string &friendly_name, uint8_t pin, uint32_t update_interval = 15000)

Create an ADC Sensor component.

Every check_interval ms, the value from the specified pin (only A0 on ESP8266, 32-39 for ESP32), and converts it into the volt unit. On the ESP32 you can additionally specify a channel attenuation using the return value of this function. pinMode can also be set using the return value.

Return
The components. Use this for advanced settings.
Parameters
  • pin: The pin the ADC should sense on.
  • friendly_name: The name the sensor should be advertised as.
  • update_interval: The interval in ms the sensor should be checked.

ADS1115Component *make_ads1115_component(uint8_t address)

Create an ADS1115 component hub.

From this hub you can then create individual sensors using get_sensor().

Note that you should have i2c setup for this component to work. To setup i2c call App.init_i2c(SDA_PIN, SCL_PIN); before App.setup().

Return
The ADS1115Component hub. Use this to set advanced setting and create the actual sensors.
Parameters
  • address: The i2c address of the ADS1115. See ADS1115Component::set_address for possible values.

Application::MakeBMP085Sensor make_bmp085_sensor(const std::string &temperature_friendly_name, const std::string &pressure_friendly_name, uint32_t update_interval = 15000)

Create an BMP085/BMP180/BMP280 i2c temperature+pressure sensor.

Be sure to initialize i2c before calling App.setup() in order for this to work. Do so with App.init_i2c(SDA_PIN, SCL_PIN);.

Return
A MakeBMP085Component object, use this to set advanced settings.
Parameters
  • temperature_friendly_name: The friendly name the temperature should be advertised as.
  • pressure_friendly_name: The friendly name the pressure should be advertised as.
  • update_interval: The interval in ms to update the sensor values.

Application::MakeHTU21DSensor make_htu21d_sensor(const std::string &temperature_friendly_name, const std::string &humidity_friendly_name, uint32_t update_interval = 15000)

Create a HTU21D i2c-based temperature+humidity highly accurate sensor.

Be sure to initialize i2c before calling App.setup in order for this to work. Do so with App.init_i2c(SDA_PIN, SCL_PIN);.

Return
A MakeHTU21DSensor, use this to set advanced settings.
Parameters
  • temperature_friendly_name: The friendly name the temperature sensor should be advertised as.
  • humidity_friendly_name: The friendly name the humidity sensor should be advertised as.
  • update_interval: The interval in ms to update the sensor values.

Application::MakeHDC1080Sensor make_hdc1080_sensor(const std::string &temperature_friendly_name, const std::string &humidity_friendly_name, uint32_t update_interval = 15000)

Create a HDC1080 i2c-based temperature+humidity sensor.

Be sure to initialize i2c before calling App.setup in order for this to work. Do so with App.init_i2c(SDA_PIN, SCL_PIN);.

Return
A MakeHDC1080Sensor, use this to set advanced settings.
Parameters
  • temperature_friendly_name: The friendly name the temperature sensor should be advertised as.
  • humidity_friendly_name: The friendly name the humidity sensor should be advertised as.
  • update_interval: The interval in ms to update the sensor values.

Application::MakeUltrasonicSensor make_ultrasonic_sensor(const std::string &friendly_name, const GPIOOutputPin &trigger_pin, const GPIOInputPin &echo_pin, uint32_t update_interval = 5000)

Create an Ultrasonic range sensor.

This can for example be an HC-SR04 ultrasonic sensor. It sends out a short ultrasonic wave and listens for an echo. The time between the sending and receiving is then (with some maths) converted to a measurement in meters. You need to specify the trigger pin (where to short pulse will be sent to) and the echo pin (where we’re waiting for the echo). Note that in order to not block indefinitely if we don’t receive an echo, this class has a default timeout of around 2m. You can change that using the return value of this function.

Return
The Ultrasonic sensor + MQTT sensor pair, use this for advanced settings.
Parameters
  • friendly_name: The friendly name for this sensor advertised to Home Assistant.
  • trigger_pin: The pin the short pulse will be sent to, can be integer or GPIOOutputPin.
  • echo_pin: The pin we wait that we wait on for the echo, can be integer or GPIOInputPin.
  • update_interval: The time in ms between updates, defaults to 5 seconds.

Application::MakeWiFiSignalSensor make_wifi_signal_sensor(const std::string &name, uint32_t update_interval = 15000)
sensor::MPU6050Component * Application::make_mpu6050_sensor(uint8_t address = 0x68, uint32_t update_interval = 15000)

Create a MPU6050 Accelerometer+Gyroscope+Temperature sensor hub.

This integration can be used to get accurate accelerometer readings and uncalibrated gyroscope values (in degrees per second). If you need the latter with calibration applied, your best bet it to just copy the source and do it yourself, as calibration must be performed while the sensor is at rest and this property can not be asserted for all use cases.

Return
An MPU6050Component, use this to create the individual sensors and register them with register_sensor.
Parameters
  • address: The address of the device, defaults to 0x68.
  • update_interval: The interval in ms to update the sensor values.

Application::MakeTSL2561Sensor make_tsl2561_sensor(const std::string &name, uint8_t address = 0x23, uint32_t update_interval = 15000)

Create a TSL2561 accurate ambient light sensor.

This i2c-based device can provide very precise illuminance readings with great accuracy regarding the human eye response to the brightness level. By default, this sensor uses the i2c address 0x39, but you can change it with set_address later using the return value of this function (address 0x29 if ‘0’ shorted on board, address 0x49 if ‘1’ shorted on board).

The sensor values that are pushed out will be the transformed illuminance values in lx taking using the internal IR and Full Spectrum photodiodes.

Additionally, you can specify the time the sensor takes for accumulating the values (higher is better for lower light conditions, defaults to 402ms - the max) and a gain that should be used for the ADCs (defaults to 1x). Finally, this integration is energy efficient and only turns on the sensor when the values are read out.

Return
The TSL2561Sensor + MQTT sensor pair, use this for advanced settings.
Parameters
  • name: The friendly name how the sensor should be advertised.
  • address: The address of this i2c device.
  • update_interval: The interval in ms to update the sensor values.

Application::MakeBH1750Sensor make_bh1750_sensor(const std::string &name, uint8_t address = 0x23, uint32_t update_interval = 15000)

Create a BH1750 ambient light sensor.

This i2c-based provides ambient light readings in lx with resolutions of 4LX, 1LX and 0.5LX (the default). To change the resolution, call set_resolution on the return value of this function.

By default, this sensor uses the i2c address 0x23 (the default if ADDR is pulled low). If the ADDR pin is pulled high (above 0.7VCC), then you can manually set the address to 0x5C using set_address.

Return
The BH1750Sensor + MQTT sensor pair, use this for advanced settings.
Parameters
  • name: The friendly name that this sensor should be advertised as.
  • address: The address of this i2c device.
  • update_interval: The interval in ms to update the sensor values.

Application::MakeBME280Sensor make_bme280_sensor(const std::string &temperature_name, const std::string &pressure_name, const std::string &humidity_name, uint8_t address = 0x77, uint32_t update_interval = 15000)

Create a BME280 Temperature+Pressure+Humidity i2c sensor.

Return
The BME280Component + MQTT sensors tuple, use this for advanced settings.
Parameters
  • temperature_name: The friendly name the temperature sensor should be advertised as.
  • pressure_name: The friendly name the pressure sensor should be advertised as.
  • humidity_name: The friendly name the humidity sensor should be advertised as.
  • address: The i2c address of the sensor. Defaults to 0x77 (SDO to V_DDIO), can also be 0x76.
  • update_interval: The interval in ms to update the sensor values.

Application::MakeBMP280Sensor make_bmp280_sensor(const std::string &temperature_name, const std::string &pressure_name, uint8_t address = 0x77, uint32_t update_interval = 15000)

Create a BMP280 Temperature+Pressure i2c sensor.

Return
The BME280Component + MQTT sensors tuple, use this for advanced settings.
Parameters
  • temperature_name: The friendly name the temperature sensor should be advertised as.
  • pressure_name: The friendly name the pressure sensor should be advertised as.
  • address: The i2c address of the sensor. Defaults to 0x77 (SDO to V_DDIO), can also be 0x76.
  • update_interval: The interval in ms to update the sensor values.

Application::MakeBME680Sensor make_bme680_sensor(const std::string &temperature_name, const std::string &pressure_name, const std::string &humidity_name, const std::string &gas_resistance_name, uint8_t address = 0x76, uint32_t update_interval = 15000)
Application::MakeSHT3XDSensor make_sht3xd_sensor(const std::string &temperature_name, const std::string &humidity_name, uint8_t address = 0x44, uint32_t update_interval = 15000)
Application::MakeDHT12Sensor make_dht12_sensor(const std::string &temperature_name, const std::string &humidity_name, uint32_t update_interval = 15000)
Application::MakeRotaryEncoderSensor make_rotary_encoder_sensor(const std::string &name, const GPIOInputPin &pin_a, const GPIOInputPin &pin_b)

Create a continuous rotary encoder sensor with a digital signal.

It will keep track of how far the encoder has been turned using the signals from the two required pins A & B. There’s also support for a third “index” pin. Each time this pin is pulled high, the counter will reset to 0.

Additionally, you can specify a resolution for the rotary encoder. By default, the encoder will only increment the counter once a full cycle of A&B signals has been detected to prevent triggers from noise. You can change this behavior using the set_resolution method.

The output value of this rotary encoder is a raw integer step value. Use filters to convert this raw value to something sensible like degrees. Next, this sensor pushes its state on every detected counter change.

Read https://playground.arduino.cc/Main/RotaryEncoders to see how they work.

Return
A MakeRotaryEncoderSensor, use this for advanced settings.
Parameters
  • name: The name of the rotary encoder.
  • pin_a: The first pin of the sensor.
  • pin_b: The second pin of the sensor.

Application::MakeTemplateSensor make_template_sensor(const std::string &name, uint32_t update_interval = 15000)
Application::MakeMAX6675Sensor make_max6675_sensor(const std::string &name, SPIComponent *spi_bus, const GPIOOutputPin &cs, uint32_t update_interval = 15000)
Application::MakeESP32HallSensor make_esp32_hall_sensor(const std::string &name, uint32_t update_interval = 15000)
Application::MakeDutyCycleSensor make_duty_cycle_sensor(const std::string &name, const GPIOInputPin &pin, uint32_t update_interval = 15000)
Application::MakeMHZ19Sensor make_mhz19_sensor(UARTComponent *parent, const std::string &co2_name, uint32_t update_interval = 15000)
Application::MakeUptimeSensor make_uptime_sensor(const std::string &name, uint32_t update_interval = 15000)
sensor::INA219Component *make_ina219(float shunt_resistance_ohm, float max_current_a, float max_voltage_v, uint8_t address = 0x40, uint32_t update_interval = 15000)
sensor::INA3221Component *make_ina3221(uint8_t address = 0x40, uint32_t update_interval = 15000)
sensor::HMC5883LComponent *make_hmc5883l(uint32_t update_interval = 15000)
Application::MakeHX711Sensor make_hx711_sensor(const std::string &name, const GPIOInputPin &dout, const GPIOOutputPin &sck, uint32_t update_interval = 15000)
Application::MakeMS5611Sensor make_ms5611_sensor(const std::string &temperature_name, const std::string &pressure_name, uint32_t update_interval = 15000)
sensor::TCS34725Component *make_tcs34725(uint32_t update_interval = 15000)
SNTPComponent *make_sntp_component()
sensor::HLW8012Component *make_hlw8012(const GPIOOutputPin &sel_pin, uint8_t cf_pin, uint8_t cf1_pin, uint32_t update_interval = 15000)
Application::MakeMQTTSubscribeSensor make_mqtt_subscribe_sensor(const std::string &name, std::string topic)
sensor::CSE7766Component *make_cse7766(UARTComponent *parent)
Application::MakeMQTTSubscribeTextSensor make_mqtt_subscribe_text_sensor(const std::string &name, std::string topic)
Application::MakeVersionTextSensor make_version_text_sensor(const std::string &name)
Application::MakeTemplateTextSensor make_template_text_sensor(const std::string &name, uint32_t update_interval = 15000)
sensor::PMSX003Component *make_pmsx003(UARTComponent *parent, sensor::PMSX003Type type)
Application::MakeTotalDailyEnergySensor make_total_daily_energy_sensor(const std::string &name, time::RealTimeClockComponent *time, sensor::Sensor *parent)
PowerSupplyComponent *make_power_supply(const GPIOOutputPin &pin, uint32_t enable_time = 20, uint32_t keep_on_time = 10000)

Create a power supply component that will automatically switch on and off.

Return
The PowerSupplyComponent.
Parameters
  • pin: The pin the power supply is connected to.
  • enable_time: The time (in ms) the power supply needs until it can provide high power when powering on.
  • keep_on_time: The time (in ms) the power supply should stay on when it is not used.

LEDCOutputComponent *make_ledc_output(uint8_t pin, float frequency = 1000.0f, uint8_t bit_depth = 12)

Create a ESP32 LEDC channel.

Return
The LEDC component. Use this for advanced settings.
Parameters
  • pin: The pin.
  • frequency: The PWM frequency.
  • bit_depth: The LEDC bit depth.

PCA9685OutputComponent *make_pca9685_component(float frequency)

Create a PCA9685 component.

Return
The PCA9685 component. Use this for advanced settings.
Parameters
  • frequency: The PWM frequency.

output::GPIOBinaryOutputComponent *make_gpio_output(const GPIOOutputPin &pin)

Create a simple binary GPIO output component.

Note: This is only a binary output component, not a switch that will be exposed in Home Assistant. See make_simple_gpio_switch for a switch.

Return
The GPIOBinaryOutputComponent. Use this for advanced settings.
Parameters
  • pin: The GPIO pin.

ESP8266PWMOutput *make_esp8266_pwm_output(GPIOOutputPin pin_)

Create an ESP8266 software PWM channel.

Warning: This is a software PWM and therefore can have noticeable flickering. Additionally, this software PWM can’t output values higher than 80%.

Return
The PWM output channel, use this for advanced settings and using it with lights.
Parameters
  • pin: The pin for this PWM output, supported pins are 0-16.

MY9231OutputComponent *make_my9231_component(const GPIOOutputPin &pin_di, const GPIOOutputPin &pin_dcki)

Create a MY9231 component.

Return
The MY9231 component. Use this for advanced settings.
Parameters
  • pin_di: The pin which DI is connected to.
  • pin_dcki: The pin which DCKI is connected to.

MQTTJSONLightComponent *register_light(light::LightState *state)

Register a light within esphomelib.

Application::MakeLight make_light_for_light_output(const std::string &name, light::LightOutput *output)
Application::MakeLight make_binary_light(const std::string &friendly_name, output::BinaryOutput *binary)

Create a binary light.

Return
The components for this light. Use this for advanced settings.
Parameters
  • friendly_name: The name the light should be advertised as. Leave empty for no automatic discovery.
  • binary: The binary output channel.

Application::MakeLight make_monochromatic_light(const std::string &friendly_name, output::FloatOutput *mono)

Create a monochromatic light.

Return
The components for this light. Use this for advanced settings.
Parameters
  • friendly_name: The name the light should be advertised as. Leave empty for no automatic discovery.
  • mono: The output channel.

Application::MakeLight make_rgb_light(const std::string &friendly_name, output::FloatOutput *red, output::FloatOutput *green, output::FloatOutput *blue)

Create a RGB light.

Return
The components for this light. Use this for advanced settings.
Parameters
  • friendly_name: The name the light should be advertised as. Leave empty for no automatic discovery.
  • red: The red output channel.
  • green: The green output channel.
  • blue: The blue output channel.

Application::MakeLight make_rgbw_light(const std::string &friendly_name, output::FloatOutput *red, output::FloatOutput *green, output::FloatOutput *blue, output::FloatOutput *white)

Create a RGBW light.

Return
The components for this light. Use this for advanced settings.
Parameters
  • friendly_name: The name the light should be advertised as. Leave empty for no automatic discovery.
  • red: The red output channel.
  • green: The green output channel.
  • blue: The blue output channel.
  • white: The white output channel.

Application::MakeLight make_rgbww_light(const std::string &friendly_name, float cold_white_mireds, float warm_white_mireds, output::FloatOutput *red, output::FloatOutput *green, output::FloatOutput *blue, output::FloatOutput *cold_white, output::FloatOutput *warm_white)
Application::MakeLight make_cwww_light(const std::string &friendly_name, float cold_white_mireds, float warm_white_mireds, output::FloatOutput *cold_white, output::FloatOutput *warm_white)
Application::MakeFastLEDLight make_fast_led_light(const std::string &name)

Create an FastLED light.

MQTTSwitchComponent *register_switch(switch_::Switch *switch_)

Register a Switch internally, creating a MQTT Switch if the MQTT client is set up.

Application::MakeGPIOSwitch make_gpio_switch(const std::string &friendly_name, const GPIOOutputPin &pin)

Create a simple GPIO switch that can be toggled on/off and appears in the frontend.

Return
A MakeGPIOSwitch, use this to set advanced settings.
Parameters
  • pin: The pin used for this switch. Can be integer or GPIOOutputPin.
  • friendly_name: The friendly name advertised to Home Assistant for this switch-

Application::MakeRestartSwitch make_restart_switch(const std::string &friendly_name)

Make a simple switch that restarts the device with the provided friendly name.

Application::MakeShutdownSwitch make_shutdown_switch(const std::string &friendly_name)

Make a simple switch that shuts the node down indefinitely.

Application::MakeOutputSwitch make_output_switch(const std::string &friendly_name, output::BinaryOutput *output)

Make an output switch that exposes a binary output as a switch.

Application::MakeTemplateSwitch make_template_switch(const std::string &name)
remote::RemoteTransmitterComponent *make_remote_transmitter_component(const GPIOOutputPin &output)
Application::MakeUARTSwitch make_uart_switch(UARTComponent *parent, const std::string &name, const std::vector<uint8_t> &data)
fan::MQTTFanComponent *register_fan(fan::FanState *state)

Register a fan internally.

Application::MakeFan make_fan(const std::string &friendly_name)

Create and connect a Fan with the specified friendly name.

Return
A FanStruct, use the output field to set your output channels.
Parameters
  • friendly_name: The friendly name of the Fan to advertise.

cover::MQTTCoverComponent *register_cover(cover::Cover *cover)
Application::MakeTemplateCover make_template_cover(const std::string &name)
stepper::A4988 *make_a4988(const GPIOOutputPin &step_pin, const GPIOOutputPin &dir_pin)
DebugComponent *make_debug_component()
DeepSleepComponent *make_deep_sleep_component()
PCF8574Component *make_pcf8574_component(uint8_t address = 0x21, bool pcf8575 = false)

Create a PCF8574/PCF8575 port expander component.

This component will allow you to emulate GPIOInputPin and GPIOOutputPin instances that are used within esphomelib. You can therefore simply pass the result of calling make_pin on the component to any method accepting GPIOInputPin or GPIOOutputPin.

Optionally, this component also has support for the 16-channel PCF8575 port expander. To use the PCF8575, set the pcf8575 in this helper function.

Return
The PCF8574Component instance to get individual pins.
Parameters
  • address: The i2c address to use for this port expander. Defaults to 0x21.
  • pcf8575: If this is an PCF8575. Defaults to PCF8574.

template <class C>
C *register_component(C *c)

Register the component in this Application instance.

template <class C>
C *register_controller(C *c)
void setup()

Set up all the registered components. Call this at the end of your setup() function.

void HOT Application::loop()

Make a loop iteration. Call this in your loop() function.

WiFiComponent *get_wifi() const
MQTTClientComponent *get_mqtt_client() const
const std::string &get_name() const

Get the name of this Application set by set_name().

bool is_fully_setup() const
void set_compilation_datetime(const char *str)

Tell esphomelib when your project was last compiled.

This is used to show a message like “You’re running esphomelib v1.9.0 compiled on Oct 10 2018, 16:42:00”

To use this method in code, put the following before App.setup():

App.set_compilation_datetime(__DATE__ ", " __TIME__);

Parameters
  • str: The string of the time of compilation.

const std::string &get_compilation_time() const

Protected Attributes

std::vector<Component *> components_ = {}
std::vector<Controller *> controllers_ = {}
mqtt::MQTTClientComponent *mqtt_client_ = {nullptr}
WiFiComponent *wifi_ = {nullptr}
std::string name_
std::string compilation_time_
uint32_t application_state_ = {COMPONENT_STATE_CONSTRUCTION}
I2CComponent *i2c_ = {nullptr}
struct MakeADCSensor

Public Members

sensor::ADCSensorComponent *adc
sensor::MQTTSensorComponent *mqtt
struct MakeBH1750Sensor

Public Members

sensor::BH1750Sensor *bh1750
sensor::MQTTSensorComponent *mqtt
struct MakeBME280Sensor

Public Members

sensor::BME280Component *bme280
sensor::MQTTSensorComponent *mqtt_temperature
sensor::MQTTSensorComponent *mqtt_pressure
sensor::MQTTSensorComponent *mqtt_humidity
struct MakeBME680Sensor

Public Members

sensor::BME680Component *bme680
sensor::MQTTSensorComponent *mqtt_temperature
sensor::MQTTSensorComponent *mqtt_pressure
sensor::MQTTSensorComponent *mqtt_humidity
sensor::MQTTSensorComponent *mqtt_gas_resistance
struct MakeBMP085Sensor

Public Members

sensor::BMP085Component *bmp
sensor::MQTTSensorComponent *mqtt_temperature
sensor::MQTTSensorComponent *mqtt_pressure
struct MakeBMP280Sensor

Public Members

sensor::BMP280Component *bmp280
sensor::MQTTSensorComponent *mqtt_temperature
sensor::MQTTSensorComponent *mqtt_pressure
struct MakeDHT12Sensor

Public Members

sensor::DHT12Component *dht12
sensor::MQTTSensorComponent *mqtt_temperature
sensor::MQTTSensorComponent *mqtt_humidity
struct MakeDHTSensor

Public Members

sensor::DHTComponent *dht
sensor::MQTTSensorComponent *mqtt_temperature
sensor::MQTTSensorComponent *mqtt_humidity
struct MakeDutyCycleSensor

Public Members

sensor::DutyCycleSensor *duty
sensor::MQTTSensorComponent *mqtt
struct MakeESP32HallSensor

Public Members

sensor::ESP32HallSensor *hall
sensor::MQTTSensorComponent *mqtt
struct MakeFan

Public Members

fan::BasicFanComponent *output
fan::FanState *state
fan::MQTTFanComponent *mqtt
struct MakeFastLEDLight

Public Members

light::FastLEDLightOutputComponent *fast_led
light::LightState *state
light::MQTTJSONLightComponent *mqtt
struct MakeGPIOBinarySensor

Public Members

binary_sensor::GPIOBinarySensorComponent *gpio
binary_sensor::MQTTBinarySensorComponent *mqtt
struct MakeGPIOSwitch

Public Members

switch_::GPIOSwitch *switch_
switch_::MQTTSwitchComponent *mqtt
struct MakeHDC1080Sensor

Public Members

sensor::HDC1080Component *hdc1080
sensor::MQTTSensorComponent *mqtt_temperature
sensor::MQTTSensorComponent *mqtt_humidity
struct MakeHTU21DSensor

Public Members

sensor::HTU21DComponent *htu21d
sensor::MQTTSensorComponent *mqtt_temperature
sensor::MQTTSensorComponent *mqtt_humidity
struct MakeHX711Sensor

Public Members

sensor::HX711Sensor *hx711
sensor::MQTTSensorComponent *mqtt
struct MakeLight

Public Members

light::LightOutput *output
light::LightState *state
light::MQTTJSONLightComponent *mqtt
struct MakeMAX6675Sensor

Public Members

sensor::MAX6675Sensor *max6675
sensor::MQTTSensorComponent *mqtt
struct MakeMHZ19Sensor

Public Members

sensor::MHZ19Component *mhz19
sensor::MQTTSensorComponent *mqtt
struct MakeMQTTSubscribeSensor

Public Members

sensor::MQTTSubscribeSensor *sensor
sensor::MQTTSensorComponent *mqtt
struct MakeMQTTSubscribeTextSensor

Public Members

text_sensor::MQTTSubscribeTextSensor *sensor
text_sensor::MQTTTextSensor *mqtt
struct MakeMS5611Sensor

Public Members

sensor::MS5611Component *ms5611
sensor::MQTTSensorComponent *mqtt_temperature
sensor::MQTTSensorComponent *mqtt_pressure
struct MakeOutputSwitch

Public Members

switch_::OutputSwitch *switch_
switch_::MQTTSwitchComponent *mqtt
struct MakePulseCounterSensor

Public Members

sensor::PulseCounterSensorComponent *pcnt
sensor::MQTTSensorComponent *mqtt
struct MakeRestartSwitch

Public Members

switch_::RestartSwitch *restart
switch_::MQTTSwitchComponent *mqtt
struct MakeRotaryEncoderSensor

Public Members

sensor::RotaryEncoderSensor *rotary_encoder
sensor::MQTTSensorComponent *mqtt
struct MakeSHT3XDSensor

Public Members

sensor::SHT3XDComponent *sht3xd
sensor::MQTTSensorComponent *mqtt_temperature
sensor::MQTTSensorComponent *mqtt_humidity
struct MakeShutdownSwitch

Public Members

switch_::ShutdownSwitch *shutdown
switch_::MQTTSwitchComponent *mqtt
struct MakeStatusBinarySensor

Public Members

binary_sensor::StatusBinarySensor *status
binary_sensor::MQTTBinarySensorComponent *mqtt
struct MakeTemplateBinarySensor

Public Members

binary_sensor::TemplateBinarySensor *template_
binary_sensor::MQTTBinarySensorComponent *mqtt
struct MakeTemplateCover

Public Members

cover::TemplateCover *template_
cover::MQTTCoverComponent *mqtt
struct MakeTemplateSensor

Public Members

sensor::TemplateSensor *template_
sensor::MQTTSensorComponent *mqtt
struct MakeTemplateSwitch

Public Members

switch_::TemplateSwitch *template_
switch_::MQTTSwitchComponent *mqtt
struct MakeTemplateTextSensor

Public Members

text_sensor::TemplateTextSensor *template_
text_sensor::MQTTTextSensor *mqtt
struct MakeTotalDailyEnergySensor

Public Members

sensor::TotalDailyEnergy *total_energy
sensor::MQTTSensorComponent *mqtt
struct MakeTSL2561Sensor

Public Members

sensor::TSL2561Sensor *tsl2561
sensor::MQTTSensorComponent *mqtt
struct MakeUARTSwitch

Public Members

switch_::UARTSwitch *uart
switch_::MQTTSwitchComponent *mqtt
struct MakeUltrasonicSensor

Public Members

sensor::UltrasonicSensorComponent *ultrasonic
sensor::MQTTSensorComponent *mqtt
struct MakeUptimeSensor

Public Members

sensor::UptimeSensor *uptime
sensor::MQTTSensorComponent *mqtt
struct MakeVersionTextSensor

Public Members

text_sensor::VersionTextSensor *sensor
text_sensor::MQTTTextSensor *mqtt
struct MakeWiFiSignalSensor

Public Members

sensor::WiFiSignalSensor *wifi
sensor::MQTTSensorComponent *mqtt
Application App

Global storage of Application pointer - only one Application can exist.