Closed maximilianneumann closed 3 years ago
I found that it is a conversion error, between mired and kelvin. The bulb can go to 6500 kelvin. The closest value that worked for me was 6493 kelvin, anything above crashes the bulb.
I need to understand if is a problem related to this plugin or the problem is inside the plugp100 that manage decryption and encryption.
You can try to use this snippet of code to see if the lamp turn on to 6500K or if the library report an error. First install the library using python pip: pip install plugp100==2.1.5
.
After that try this snippet:
import asyncio
from plugp100 import TapoApiClient, TapoDeviceState
async def main():
# create generic tapo api
client = TapoApiClient('lamp_ip', 'tapo_username', 'tapo_password')
await client.login()
await client.on()
await client.set_color_temperature(6500)
print(await sw.get_state())
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
loop.run_until_complete(asyncio.sleep(0.1))
loop.close()
Thanks for support :)
I have tried it, but I can't get a connection to that bulb. Also can't ping it. All other devices respond to pings, even tapo plugs. That is what I got:
Traceback (most recent call last):
File "/home/maximilian/.local/lib/python3.8/site-packages/aiohttp/connector.py", line 969, in _wrap_create_connection
return await self._loop.create_connection(*args, **kwargs) # type: ignore # noqa
File "/usr/lib/python3.8/asyncio/base_events.py", line 1025, in create_connection
raise exceptions[0]
File "/usr/lib/python3.8/asyncio/base_events.py", line 1010, in create_connection
sock = await self._connect_sock(
File "/usr/lib/python3.8/asyncio/base_events.py", line 924, in _connect_sock
await self.sock_connect(sock, address)
File "/usr/lib/python3.8/asyncio/selector_events.py", line 494, in sock_connect
return await fut
File "/usr/lib/python3.8/asyncio/selector_events.py", line 526, in _sock_connect_cb
raise OSError(err, f'Connect call failed {address}')
OSError: [Errno 113] Connect call failed ('192.168.178.36', 80)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "test.py", line 13, in <module>
loop.run_until_complete(main())
File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
return future.result()
File "test.py", line 7, in main
await client.login()
File "/home/maximilian/.local/lib/python3.8/site-packages/plugp100/api.py", line 69, in login
await self._handshake()
File "/home/maximilian/.local/lib/python3.8/site-packages/plugp100/api.py", line 138, in _handshake
response = await self.http.async_make_post(self.url, json=request_body)
File "/home/maximilian/.local/lib/python3.8/site-packages/plugp100/core/http_client.py", line 13, in async_make_post
async with self.session.post(url, json=json) as response:
File "/home/maximilian/.local/lib/python3.8/site-packages/aiohttp/client.py", line 1117, in __aenter__
self._resp = await self._coro
File "/home/maximilian/.local/lib/python3.8/site-packages/aiohttp/client.py", line 520, in _request
conn = await self._connector.connect(
File "/home/maximilian/.local/lib/python3.8/site-packages/aiohttp/connector.py", line 535, in connect
proto = await self._create_connection(req, traces, timeout)
File "/home/maximilian/.local/lib/python3.8/site-packages/aiohttp/connector.py", line 892, in _create_connection
_, proto = await self._create_direct_connection(req, traces, timeout)
File "/home/maximilian/.local/lib/python3.8/site-packages/aiohttp/connector.py", line 1051, in _create_direct_connection
raise last_exc
File "/home/maximilian/.local/lib/python3.8/site-packages/aiohttp/connector.py", line 1020, in _create_direct_connection
transp, proto = await self._wrap_create_connection(
File "/home/maximilian/.local/lib/python3.8/site-packages/aiohttp/connector.py", line 975, in _wrap_create_connection
raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host 192.168.178.36:80 ssl:default [Connect call failed ('192.168.178.36', 80)]
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7f64cef1f5e0>
Now it worked, bulb gets set to that color and returns:
dedd12f214dc97c2992d6f8800f8667107e52fd9
Traceback (most recent call last):
File "test.py", line 13, in <module>
loop.run_until_complete(main())
File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
return future.result()
File "test.py", line 10, in main
print(await sw.get_state())
NameError: name 'sw' is not defined
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7f740d0b25e0>
Unclosed connector
connections: ['[(<aiohttp.client_proto.ResponseHandler object at 0x7f740c41d160>, 1377.160392955)]']
connector: <aiohttp.connector.TCPConnector object at 0x7f740d0b2e50>
Edit: and I can see that it is set to exactly 6500k
Now it worked, bulb gets set to that color and returns:
dedd12f214dc97c2992d6f8800f8667107e52fd9 Traceback (most recent call last): File "test.py", line 13, in <module> loop.run_until_complete(main()) File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete return future.result() File "test.py", line 10, in main print(await sw.get_state()) NameError: name 'sw' is not defined Unclosed client session client_session: <aiohttp.client.ClientSession object at 0x7f740d0b25e0> Unclosed connector connections: ['[(<aiohttp.client_proto.ResponseHandler object at 0x7f740c41d160>, 1377.160392955)]'] connector: <aiohttp.connector.TCPConnector object at 0x7f740d0b2e50>
Edit: and I can see that it is set to exactly 6500k
Sorry in my snippet is use sw instead client, change to print(await client.get_state())
dedd12f214dc97c2992d6f8800f8667107e52fd9
TapoDeviceState(device_id='8023A49C5363B18E80E34A4F1ABCA91B1DB7BA17', nickname='Tapo Bulb L530', model='L530 Series', type='SMART.TAPOBULB', device_on=True, brightness=100, hue=None, saturation=None, color_temp=6500, overheated=False, signal_level=3, rssi=-42)
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7f26473ed580>
Unclosed connector
connections: ['[(<aiohttp.client_proto.ResponseHandler object at 0x7f2646757160>, 2152.327599913)]']
connector: <aiohttp.connector.TCPConnector object at 0x7f26473eddf0>
I have checked the code: the mired and kelvin are correctly converted, but there is a problem related to approximation. 6500k
are converted into 153.84 mired
, because home assistant kelvin_to_mired
is implemented as follows:
def color_temperature_kelvin_to_mired(kelvin_temperature):
"""Convert degrees kelvin to mired shift."""
return 1000000 / kelvin_temperature
This means that GUI show the coolest option as 153 (due approximation), but the conversion from kelvin to mired, is implemented as follows:
def color_temperature_mired_to_kelvin(mired_temperature):
"""Convert absolute mired shift to degrees kelvin."""
return 1000000 / mired_temperature
That return a value higher than 6500K for 153 as mired, this cause the crash of the lamp. Now I will check my clamp function that was meant to prevent this situation.
Anyway, I think that in your log there is some problem related to #23
Thanks for working on that :)
It might be related. But for #23 I have posted the complete log, where I only flip the switches until the error occurred.
Try to update the integration from hacs, the fix should work :)
Yes it works!
Thank you :)
ps: do you have any idea for #23 ?
Version of the custom_component
v1.0
Describe the bug
Tapo Bulb L530 set to cool white makes it unavailable. When the slider is set to the coolest setting (153), the bulb becomes unavailable. Sometimes it will be back after a few minutes or after a restart.
Debug log