home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
72.02k stars 30.17k forks source link

TP Link KL430: Service Call>Light.TurnOn>Transition Has Never Worked #92265

Closed SergeantPup closed 1 year ago

SergeantPup commented 1 year ago

The problem

@bdraco and I talked about this forever ago.

The light.turnon>transition for TP Link KL430 has never worked inside Home Assistant. My best recollection is we couldn't get this information out of TP Link (I tried too). I think it's working, but our human eyes can't tell.

from this TP link documentation: https://python-kasa.readthedocs.io/en/latest/smartlightstrip.html 2023-04-29 16_37_46-Greenshot The command needs to be in milliseconds. Home Assistant is sending it in seconds and maxes out at 300 milliseconds. which is 0.3 seconds. So even by me having this maxed out in home assistant, there's visually no difference because it's changing in 1/3 of a second.

The problem is that the light.turnon transition function doesn't work for KL430's but I think it might actually be working and we can't tell nor send a millisecond value high enough.

What version of Home Assistant Core has the issue?

2023.5.0b3

What was the last working version of Home Assistant Core?

None

What type of installation are you running?

Home Assistant OS

Integration causing the issue

TPLink Kasa

Link to integration documentation on our website

https://www.home-assistant.io/integrations/tplink/

Diagnostics information

I think the best way to test this against my theory is to send something like 20,000 milliseconds and see if the behavior changes. This is the first time I've seen transition acknowledged in their documentation and from reading it, this should work.

Example YAML snippet

N/A

Anything in the logs that might be useful for us?

No response

Additional information

No response

home-assistant[bot] commented 1 year ago

Hey there @rytilahti, @thegardenmonkey, mind taking a look at this issue as it has been labeled with an integration (tplink) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `tplink` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign tplink` Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


tplink documentation tplink source (message by IssueLinks)

rytilahti commented 1 year ago

The conversion to milliseconds is done in _async_extract_brightness_transition and should work as expected.

Now, how the transitions work depends on the device. The device I have used for developing and testing is my KL130, which allows smooth long turn offs but the transitions for turn ons is capped somewhere near 3-4s or in that ballpark, maybe turning the light smoothly on is a more complicated process or maybe the firmware is just buggy, who knows?

Now to your issue, is it also not working for turning off? Could you test if you have smooth transitions when using a transition of 2 seconds for both? If it is not working at all, we should remove that feature flag for the KL430 (or all light strips, if this is a LED limitation?).

For testing, you could install the python-kasa and play around using the kasa command line tool to control your device to figure out what is working and what is not working. It uses the device native milliseconds for the transitions, so kasa --host <addr> --type bulb off --transition 10000 and kasa --host <addr> --type bulb on --transition 10000 could be used to request 10s transitions.

SergeantPup commented 1 year ago

Hi thanks for the response.

I tested these scenarios: Turn on KL430 with 5 second transition and it turns on instantly Turn off KL430 with 5 second transition and it turns off instantly (this is consistent with all my programming experience with kl430 in home assistant)

To further validate what you said on the KL130 Turn on KL130 with 20 second transition works as expected Turn off KL130 with 20 second transition works as expected Change KL130 color with 20 second transition works as expected

Comparing how the two work, I can unequivocally say that the KL430 doesn't behave the same way as the KL130 given the same transition commands but we know transition is an integral part of the scripts/effects to run on the KL430's (which we've had working for a year)

For the last part, I'll have to research how to get python-Kasa. I've seen it mentioned in the threads for years but haven't had the pleasure of using it yet.

SergeantPup commented 1 year ago

also, in my search for Python Kasa, I found somebody hypothesizing the same thing with more detail back in march: https://community.home-assistant.io/t/kasa-bulbs-transition-time/161615/7?u=sergeantpup I tried this in dev tools with 10,000 for ms and it was still instant

rytilahti commented 1 year ago

The handling of effects differs from regular turn on and turn off commands, so if transitions for regular turn ons and offs are doable using the official app, this is something that could be fixed when someone figures out what's the problem.

The comment you linked is from me and it's a different issue, I edited the comment to include a link to the PR that fixed the unit issue, thanks for bringing that up! :-)

SergeantPup commented 1 year ago

The handling of effects differs from regular turn on and turn off commands, so if transitions for regular turn ons and offs are doable using the official app, this is something that could be fixed when someone figures out what's the problem.

I'm not aware of any Native TP Link app functionality that allows you to set the transition of bulbs or strips. It's just a slider and where you select last is where the lights go. I'm not aware of a way to transition KL130's from the TPlink app like I just did with home assistant (change the bulb to blue over 20 seconds or turn off over 20 seconds), so I'm not sure how I can try it without HA. I tried to do this in tp link smart actions with a 'duration' button but that's literally what that button is. I couldn't find a way to transition any bulb or lightstrip natively in TP link. So best I can see is inconclusive until I can find the functionality for 1 of them.

rytilahti commented 1 year ago

I think this is then a hardware limitation of the led strips, so I suppose the integration should not advertise that it supports transitions for those devices. I have a feeling that this is a hardware limitation and there is nothing else we can do about it, sorry!

raphaelmaenle commented 1 year ago

Hello, I didn't want to create a unique issue for this; this is the closest one I found regarding Transition issues with KL430.

Using the python-kasa library, I found that Transitions (when the LED's fade) can be used, but only coming from effects which are type: "random", not type "sequence".

For example, this successfully 'dimms' the lights, before turning them off:

      effect_running = {'custom': 0,·                                                                                     
                        "id": "CdLeIgiKcQrLKMINRPTMbylATulQewLD",                                                         
                        "brightness": 100,                                                                                
                        "name": "Hanukkah",                                                                               
                        "segments": [1],                                                                                  
                        "expansion_strategy": 1,                                                                          
                        "enable": 1,                                                                                      
                        "type": "random",                                                                                 
                        "hue_range": [210, 210],                                                                          
                        "duration": 1500,                                                                                 
                        "transition": 0,                                                                                  
                        "transition_range": [400, 500],                                                                   
                        "init_states": [[35, 81, 80]],                                                                    
                        }                                                                                                 

      dev = SmartLightStrip(ip_address)       
      await dev.update()    
      await asyncio.sleep(0.5)                                                                                                                                                                      
      await dev.set_brightness(brightness=100, transition=2000)                                                           
      await asyncio.sleep(2)                                                                                              
      await dev.set_custom_effect(effect_running)                                                                         
      await asyncio.sleep(5)                                        
      await dev.set_brightness(brightness=1, transition=2000)                                                             
      await asyncio.sleep(2)                                                                                              
      await dev.turn_off()    

While the same setup but with a different effect does not transition the lights, but instead makes them 'jump' to the new brightness immediately, for example:

      aurora = {                                                                                                          
              "custom": 0,                                                                                                
              "id": "CdLeIgiKcQrLKMINRPTMbylATulQewLD",                                                                   
              "brightness": 100,                                                                                          
              "name": "Hanukkah",                                                                                         
              "segments": [0],                                                                                            
              "expansion_strategy": 1,                                                                                    
              "enable": 1,                                                                                                
              "type": "sequence",                                                                                         
              "duration": 0,                                                                                              
              "transition": 1500,                                                                                         
              "direction": 4,                                                                                             
              "spread": 7,                                                                                                
              "repeat_times": 0,                                                                                          
              "sequence": [[37, 100, 100], [25, 100, 100], [50, 100, 100], [55, 100, 100]],                               
              }  

Disregard ID and Name, these should be of no issue.

Is there already a way to reflect this behavior in home-assistant? The same setup would also allow for a fade-in, as long as the last effect sent to the device is of type 'random'.

This might be used as a work-around to allow for some fade-in fade-out behavior these light-strips are currently missing.

Has anyone been down this path already?

raphaelmaenle commented 1 year ago

This effect is also observable in the Kasa Application, where the change of the brightness value results in the LEDs having some transition time, if the currently running animation is an effect which is of type 'random', instead of sequence. Also, when constructing the same scenario in Home Assistant, there is a transition.

As far as I can tell, there is no way to create a custom effect in home assistant, is that correct?

SergeantPup commented 1 year ago

Yes but, through scripts. Take one of the existing sequential or random effects and then change the effects how you want them. I do this to slow the animations as slow as they'll go and to hardcode the default brightness of effects to a lesser value.

Is there a cleaner way to make custom effects in the UI? No, its a highly requested feature.

Last I knew, we had some approaches from other custom effect lights like nanoleaf, cololight, and I forget the other one and folks were casually seeing if some of that could be adapted for kl430. The part folks really want is color painting.

issue-triage-workflows[bot] commented 1 year ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.