# OpenLED and ESPHome

There are multiple ways through which you can use OpenLED (and integrate it with your smart home).

One of the ways is using ESPHome (described on this page) or using [WLED](https://docs.sasakaranovic.com/openled/wled/index.md).\
There are other ways as well but these two are probably the easiest.

Depending on your application/project, comfort level and/or personal preference, you might choose to use WLED, ESPHome or some other application.

## What is ESPHome

> [ESPHome](https://esphome.io/) is a system to control your microcontrollers by simple yet powerful configuration files and control them remotely through Home Automation systems.

Please note that while ESPHome is more/very customizable, it does require that you compile your configuration file and upload the compiled binary. The setup and compile process is simple and well documented, however it is not plug&play.

## Common OpenLED and ESPHome use-case

![](https://docs.sasakaranovic.com/openled/openled_an_pir.png) ![](https://docs.sasakaranovic.com/openled/openled_an_rf.png)

You might want to use OpenLED and ESPHome for example if you want to connect sensors (ie PIR or RF proximity sensor) and use that to turn on/off lights based on motion detection or presence.

Fully functional configuration that uses both PIR and RF sensor is available in the official [GitHub repository](https://github.com/SasaKaranovic/OpenLED/blob/master/ESPHome-Examples/OpenLED-PIR_and_RF_controlled_light.yaml)

## Example .yaml configurations

Multiple example ESPHome `.yaml` configurations for OpenLED are provided in the OpenLED [GitHub repository](https://github.com/SasaKaranovic/OpenLED/tree/master/ESPHome-Examples).\
These examples covers all the basic OpenLED + ESPHome configuration and hopefully you should be able to easily customize them to fit your use-case.

## How to compile and install my ESPHome configuration

Please refer to the official [ESPHome build guide](https://esphome.io/guides/getting_started_command_line).

## Configure the three 12V PWM channels

OpenLED has three 12V PWM channels that you can use to control different LEDs strips.\
For example control RGB LED strip, or Cool-White + Warm-White LED strip, or to have multiple individual zones.

You should have the `output:` section that describes which pins are connected to which channel.

```yaml
output:
  - platform: ledc
    pin: GPIO0 # Do not change this
    id: gpio_0 # This is the name you can use to assign to control LED CH1
    inverted: true # Do not change this
    frequency: 400Hz

  - platform: ledc
    pin: GPIO1 # Do not change this
    id: gpio_1 # This is the name you can use to assign to control LED CH2
    inverted: true # Do not change this
    frequency: 400Hz

  - platform: ledc
    pin: GPIO3 # Do not change this
    id: gpio_3 # This is the name you can use to assign to control LED CH3
    inverted: true # Do not change this
    frequency: 400Hz
```

## Configure the addressable LED data out

```yaml
light:
  - platform: esp32_rmt_led_strip
    id: LedsStrip
    chipset: WS2812
    rgb_order: GRB
    pin: GPIO6            # Do not change this
    num_leds: $ledcount   # Total number of LEDs on your addressable strip
    name: "$devicename Addressable LEDs"
```

> **NOTE: Use variables**
>
> If you are using example configuration, instead of manually renaming each line that starts with `$`, you can just modify your `substitutions:` section at the top of the `.yaml` file.
