There’s no shortage of information on the Internet on how to dim leds. I assume you havnt tried Google and educating yourself. You can’t search for “esp8266 dim led” ? You have to make an effort bud, this is a DIY hobby.
Have another drink bro. You don’t have to be a prick. Your solution doesn’t (at least to me) address handling a physical device for light level control. Of course you have that sorted…
Yes it does. A rotary encoder is a physical device.
You’re in an esphome forum… The device is the esp, the rotary encoder or potentiometer and the mosfet. When you put the 3 together you can control a wide range of devices including led’s. What you are confused about is you think it’s my job to be your private tutor and hold your hand, it’s not. I pointed you in the direction you needed and told you the components you need. All you had to do is do some basic searches with Google or here and put it together or just copy one of the many projects that do this and are widely available online. All you have to do is use a search box. If you can’t do that, you better just stick to some premade Tuya crap.
here this is with WLED but, two of these light (as shown in the video) and one fixed on the aquarium hood is being controlled via esphome.
light:
- platform: monochromatic
name: "10Gal Aquarium Light"
output: gpio_19
id: AqauriumLight
output:
- platform: ledc
pin: GPIO19
id: gpio_19
frequency: "1000Hz"
and local (esphome based ) automation for it
#Automation for the Neopixel light
on_time:
# Every morning everyday at 7am
- seconds: 0
minutes: 0
hours: 7
then:
- light.turn_on:
id: AqauriumLight
brightness: 20%
# Every morning everyday at 9am brightness increased to 50%
- seconds: 0
minutes: 0
hours: 9
then:
- light.turn_on:
id: AqauriumLight
brightness: 50%
# Every morning everyday at 10am brightness increased to 75%
- seconds: 0
minutes: 0
hours: 10
then:
- light.turn_on:
id: AqauriumLight
brightness: 75%
# Every morning everyday at 11am brightness increased to 100%
- seconds: 0
minutes: 0
hours: 11
then:
- light.turn_on:
id: AqauriumLight
brightness: 100%
# Every evening everyday at 5pm brightness decreased to 50%
- seconds: 0
minutes: 0
hours: 17
then:
- light.turn_on:
id: AqauriumLight
brightness: 50%
# Every evening everyday at 7pm light turn.off
- seconds: 0
minutes: 0
hours: 19
then:
- light.turn_off:
id: AqauriumLight
and the rotary encode
#Rotary encoder
- platform: rotary_encoder
name: "Rotary Encoder"
pin_a: GPIO34
pin_b: GPIO35
id: Rotarysensor
min_value: 0
max_value: 100
publish_initial_value: true
but that is not being used for brigtness control right now.
Hopefully, I cleared the air on this one.
You need following materials
- Esp32/ESP8266 node-mcu or any other esp32/esp8266
- Power mosfet.
- 12V power supply which you already have in RV
connection is simple.
12V connected to the VIN + and VIN - side.
light connected on the OUT + and OUT -side.
Connect GND from esp32/8266 to gnd pin on the power mosfet, and TRIG/PWM will be connected to any GPIO pin on the esp32/8266. in my case it is GPIO19.
As for choosing the right pin follow this guide
and if you want to use wled
here you go, hardware is same as my above post, esp32/8266, power Mosfet, 12V led and your time. Download the relevant bin with rotary encoder in file name.
https://github.com/srg74/WLED-wemos-shield/tree/master/resources/Firmware/%40Aircoookie/v0.14.0-b2
==================
@KevinE here are the setting for rotary-encoder in WLED.
Thanks for all the responses. I’m not an electronics guy but my guess is a rotary encoder is just a variable resistor. For the device I want to use, it is already outputting a pwm signal. Can an Esp read this signal and calibrate it to a brightness level?
I don’t like the look of a rotary encoder in my application.
Why would you guess what it is when you could just look it up? No, it’s not a variable resistor. They look similar but they’re completely different things. You’re making this way harder than it should be. If you already have a controller than use that. Trying to use a pre-made controller and then add onto it what is essentially another controller doesn’t make any sense, it’s like a dog chasing its tail. If your not into electronics and for some reason can’t Google anything, then you need to buy a controller that will do what you need and integrate into HA because what your trying to do is going to be a nightmare and this actually very simple and a beginner project
I mocked up the circuit for you. Instead of that red wire going to an led you would use the pwm terminal on the mosfet board or you can use an led w/220ohm resistor to test it.
here is the code for it. The rotary encoders usually have a push switch built in so you can push it to toggle on/off then spin it for changing the brightness. I didn’t add it in the circuit but its just one more wire to a gpio and the other pin from the encoder goes to ground.
number:
- platform: template
name: ledchange
id: my_number
min_value: 0.0
max_value: 100.0
step: 5.0
optimistic: true
initial_value: 0.0
sensor:
- platform: rotary_encoder
name: "Rotary Encoder Dimmer"
id: ledencoder
min_value: 1
max_value: 255
resolution: 4
pin_a:
number: D2
inverted: true
mode:
input: true
pullup: true
pin_b:
number: D7
inverted: true
mode:
input: true
pullup: true
filters:
- or:
- debounce: 0.1s
- delta: 8
- lambda: |-
if (x < 0.0) return 0.0;
if (x > 255.0) return 255.0;
return x;
on_value:
then:
- light.turn_on:
id: greenLED
brightness: !lambda |-
return x / 255;
- logger.log:
format: "pwm_output set to %.1f%s"
args: [ 'x*100/256.0', '"%"' ]
output:
- platform: esp8266_pwm
pin: D5
id: dim_green
light:
- platform: monochromatic
output: dim_green
name: "Green LED"
id: greenLED
switch:
- platform: gpio
id: encoder_push
name: 'Rotary Push'
pin:
number: D6
mode:
input: true
pullup: true
inverted: true
on_turn_on:
if:
condition:
light.is_off: greenLED
then:
- light.turn_on:
id: greenLED
brightness: 80%
else:
light.turn_off: greenLED
Justin,
Did you look at the dimmer I want to use? Its tap to toggle on/off and press hold to dim. I don’t want to use a rotary switch, I am trying to get a bit more modern behaviour and not look like an electronics experiment.
I think you’re in the wrong place. I clearly said, “I mocked this circuit up”. Was it not obvious that it’s not a finished product and it was to show you how to make the circuit? I told you that switch wont work and someone else did too. It’s not going to change by asking over and over. I think you might be in the wrong place. You can find those cheap Chinese Tuya dimmers and such that aren’t an “electronics experiment” but they are idiot proof and you basically just plug therm in.
I put a link in my original post
Potentiometer vs rotatory encoder. both have their own uses.
===================================================
Here is complete circuit, working without any issues with wled. for esphome just need to flash with esphome and use the above code. there are some extra wires. circuit is simple
Would you install a rotary encoder in your home as a dimmer switch? I need something a bit more elegant than this.
Actually for many many years dimmers in homes were rotary like this and yes I prefer a knob to pressing a button for dimming (or volume control for that matter). So yes i’d fill my home with them. Knobs are easy to buy.
But push button is possible too. Typically
Short press - toggle on/off
Long press - dim up, once full brightness, another long press to dim down.
Very do-able in esphome. I have seen this implemented in this forum.
I am already using one in one of my aquarium controller based on esphome.
I’m liking this solution. I have 2 rooms in my camper that have 4 bulb LEDs, each set (of 4) are currently controlled by a On/Off rocker switch.
Do you step down the power for the ESP32 or are you running off 12V? I would assume the 12V (at the switch) should be pretty regulated for the LEDs already but not sure about long-term effect of running the ESP at that voltage.
I use 5V for esp32.