I want to control the brightness of a single LED that is connected with a resistor to a pin on a a ESP32-S3 with esphome. I want to use a slider as seen here in the docs https://esphome.io/components/light/monochromatic
I’ve added the following parts but only a binary switch is created and not a slider
If I open de esphome integration and look up the esphome device then I can see there all the created entities that are marked visible (internal: not set to true)
There is only a switch is available.
I solved it in this manner
light:
- platform: monochromatic # KEUKEN
output: zmc_volume1
name: ${zmc_volume1}
internal: True
output:
- platform: ledc
id: zmc_volume1 # KEUKEN
pin: 14
number:
- platform: template # KEUKEN
name: ${zmc_volume1}
id: volume1_slider
max_value: 15.0
min_value: 0.0
step: 0.1
mode: slider
initial_value: ${preset_woonkamer_volume}
optimistic: true
on_value:
then:
# Must be turned on before setting frequency & level
- output.turn_on: zmc_volume1
- output.ledc.set_frequency:
id: zmc_volume1
frequency: "19531Hz"
# level sets the %age time the PWM is on
- output.set_level:
id: zmc_volume1
level: !lambda |-
// output value must be in range 0 - 1.0
return id(volume1_slider).state / 100.0;
Oww, I just followed the example. I will try to remove the light component.
To explain the 15% brightness in the code
I made a multi channel audio mixer from scratch (will post more on that later) and I want to control the volume of a few output channels with just 1 pin per channel on the controller. I made a LED/LDR combo where the LDR is the volume control and the brightness of the LED the controlling bit. I’ve added some extra code to the lambda to make the brightness from 0% to max more linear. At 15% the LED is already bright enough to max out the LDR so no use to waste extra energy here. Also a scale of 0.0 - 15.0 with 0.1 step width gave me a good enough slider effect.
Update
I removed the light components and it still worked. Thx for mention this.
I was in the impression that I needed it because of the LED.
So, it’s an HA question, not an ESPHome issue. If you click on the light name in the device page in HA you will get a dialog box with a brightness slider (and color if available.) You can also add it to a suitable card in a dashboard to have the brightness visible.
I am sorry but it was not.
If I did what you advised a switch was shown, not a slider.
However, I have solved it already as mentioned above. Thank you for your attention and your time to help.
You needed that to have a “slider”.
But you made it with number component, so doesn’t serve anything.
Mystery remains, why light component didn’t give you UI like it should…