basnijholt / adaptive-lighting

Adaptive Lighting custom component for Home Assistant
https://basnijholt.github.io/adaptive-lighting/
Apache License 2.0
1.71k stars 127 forks source link

Allow invoking a script to control the lights #877

Open lbschenkel opened 7 months ago

lbschenkel commented 7 months ago

Some lights are finicky (like the IKEA ones) and require special cases such as separate_turn_on_commands. However, it would be even nicer if it is possible that the user could specify a script that would be invoked to control the lights.

Two use cases to illustrate why that would help:

  1. It's possible to do it nicer for some lights:

    • no IKEA light supports setting brightness+temperate simultaneously if there is a transition (solved by separate_turn_on_commands)
    • however, some IKEA lights do support setting temperature while the light is off
    • the above open us the possibility of a nicer workaround when turning on lights: 1. set the temperature while the light is off, 2. fade it to the desired brightness with transition
    • unfortunately, Home Assistant doesn't let you set the temperature without turning on the light (you can only do it via light.turn_on)
    • when using Zigbee2MQTT it's possible to do it by sending a MQTT message to set the temperature without changing the on/off state, then using light.turn_on to set the brightness
  2. It's possible to implement alternative "separate_turn_on" mechanisms:

    • turn on light at minimum brightness at the desired temperature with no transition (the sudden shift in temperature happens with a very dim light, may not be noticeable depending on the light)
    • fade light to desired brightness with transition

I have personally done both the above in my house via my own customized turn_on script. To make Adaptive Lighting call my script I had to create templated versions of the lights which invoke the script, and configured AL to use those. That works but it's a bit of unnecessary extra work. If AL allowed specifying a custom script as the turn_on mechanism, this would be perfect.

This would be a mechanism for advanced users of course, but still very helpful because in practice what we're doing is extending AL slightly without changing the component itself. If new lights require odd workarounds, or it turns out there's a better way to handle some lights, this could be implemented first by the users themselves via a custom script without requiring changes to the component. AL can still implement itself the most common workarounds (such as separate_turn_on_commands) but still allow the user to have flexibility for the niche stuff that can't be upstreamed (such as the IKEA functionality above that is not achievable via HA service calls only).

What do you think?