TP-Link HS220 Dimmer

I can test too but don’t know how or what to do

The testing this is a bit more involved than a custom component, and is simplest done if you are using/used to virtualenv-based systems which will keep your regular system intact. The basic procedure is somewhat following (with the same user homeassistant is normally run):

<first, stop running homeassistant instance>
$ virtualenv testenv
$ source testenv/bin/activate
$ pip install -e git+https://github.com/rytilahti/home-assistant.git@tplink_unique_id#egg=homeassistant
<wait for install to complete>
$ hass

After homeassistant has started, you need to go to Configuration -> Integrations to activate the integration, which will then automatically discover your devices.

The configuration has changed, the PR has a configuration example (in case the autodetection is not wanted, or not working), more in https://github.com/home-assistant/home-assistant.io/pull/7338 .

After testing you can simply remove the testenv directory to get rid of it and relaunch the regular homeassistant instance.

Im running my homeassistant in a docker container so i dont think that will really work for me… any way to start it up using docker in a new container?

this is basically the commands i run to uninstall and pull the latest updated docker container for homeassistant…

docker stop home-assistant
docker rm home-assistant -f
docker container prune -f
docker volume prune -f
docker image prune -a -f
docker pull homeassistant/home-assistant

docker run -d --name=“home-assistant” -v /usr/share/hassio/homeassistant:/config -v /etc/localtime:/etc/localtime:ro --net=host homeassistant/home-assistant

You would need to check out that PR branch, and build a container manually from it. Unfortunately I have no idea how that should be done properly (docker build and then launching the built container?). If someone knows how to do that, it would be nice to have it documented in homeassistant’s docs as it would be useful for other testers, too.

Any update on this? I’m looking forward to it

1 Like

I’ve been trying to read some posts about similar questions but nothing I can really understand fully

Seems like if you submit the PR there is testing already

but then I also read something about TOX …which I guess is some unit testing tool or something

I have just picked up one of these dimmers and would be willing to test, how do I get the tplink.py script for install/activation?

Any updates on this and when it will be available?

It will be available when it’s ready. I created the necessary tests and there should be only one showstopper (unloading & reloading the discovery on the configuration page) anymore to get this merged. It would still be nice if someone could test it, I have just a single plug I have used to test it, and sofar no one has reported back if it is working or not with the 220.

@teprrr I managed to get it to work with the 220. I wasn’t able to do custom components, so I just edited the files on my mac and the 220 showed up as lights.

You are using the files from the PR? It should now work as a custom component simply by copying the complete tplink directory under your custom_components, as far as I know. You may need to move light/tplink.py and switch/tplink.py away for testing to avoid naming conflicts as these are now contained inside the component itself.

I’ve merged the files into my Home Assistant install, the 220 shows up as a light but since it’s internally a SmartPlug, it’s missing a bunch of attributes such as is_variable_color_temp, is_color, BULB_STATE_ON, etc. I understand it’s a switch with a light-like interface but am not sure if I’m missing something to get this to work?

Any updates to this switch? It looks like a good WiFi Value dimmer/switch.

Does the dimmer support colors in some form? What exactly is not working at the moment?

Anyway, could you checkout this PR API and tests cleanup by rytilahti · Pull Request #151 · GadgetReactor/pyHS100 · GitHub and execute pyhs100 dump_discover and paste the output / add it to an issue of that repository.

Just adding my support and request for this dimmer to be added to HA. I have installed two so far and they work very well. Did not understand that they were not fully supported at the time I purchased. Will be waiting patiently to see if support arrives!

Heywood

Sorry for the late reply; I’ve checked out the PR and commented there with the output of the script.

The dimmer doesn’t support colours. The dimmer does shows up in Home Assistant, but I cannot do anything with it. When I click the dimmer to turn it on, the UI shows Failed to call service light/turn_on. This is the traceback:

Error handling message: {'type': 'call_service', 'domain': 'light', 'service': 'turn_on', 'service_data': {'entity_id': 'light.living_room_left_dimmer'}, 'id': 36}
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/websocket_api/decorators.py", line 17, in _handle_async_response
    await func(hass, connection, msg)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/websocket_api/commands.py", line 148, in handle_call_service
    connection.context(msg))
  File "/usr/local/lib/python3.6/site-packages/homeassistant/core.py", line 1126, in async_call
    self._execute_service(handler, service_call))
  File "/usr/local/lib/python3.6/site-packages/homeassistant/core.py", line 1148, in _execute_service
    await handler.func(service_call)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/light/__init__.py", line 287, in async_handle_light_on_service
    await light.async_turn_on(**pars)
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/tplink/light.py", line 114, in turn_on
    self.smartbulb.state = self.smartbulb.BULB_STATE_ON
AttributeError: 'SmartPlug' object has no attribute 'BULB_STATE_ON'

I’ll poke at the code a little more and see what’s going on in the meantime. Thanks for all the work you’ve put into this!

Bit more info after poking around: if I set the HS220 as a light in HA’s config, this is the error:

Unable to initialize light 192.168.1.200: Error on smartlife.iot.smartbulb.lightingservice.get_light_state: {'err_code': -1, 'err_msg': 'module not support'}

which is why I set the dimmer as a switch instead in the config. But then the code checks whether it has an is_dimmable attribute (which it does) then adds the dimmer to the light list. Since the dimmer is a SmartPlug internally, it lacks all those variables I mentioned before in light.py. I edited the code to force the dimmer to be added to the switch list and now it appears under the switch list can be turned on and off.

Hopefully I didn’t make a mistake anywhere, as a lot of the above was a lot of trial and error.

Also, let me know if you would like some help with coding for the HS220. I also have a HS105. I’m not quite sure how @brycew got the PR to work, I think I have the latest code.

Could you modify the light.py for testing, simply replacing all BULB_STATE_ONs with 'ON' and BULB_STATE_OFF with 'OFF'?

edit: or update from the homeassistant PR, I just changed it there.

It works! I can now turn on/off the lights and also set their brightness :raised_hands:

I did need to change line 225 and line 231 (get_features method) to check for attributes since the SmartPlug object doesn’t have them like so:

def get_features(self):
    """Determine all supported features in one go."""
    self._sysinfo = self.smartbulb.sys_info
    self._supported_features = 0

    if self.smartbulb.is_dimmable:
        self._supported_features += SUPPORT_BRIGHTNESS
    if hasattr(self.smartbulb, 'is_variable_color_temp') and self.smartbulb.is_variable_color_temp:
        self._supported_features += SUPPORT_COLOR_TEMP
        self._min_mireds = kelvin_to_mired(
            self.smartbulb.valid_temperature_range[1])
        self._max_mireds = kelvin_to_mired(
            self.smartbulb.valid_temperature_range[0])
    if hasattr(self.smartbulb, 'is_color') and self.smartbulb.is_color:
        self._supported_features += SUPPORT_COLOR

The dimmer only works if configured as a switch though, not a light (appears as unavailable). Discovery set to true works fine. I’ll take a look later to see if I can figure out why setting as light doesn’t work. Or maybe it’s supposed to be that way? I got confused since the dimmers show up as lights in the UI.

Glad to hear you got it working! The interface is a bit messy and I’ll be adding those missing properties to the backend library, but for now they need to be checked like that. I’ll update the PR when I find some time to do it.

It must be currently defined as a switch in the configuration (when configuring it manually), but the homeassistant should automatically set it up as a light. Is that not happening?