Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom turn_on & turn_off services #86

Closed
trevorbenyack opened this issue Feb 9, 2021 · 12 comments · May be fixed by #559 or #561
Closed

Custom turn_on & turn_off services #86

trevorbenyack opened this issue Feb 9, 2021 · 12 comments · May be fixed by #559 or #561

Comments

@trevorbenyack
Copy link

Not sure how feasible this would be, but it'd be great if AL had custom turn_on/_off services that could be called, which would then package the appropriate brightness and color temp into a light.turn_on command and send that to home assistant. I use a lot of motion sensors so if someone hasn't been in the room since it's been light out, there's often a pop of light when motion is triggered b/c the light is turned on first to it's previous state and then quickly adjusted by AL. I know some have their light.turn_on commands packaged with a brightness of 1, but having AL handle the initial turn_on command seems more elegant. Thanks for all your work! Because of your component (and motion sensors) I never have to manually turn on/off or adjust lights anymore!

@trevorbenyack trevorbenyack changed the title Feature Request Feature Request: Custom turn_on & turn_off services Feb 9, 2021
@jackemerson
Copy link

jackemerson commented Feb 9, 2021

Not used it myself, as of yet, but the adaptive_lighting.apply service looks to be what you're after.

@igiannakas
Copy link
Contributor

igiannakas commented Feb 9, 2021

This is what I do to avoid that transition and prime the light with the right colour temp and brightness when turning the lights on using motion sensors. I get no jump in temp or brightness as a result.

service: light.turn_on
data_template:
entity_id: light.corridor_lights
kelvin: >-
{{ state_attr('switch.adaptive_lighting_corridor', 'color_temp_kelvin') |
int }}
brightness_pct: >-
{{ state_attr('switch.adaptive_lighting_corridor', 'brightness_pct') | int
}}

The adaptive light switch needs to be on for the variables colour temp and brightness to be populated.

@trevorbenyack
Copy link
Author

Not used it myself, as of yet, but the adaptive_lighting.apply service looks to be what you're after.

I'll have to test this out. My initial reading of it was that it would operate just like the component normally does (e.g. turn on light, then adapt), but on demand.

@trevorbenyack
Copy link
Author

This is what I do to avoid that transition and prime the light with the right colour temp and brightness when turning the lights on using motion sensors. I get no jump in temp or brightness as a result.

service: light.turn_on
data_template:
entity_id: light.corridor_lights
kelvin: >-
{{ state_attr('switch.adaptive_lighting_corridor', 'color_temp_kelvin') |
int }}
brightness_pct: >-
{{ state_attr('switch.adaptive_lighting_corridor', 'brightness_pct') | int
}}

The adaptive light switch needs to be on for the variables colour temp and brightness to be populated.

I always keep AL on so this should work. Thanks! I'll give it a go!

@jackemerson
Copy link

jackemerson commented Feb 10, 2021

I'll have to test this out. My initial reading of it was that it would operate just like the component normally does (e.g. turn on light, then adapt), but on demand.

Sorry, should have highlighted the turn_on_lights attribute of the service.

turn_on_lights Whether to turn on lights that are currently off.

Behaviour of lights (in general) does seem to vary per brand/model, though. It's good to have finer control in those situations—igiannakas' use of a data template looks perfect for such.

You might also look towards a Template Light, for complete handling of functionality. A little overkill for what I'm doing ... sidesteps much of the convenience afforded by automation and the Adaptive Lighting integration; though—if you've an exact requirement of how entities should behave—it's probably a good fit.

@Slinky-Wrangle-Punch
Copy link

turn_on_lights isn't the perfect solution. My IKEA Tradfri bulbs need separate commands for brightness and color.

When I trigger the adaptive_lighting.apply the two transitions of the service and the two transitions of the initial_transition start and if a transition start while another transition is still ongoing the ongoing transition gets cancelled. And if the timing is bad they cancel each other in a way that bulb does not reach it's final color/brightness.

Is there an easy way to suppress the the initial_transition?

@Slinky-Wrangle-Punch
Copy link

For testing purposes I removed the following call in line 917 in switch.py

await self._update_attrs_and_maybe_adapt_lights(
    lights=[entity_id],
    transition=self._initial_transition,
    force=True,
    context=self.create_context("light_event"),
)

Without this the adaptive_lighting.apply with turn_on_lights works like a charm and just the two service calls for brightness and color are issued.

Does this function call do anything else than the initial_transition? If it's only for the initial_transition than a checkbox in the UI could be added and the function could be called depending on the checkbox.

@trevorbenyack
Copy link
Author

trevorbenyack commented Mar 24, 2021 via email

@KrzysztofHajdamowicz
Copy link

I am also this issue, had a hope zigbee2mqtt will speed things up (compared to Tradfri and Hue), but it's not that much.

It would be great to have a service that preloads light.turn_on with appropriate settings!

@RubenKelevra RubenKelevra changed the title Feature Request: Custom turn_on & turn_off services Custom turn_on & turn_off services Jul 31, 2021
@RubenKelevra RubenKelevra added this to the v2.0 milestone Jan 9, 2022
@RubenKelevra RubenKelevra self-assigned this Jan 9, 2022
@RubenKelevra
Copy link
Collaborator

I'm currently in the process of doing version 2. This will be added/fixed.

Keep this ticket open until you can verify that it's properly working in the upcoming version 2.

@th3w1zard1
Copy link
Collaborator

th3w1zard1 commented Apr 9, 2023

This is currently done/waiting-for-review. I wanted this too so I spent a half hour making it :)

@basnijholt
Copy link
Owner

The problem described by @Slinky-Wrangle-Punch here #86 (comment) is no longer present.

Right now AL will wait for transitions that have been set (thanks to @th3w1zard1! 🎉)

Therefore, I think the request has an existing solution (use adaptive_lighting.apply with turn_on_lights and desired transition). Then just use the normal light.turn_off.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment