TP-Link HS220 Dimmer

@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?

How are these at dimming LED’s? I have found that Insteon and ZWave dimmers will dim LED’s somewhat (~50%) but not nearly as much as I would like. The only switches I’ve found that really work well at dimming LED’s are Lutron dimmers. I haven’t wanted to pay the $100 for the nice Lutron Caseta controllable swiches so I just use non-controllable dimmers at this point. I’m still hoping someone makes a remote controllable switch that can dim an LED down to low (10-20%) output.

What you described is what’s happening. Was just confused that when configured as switch it shows up as light. It’s all good then!

I wouldn’t say they dim down all the way but mine seem to go down to 30 percent without flickering. Took the screenshot below from the Kasa app that comes with the dimmer.

Patiently (not really) waiting for this to be merged. A number of my automations rely on my ability to set brightness and without it they’re substantially less useful.

I’m still relatively new here and don’t have a lot of experience with PRs. Someone above mentioned using the files from the PR to do a custom component. Can someone explain which files I’m supposed to copy to my /custom_components directory?

Also, regarding dimming %, I’m able to get mine very low without any flicker or buzzing. The app allows you to calibrate (as seen above) and mine dims low enough to barely have any visible light output. Very satisfied with these dimmers (I have 4 throughout the house)

Today’s HA update says it pulls the new pyHS100 library.
Does this change anything for you?

The original PR got merged yesterday, but until the HS220 works fine, https://github.com/home-assistant/home-assistant/pull/21309 needs also get merged. After that HS220 should work out-of-the-box!

2 Likes

Hey-

Did you manage to find out how to incorporate the PR in advance on the merge?

Heywood

No, no luck, but I haven’t had a ton of time to play around with it. Any attempt I’ve made to use it as a light shows unavailable.

I haven’t tried it out, but copying the whole directory from the current git master (https://github.com/home-assistant/home-assistant/tree/dev/homeassistant/components/tplink) under custom_component should work. If that doesn’t directly work, then it may be necessary to remove light/tplink.py and switch/tplink.py from the installation.

Then either going to configuration -> integrations and selecting tplink smart home to autodetect the devices, or for manual configuration see https://github.com/home-assistant/home-assistant.io/blob/next/source/_components/tplink.markdown . The HS220 has to be defined as a switch, but it will appear as light inside homeassistant (to allow brightness control).