Thank you so much, I wish this was natively supported.
Can anybody add support for color changing to @aa755ās /light/tplink.py?
I think its simply a matter of adding the code for RGB support in that one file.
I made a repository with my changes added in. Please help me test.
- Added /light/tplink.py
- Added āfutureā to the list of requirements in setup.py
Got it working now, but putting the bulb in a group allows me only to switch the light on, the switch then automatically moves to the off position again while the light stays on.
But itās not a real toggle functionality either because clicking it again doesnāt switch the light off.
Any hints or am I just thinking too simplistic?
That is strange.
Could you show me how your defining the bulb in your configuration.yaml?
Also, check for any errors in the hass terminal.
Thatās the content of the configuration.yaml:
light:
- platform: tplink
host: 192.168.7.64
name: FrontDoorLight
- platform: tplink
host: 192.168.7.65
name: PatioLight
And this is from groups.yaml:
light_stuff:
name: Lights
entities:
- light.FrontDoorLight
- light.PatioLight
Looks good from configuration standpoint, could you upload your console log so I can check for errors?
Just noticed a very strange behavior:
When I restart HASS while a light is on it doesnāt show up as a current entity.
The only chance to āget it backā is by switching it off and re-starting HASS.
Calling the service from the dev-service by using
Domain: light
Service: toggle
Service Data:
{
"friendly_name": "PatioLight",
"supported_features": 3
}
results in this log entry:
17-04-07 19:19:48 ERROR (MainThread) [homeassistant.core] Invalid service data for light.toggle: extra keys not allowed @ data['friendly_name']. Got 'PatioLight'
extra keys not allowed @ data['supported_features']. Got 5
Using the switch in the UI results in this log entry:
17-04-07 19:25:53 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/usr/lib/python3.4/asyncio/tasks.py", line 233, in _step
result = coro.throw(exc)
File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/core.py", line 1010, in _event_to_service_call
yield from service_handler.func(service_call)
File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/light/__init__.py", line 263, in async_handle_light_service
yield from update_coro
File "/usr/lib/python3.4/asyncio/futures.py", line 388, in __iter__
yield self # This tells Task to wait for completion.
File "/usr/lib/python3.4/asyncio/tasks.py", line 286, in _wakeup
value = future.result()
File "/usr/lib/python3.4/asyncio/futures.py", line 277, in result
raise self._exception
File "/usr/lib/python3.4/asyncio/tasks.py", line 237, in _step
result = next(coro)
File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/helpers/entity.py", line 246, in async_update_ha_state
attr = self.state_attributes or {}
File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/light/__init__.py", line 362, in state_attributes
value = getattr(self, prop)
File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/light/tplink.py", line 82, in color_temp
return kelvin_to_mired(self.smartbulb.color_temp)
File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/util/color.py", line 388, in color_temperature_kelvin_to_mired
return 1000000 / kelvin_temperature
TypeError: unsupported operand type(s) for /: 'int' and 'NoneType'
Found a way to turn the lights off again and changing brightness - only both at the same time, though:
From this Stack Overflow question:
Iād say you should replace the line
return 1000000 / kelvin_temperature
with:
if kelvin_temperature != None:
return 1000000 / kelvin_temperature
This will check if kelvin_temperature is none (in case your bulb doesnāt support it), and only run it if the bulb has it. Thus, any bulbs that donāt have it will not run it unlike before.
Could you try making this change to color.py? It should be near the bottom of the file. Iāll also add this to my GitHub repo as well.
Iām assuming youāre using a non-tunable bulb, thatās why. Itās trying to set the color on a bulb you canāt set the color for. Once you add the if statement it will prevent it from doing so if the bulb does not support it.
Replacing the != 0:
I had in there before with != None:
did the trick - fantastic!
Thanks for your help & patience & quick replies
FYI:
Iām using an LB100 and an LB110.
No problem. I really wanted to make this work, because TP-Link is a very good quality brand. Their products work better then Wemo and better then Phillips while somehow being cheaper.
Note: There is a known issue with bulbs that it takes about 15 seconds to update if it is switch on/off with something other then HASS (e.g. Amazon Echo)
I edited my original ā100% Fixā response to include the new code, editing my GitHub repo now.
I suggest filing a bug report about the divide-by-zero error in homeassistant/util/color.py
.
Any news on this? I created a PR for adding support for controlling the bulbs with pyhs100 tool, all feedback & testing (please report back to that PR) would be appreciated, unfortunately I donāt have those bulbs available: https://github.com/GadgetReactor/pyHS100/pull/50
Is anyone working into getting this to be natively supported in Home Assistant? I can help. Iām a newby on home assistant development, but I have a solid python base. I also have a LS130 smart bulb to test.
@teprrr, if you tell me a bit more on what and how you want HS100 tested, I can help.
Decided to dive in on this with TP-Link LB100 and LB130. I have installed the HASSbian 1.22 with samba and mosquito. On first boot every thing looks to be ok and even pulls up my Direct Tv boxes. I have tried to follow the directions here but canāt seem to get it to work. Iām not 100% sure I put tp Link.py in the right place. Can I get a step by step instructions on how to do this. (full paths). Iām not new to programming but Iām no expert. Any help will be grateful. Thanks in advance.
After upgrading to Home Assistant 0.45.1, the tplink.py provided by @aa755 goes wrong saying
File "/home/homeassistant/.homeassistant/custom_components/light/tplink.py", line 97, in update
raspberrypi hass[30734]: from pyHS100 import (SmartBulb, SmartPlugException)
raspberrypi hass[30734]: ImportError: cannot import name 'SmartPlugException'
Iām not familiar with python so after some stackoverflow search, I made changes to ādef update(self)ā:
def update(self):
from pyHS100 import SmartBulb
"""Update the TP-Link switch's state."""
try:
self._state = self.smartbulb.state == self.smartbulb.BULB_STATE_ON
except:
pass
Then it works pretty well. If thereās better way to fix it, please tell me.
Or maybe itās just me having problem on Home Assistant 0.45.1 with the tplink.py ?
Iām certainly no expert but I ran into this same problem after the most recent upgrade. Part of the issue lies here: https://github.com/GadgetReactor/pyHS100/pull/61
It would seem that they changed the API and the tplink.py script has not been updated to deal with that. My woefully inadequate python skills have yet to come up with a solution. Though Iāll keep at it. These are great lights especially for the money.
SmartPlugException should be still in there (assuming you are running a release instead of git version), as there has been no releases since April. Anyone willing to put some effort to get the bulb component integrated into the official homeassistant? @nate123?
After a new release of pyhs100 will be made, both the switch and the bulb component has to be updated accordingly, and it would be easier to avoid breaking things when both components would be in the official repository.
Sure, I can open up a pull request since I already have it ready.
The basic On/Off functionality is working on both of my LB120 bulbs, but brightness and color temperature are not functioning properly.