I have an existing setup where I control two channels of 12 CREE LEDs each (12 white and 12 blue) using an Arduino Uno. I made this quite some time ago and want to now shift to ESP32. Here is what I want to do.
I want to control the start and end times of the white and blue channels separately.
I want these timings to be controllable from HA. I have created Helper entries for these.
I visualise the total timing for each channel to be 6 hours, broken up into two sections of 3 hours each - from 0 to x% for 3 hours and x% to 0 for the next 3 hours.
My design is to a) use Number to store and update the brightness level of each channel b) check if the current time on the ESPHome end is equal to the time set in HA for each channel separately, c) turn on the light and d) run a script to increase the brightness at a certain frequency till I reach the target percentage.
I am able to understand the sequence in which these actions are to be taken, however not being a programmer myself, I wish to check if a) my approach is correct and b) how do I combine these three - the Number, the Time Check and the Script in one single flow of logic ? Meaning - if the time equals the start time, turn on the lights, update the brightness and send that number via the PWM pin to the LED driver ?
I suggest you to read esphome documentation. Instead of sequence, esphome uses then.
You don’t necessarily need to use template number for brightness.
As simplest form it would be just light.turn_on with 3 hours transition length and then back. I don’t see it best approach though .
I personally would use something like this (not tested):
Thanks Mahko. You are right to suggest keeping most of the things on the ESP side. Have tried Karosm’s suggestion in the meanwhile…lets see how it works.
The display part can be ignored…I am still working on it. I see 5 entries in the HA UI and set the light switch on time to 22:15. The problem I am facing is that the script is not being executed. The log is as below…
[22:12:59][W][component:490]: wifi took a long time for an operation (225 ms)
[22:12:59][W][component:493]: Components should block for at most 30 ms
[22:12:59][I][wifi:1149]: Connected
[22:12:59][C][wifi:897]: Local MAC: D4:E9:F4:B3:B4:44
[22:12:59][C][wifi:904]: IP Address: 192.168.0.111
[22:12:59][C][wifi:908]: SSID: 'Mandrake'[redacted]
[22:12:59][C][wifi:908]: BSSID: 3C:84:6A:F3:B5:F4[redacted]
[22:12:59][C][wifi:908]: Hostname: 'esphome-web-b3b444'
[22:12:59][C][wifi:908]: Signal strength: -54 dB ▂▄▆█
[22:12:59][C][wifi:908]: Channel: 2
[22:12:59][C][wifi:908]: Subnet: 255.255.255.0
[22:12:59][C][wifi:908]: Gateway: 192.168.0.1
[22:12:59][C][wifi:908]: DNS1: 192.168.0.1
[22:12:59][C][wifi:908]: DNS2: 0.0.0.0
[22:12:59][D][wifi:1173]: Disabling AP
[22:12:59][W][component:373]: wifi cleared Warning flag
[22:12:59][D][api:136]: Accept 192.168.0.116
[22:12:59][W][component:373]: api cleared Warning flag
[22:12:59][W][component:490]: api took a long time for an operation (53 ms)
[22:12:59][W][component:493]: Components should block for at most 30 ms
[22:12:59][D][api.connection:1398]: Home Assistant 2025.12.5 (192.168.0.116) connected
[22:12:59][D][time:068]: Synchronized time: 2026-01-03 22:12:37
[22:12:59][D][datetime.time_entity:056]: 'Turn on White LED ' - Setting
[22:12:59][D][datetime.time_entity:058]: Hour: 22
[22:12:59][D][datetime.time_entity:061]: Minute: 0
[22:12:59][D][datetime.time_entity:064]: Second: 0
[22:12:59][D][datetime.time_entity:029]: 'Turn on White LED ': Sending time 22:00:00
[22:12:59][D][datetime.time_entity:056]: 'Turn on White LED ' - Setting
[22:12:59][D][datetime.time_entity:058]: Hour: 22
[22:12:59][D][datetime.time_entity:061]: Minute: 15
[22:12:59][D][datetime.time_entity:064]: Second: 0
[22:12:59][D][datetime.time_entity:029]: 'Turn on White LED ': Sending time 22:15:00
[22:12:59][D][datetime.time_entity:056]: 'Turn on Blue LED ' - Setting
[22:12:59][D][datetime.time_entity:058]: Hour: 22
[22:12:59][D][datetime.time_entity:061]: Minute: 0
[22:12:59][D][datetime.time_entity:064]: Second: 0
[22:12:59][D][datetime.time_entity:029]: 'Turn on Blue LED ': Sending time 22:00:00
[22:12:59][D][datetime.time_entity:056]: 'Turn on Blue LED ' - Setting
[22:12:59][D][datetime.time_entity:058]: Hour: 22
[22:12:59][D][datetime.time_entity:061]: Minute: 15
[22:12:59][D][datetime.time_entity:064]: Second: 0
[22:12:59][D][datetime.time_entity:029]: 'Turn on Blue LED ': Sending time 22:15:00
[22:13:29][I][safe_mode:042]: Boot seems successful; resetting boot loop counter
[22:13:29][D][esp32.preferences:149]: Writing 1 items: 0 cached, 1 written, 0 failed
[22:13:31][D][main:148]: Lights are off
[22:13:32][D][main:161]: Lights are off
[22:14:31][D][main:148]: Lights are off
[22:14:32][D][main:161]: Lights are off
[22:15:31][D][main:148]: Lights are off
[22:15:32][D][main:161]: Lights are off
I have pasted the portion of the log from the time that the Wifi got connected. If you see towards the end of the log, the script has not kicked in.
Any suggestions on what I may be doing wrong here ?
First step, add a button to fire the script, so you can be sure it works like intended.
Second step, dig deeper into the daytime component (I’m not familiar with it). state_as_esptime() especially, is it valid just for time without date…
Maybe make condition for .hour and .minute instead.