Close

PWM output (for lights)

A project log for Experiences with ESPhome

Setting up some ESPhome-devices

mabe42MaBe42 a day ago0 Comments

Something you quite often want to have with lights is that you can dim them.

Ok. But don't look for something like Light-PWM. What you want to change is not the abstract light component but the underlying output. And here we find several components: 

- ESP32 LEDC

- ESP8266 Software PWM

- LibreTiny PWM

- Slow PWM

As I'm working with the Wemos D1 mini which is an ESP8266 board, I choose ESP8266 Software PWM.

The first thing I have to change is a single line in my code to make the red LED dimmable:

  - platform: esp8266_pwm

instead of gpio.

But a dimmable light is not a binary one any more. Therefore, this needs to be changed, too and becomes:

  - platform: monochromatic

instead of  binary.

The appearance in HA is the same but when clicking on the red LED, a widget pops up where the brightness can be set to anything between 0 and 100%.

And looking at the log, the following can be seen:

[09:06:28][D][light:036]: 'red LED' Setting:
[09:06:28][D][light:047]:   State: ON
[09:06:28][D][light:051]:   Brightness: 53%
[09:06:28][D][light:085]:   Transition length: 1.0s
[09:06:31][D][light:036]: 'red LED' Setting:
[09:06:31][D][light:047]:   State: OFF
[09:06:31][D][light:085]:   Transition length: 1.0s
[09:06:32][D][light:036]: 'red LED' Setting:
[09:06:32][D][light:047]:   State: ON
[09:06:32][D][light:085]:   Transition length: 1.0s

There is something called "Transition length" which defines how long it takes to fade-in/fade-out. And with the button below the slider, the light can be switched on/off. But "on" is then the previously set intensity. In the above case it means it will return again to 53% intensity - not to 100%.

Looking into the documentation, (https://esphome.io/components/light/#config-light) there are plenty of possibilities for setting parameters like default_transition_length but not all can be used with the monochromatic light.

For example:

light:
  - platform: monochromatic
    name: "red LED"
    output: gpio_d7
    default_transition_length: 3s

Discussions