Simple Question I'm sure

Hi

New to the forum, but have a few things on HA already

I am struggling with the logic of what I’m trying to achieve. I promise I have searched but I cannot find answer to what I’m trying to do - I admit though my search logic is probably all wrong and I apologise for asking what I know is a simple question

I have an LED connected to a WEMOS D1 MINI - HA turns it on at a random time during a one hour window before sunset. Pretty standard and works a treat… HA switches that LED off at 11.59pm

What I would like to do now is change the behavior of the switch off to use a PWM pin on the WEMOS so that in say a 1 hour window the LED gradually dims to nothing so would be off at 11.59

I am really struggling with the logic though. Simply turning on the LED is going to change, I need to send a command to the WEMOS to turn it on a PWM value 255. I don know how to do that. Even if I could figure that out however I then need to know how to send a PWM command at (for instance) 10pm to start dimming the light to 0 by 11.59 (this is maths - I’m sure I can figure it out)

I dont want HA to send out a message every 4 minutes to say ‘dim but int 4’ (for example).

Ideally I’d like to have a loop installed on the wemos which I can launch from HA at 10pm so start running?

In my head this should be so simple but I have obviously gone into some loop of stupidity

I’d really appreciate any help

Thanks for any help if you read this and think, clown!

Jase

Some lights support this as canned functionality, as a “transition.” Are you using esphome? Your light may already accommodate it. If no, maybe at least I’ve given you the “magic word” for additional research.

If you are using esphome; https://esphome.io/components/light/index.html#light-turn-off-action

If not; meh.

That’s great thank you both really appreciate the esphome ideas

The LEDs in this case are just a simple string of battery ones (before I converted them to run off usb) Connected through a transistor to wemos d1mini pwm pin

I think the esphome link might give me what I want!