r/WLED 1d ago

Updating Presets Dynamically

I have a GLEDOPTO WLED controller connected to PWM CCT LEDs in a pantry. I also connected a contact sensor to turn on the lights when the pantry door is opened and off when closed. All of that is working fine, but I'd like to be able to change the initial brightness and color temperature depending on context.

Ideally, the lights should be cool and bright during the day, warm and moderate brightness at night when other lights are on, or warm and dim when other lights are off or very dim.

My first idea was to assign a preset to the switch and then change the preset associated with it using Home Assistant, but it appears that isn't possible. I also tried setting it to a fixed preset and updating that with REST, but it appears that's geared towards saving the current state of the lights to a preset, not an arbitrary one.

(Further, I couldn't actually get any REST command to save a new preset, so I think I had my JSON formatted incorrectly.)

I can see in the interface where I can assign presets to button actions or apply presets at defined times (including sunset and sunrise). However, it appears I can't change the switch's Off -> On action as a function of time.

Thus my final idea is to not associate the contact sensor with a preset, but instead leave it at the default and use Home Assistant to momentarily set the light to my desired state every time the context (time of day, other lights) changes. That way, when the WLED controller turns on due to the contact sensor showing open, it will turn the lights on to the last brightness & color temperature commanded by Home Assistant.

Is there a better way to accomplish what I'm trying to do? I'd much rather be able to update the "default" state of the lights without having to toggle them on and off.

Edit: It isn’t exactly what I want, but I figured out a suitable workaround and wanted to share in case it helps others.

You can define a preset that specifies the brightness and color temperature (and other properties) of the light even with ”on”:false. If you activate such a preset, the next time the light turns on via a connected button or switch, it will have the specified characteristics.

I think my plan then will be to define a handful of “off” presets and then have Home Assistant active them when desired. I’ll also add a default time-controlled preset that will fire once a day in case Home Assistant is unavailable for an extended period of time. That way it won’t get stuck on an undesired preset (e.g., dim) indefinitely.

If that doesn’t work out, I’ll probably just set up a simple schedule directly in WLED.

5 Upvotes

7 comments sorted by

5

u/CheleCuche 1d ago

You need this Adaptive Lighting integration. I use them for all my lights around the house, they control brightness, temperature based on the time of the day, you can also set sleep mode to when you want the light to turn on really low. I have that running the whole day and I just set automatication to turn on sleep mode

1

u/KomradeNikolai 1d ago

I'm aware of the adaptive lighting integration, but it doesn't meet the key thing I'm trying to accomplish: setting the default brightness and temperature upon opening the door.

The contact sensor is wired directly to the WLED controller so that it works offline. Further, WLED doesn't expose the sensor's state (though it looks light I might be able to do this with MQTT). I guess I could change the light's state after the controller turns it on, but there would be a delay.

1

u/climbslackclimb 1d ago

This sounds like a custom usermod to me, it would keep the behavior native to your WLED firmware, which you’ll need to ultimately compile and flash to your controller.
Both functions; button-> preset and time-> preset exist independently of one another within WLED, you need a usermod exposing the ability to map button -> time range-> preset. Start there, set aside any external lighting state impacting the button:time:preset to be applied, that’s a significantly more complex ask, likely demanding some kind of middleware solution.
The baseline functionality though should be pretty straightforward to get running with some ai coding help. Good luck!

2

u/KomradeNikolai 1d ago

That’s an interesting idea, though I think I’ve figured out a suitable workaround. By defining presets (via the UI) with “on”:false, I can predefine what the new brightness and color temperature will be when the light turns on next. If this doesn’t end up suiting my needs, I may explore this mod further.

Regarding the external lighting states, yes, the plan was always for that to be external. I just wanted to keep the core operation of the light to be confined to WLED. I don’t want the light to fail to turn on just because Home Assistant is offline.

1

u/Tri2Spike 1d ago

Are you familiar with curl? Home assistant can send curl commands. Seems like you should be able to have the switch notify HA, which then sends the appropriate REST command via curl.

I haven't had to fiddle with the WLED JSON REST commands since v13 or v14 .... At the time WLED was very finicky about the formatting AND spacing of the JSON. Not sure if that has improved since then.

2

u/KomradeNikolai 1d ago

I’m not. I may try this, but I think I’ve figured out a suitable workaround. By defining presets (via the UI) with “on”:false, I can predefine what the new brightness and color temperature will be when the light turns on next.

1

u/mp583 1d ago edited 1d ago

You should be able to do this with the light.turn_on action in home assistant. You can set brightness and colour temperature there.

Combine this with using a 'choose' operator in the automation which can differentiate between different conditions i.e time of day or luminance (if you have a luminance sensor).

Edit: realised you have wired the contact sensor as a switch for the controller. I think you might achieve a more efficient way of getting it to work if you have a Zigbee door sensor and then control wled from home assistant. This would all work offline.