Trying to expand tellduslive support

Hi!

I am trying to understand how the telldus live component can be improved to not only support switches and sensors, but also up, down, dim etc. I am new to this but trying to understand.

I have added a roller shutter to my telldus live account. It gets discovered in HA as a switch.
When I try to use it as a switch in HA, I get this in the log:

16-08-29 14:31:03 homeassistant.core: BusHandler:Exception doing job
Traceback (most recent call last):
File “/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/core.py”, line 852, in job_handler
func(*args)
File “/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/core.py”, line 717, in _execute_service
service(call)
File “/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/core.py”, line 572, in call
self.func(call)
File “/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/components/switch/init.py”, line 88, in handle_switch_service
switch.turn_off()
File “/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/components/switch/tellduslive.py”, line 71, in turn_off
tellduslive.NETWORK.turn_switch_off(self._id)
File “/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/components/tellduslive.py”, line 183, in turn_switch_off
if self._check_request(“device/turnOff”, id=switch_id):
File “/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/components/tellduslive.py”, line 164, in _check_request
response = self.request(what, **params)
File “/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/components/tellduslive.py”, line 125, in request
response = self._client.request(what, params)
File “/home/hass/.homeassistant/deps/tellive/client.py”, line 86, in request
raise TelldusLiveError(values[‘error’])
tellive.client.TelldusLiveError: Device “1252654” does not support method “2”

Metod 2 in this case is “off” and method 1 is “on”. I get the same response if I try to send these commands in tdtool.py.

However if I send up or down in tdtool, it works. Up and down is method 6 and 7.

So I figure it should just be a case of getting the component to send method 6 or 7 instead of 1 and 2.

I think the method is being sent by deps/tellive/client.py in here

def request(self, method, params):
path = “/json/{}?{}”.format(method, urllib.parse.urlencode(params))
response = self._request(path, self.token, self.secret)
values = json.loads(response.read().decode(‘utf-8’))
if ‘error’ in values:
raise TelldusLiveError(values[‘error’])
return values

Any ideas on where I can start?

I’ve found ipython super useful for debugging. You can stick a statement in your code, and able to poke around the environment to see what is going on. Here’s a good summary of using it: http://daguar.github.io/2014/06/05/just-dropped-in-interactive-coding-in-ruby-python-javascript/

You could stick the embed statements in homeassistant or a dependency, ie ~/.homeassistant/deps/tellive.

Hi! I made the initial Telldus Live implementation in Home Assistant. You are very welcome on improving it and adding support for more kinds of devices! At the time of implementation I only had access to basic sensors and switches, which is the reason no other devices are currently supported.

The exception looks like it could be an issue with the used tellive library. However, maybe you first could try to enable the relevant constants in the request method in tellduslive.py and see if that changes anything for you:
https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/components/tellduslive.py#L110

Hm, if I enable up and down constant for example, home assistant won’t even start for some reason, nothing in home assistant.log either…

There is probably some kind of exception raised/thrown, would be interesting to know which one - if you could find it.

I tried this again, and it did start now with the relevant constants enabled in telldyslive. However, my blinds is still showing up as a switch in HA. And therefore sends method 1 and 2.

I guess somehow HA needs to realize that this device is not a switch, but a device that supports up and down (method 6 or 7).

Any further ideas? :slight_smile:

It is hard to debug without having access to the devices. It would be interesting to know what the server returns. If you turn on logging for the tellduslive component, it will print out the communication with the server.

Try adding this to your configuration.yaml:

logger:
  default: info
  logs:
    homeassistant.components.tellduslive: debug
    homeassistant.components.sensor.tellduslive: debug
    homeassistant.components.switch.tellduslive: debug

Here are the relevant parts of the log

16-10-08 13:02:06 homeassistant.components.tellduslive: Updating sensors from Telldus Live
16-10-08 13:02:06 homeassistant.components.tellduslive: got response {‘sensor’: []}
16-10-08 13:02:06 homeassistant.components.tellduslive: Updating switches from Telldus Live
16-10-08 13:02:06 homeassistant.components.tellduslive: got response {‘device’: [{‘name’: ‘Lampa vardagsrum’, ‘clientDeviceId’: ‘8’, ‘methods’: 3, ‘clientName’: ‘Vardagsrum’, ‘client’: ‘115954’, ‘ignored’: 0, ‘online’: ‘1’, ‘id’: ‘1240861’, ‘statevalue’: ‘unde’, ‘editable’: 1, ‘type’: ‘device’, ‘state’: 1}, {‘name’: ‘Rullgardin’, ‘clientDeviceId’: ‘15’, ‘methods’: 3, ‘clientName’: ‘Vardagsrum’, ‘client’: ‘115954’, ‘ignored’: 0, ‘online’: ‘1’, ‘id’: ‘1252654’, ‘statevalue’: ‘0’, ‘editable’: 1, ‘type’: ‘device’, ‘state’: 2}, {‘name’: ‘Sänglampa’, ‘clientDeviceId’: ‘10’, ‘methods’: 3, ‘clientName’: ‘Vardagsrum’, ‘client’: ‘115954’, ‘ignored’: 0, ‘online’: ‘1’, ‘id’: ‘1241508’, ‘statevalue’: ‘38’, ‘editable’: 1, ‘type’: ‘device’, ‘state’: 2}, {‘name’: ‘Taklampa sovrum’, ‘clientDeviceId’: ‘12’, ‘methods’: 3, ‘clientName’: ‘Vardagsrum’, ‘client’: ‘115954’, ‘ignored’: 0, ‘online’: ‘1’, ‘id’: ‘1241702’, ‘statevalue’: ‘234’, ‘editable’: 1, ‘type’: ‘device’, ‘state’: 2}, {‘name’: ‘Vardagsrumslampa hörn’, ‘clientDeviceId’: ‘7’, ‘methods’: 3, ‘clientName’: ‘Vardagsrum’, ‘client’: ‘115954’, ‘ignored’: 0, ‘online’: ‘1’, ‘id’: ‘1239723’, ‘statevalue’: ‘unde’, ‘editable’: 1, ‘type’: ‘device’, ‘state’: 1}, {‘name’: ‘Växtbelysning’, ‘clientDeviceId’: ‘6’, ‘methods’: 3, ‘clientName’: ‘Vardagsrum’, ‘client’: ‘115954’, ‘ignored’: 0, ‘online’: ‘1’, ‘id’: ‘573531’, ‘statevalue’: ‘unde’, ‘editable’: 1, ‘type’: ‘device’, ‘state’: 1}]}
16-10-08 13:02:06 homeassistant.components.tellduslive: discovered 6 new switch devices
16-10-08 13:02:06 homeassistant.core: Bus:Handling <Event platform_discovered[L]: platform=tellduslive, discovered=[‘573531’, ‘1239723’, ‘1241702’, ‘1241508’, ‘1252654’, ‘1240861’], service=load_platform.switch>
16-10-08 13:02:06 homeassistant.loader: Loaded switch.tellduslive from homeassistant.components.switch.tellduslive
16-10-08 13:02:06 homeassistant.components.switch.tellduslive: created switch <Entity Växtbelysning: on>
16-10-08 13:02:06 homeassistant.core: Bus:Handling <Event component_loaded[L]: component=tellduslive>
16-10-08 13:02:06 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=switch.vxtbelysning, old_state=None, new_state=<state switch.vxtbelysning=on; icon=mdi:flower, assumed_state=True, friendly_name=Växtbelysning @ 2016-10-08T13:02:06.680569+02:00>>
16-10-08 13:02:06 homeassistant.core: Bus:Handling <Event component_loaded[L]: component=binary_sensor>
16-10-08 13:02:06 homeassistant.components.switch.tellduslive: created switch <Entity Vardagsrumslampa hörn: on>
16-10-08 13:02:06 homeassistant.core: Bus:Handling <Event platform_discovered[L]: platform=mysensors, discovered=, service=load_platform.binary_sensor>
16-10-08 13:02:06 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=switch.vardagsrumslampa_hrn, old_state=None, new_state=<state switch.vardagsrumslampa_hrn=on; icon=mdi:sofa, assumed_state=True, friendly_name=Sofflampa @ 2016-10-08T13:02:06.698492+02:00>>
16-10-08 13:02:06 homeassistant.components.switch.tellduslive: created switch
16-10-08 13:02:06 homeassistant.loader: Loaded binary_sensor.mysensors from homeassistant.components.binary_sensor.mysensors
16-10-08 13:02:06 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=switch.taklampa_sovrum, old_state=None, new_state=<state switch.taklampa_sovrum=off; assumed_state=True, friendly_name=Taklampa sovrum @ 2016-10-08T13:02:06.776632+02:00>>
16-10-08 13:02:06 homeassistant.components.switch.tellduslive: created switch <Entity Sänglampa: off>
16-10-08 13:02:06 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=switch.snglampa, old_state=None, new_state=<state switch.snglampa=off; icon=mdi:hotel, assumed_state=True, friendly_name=Sänglampa @ 2016-10-08T13:02:06.805153+02:00>>
16-10-08 13:02:06 homeassistant.components.switch.tellduslive: created switch 16-10-08 13:02:06 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=switch.rullgardin, old_state=None, new_state=<state switch.rullgardin=off; assumed_state=True, friendly_name=Rullgardin @ 2016-10-08T13:02:06.831622+02:00>>
16-10-08 13:02:06 homeassistant.components.switch.tellduslive: created switch
16-10-08 13:02:06 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=switch.lampa_vardagsrum, old_state=None, new_state=<state switch.lampa_vardagsrum=on; assumed_state=True, friendly_name=Lampa vardagsrum @ 2016-10-08T13:02:06.854073+02:00>>
16-10-08 13:02:06 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=group.all_switches, old_state=<state group.all_switches=off; entity_id=(‘switch.foscam_motion’,), order=0, friendly_name=all switches, auto=True, hidden=True @ 2016-10-08T13:02:05.958337+02:00>, new_state=None>
16-10-08 13:02:06 homeassistant.core: Bus:Handling <Event service_registered[L]: domain=light, service=turn_on>
16-10-08 13:02:06 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=group.all_switches, old_state=None, new_state=<state group.all_switches=on; entity_id=(‘switch.taklampa_sovrum’, ‘switch.rullgardin’, ‘switch.vxtbelysning’, ‘switch.foscam_motion’, ‘switch.snglampa’, ‘switch.lampa_vardagsrum’, ‘switch.vardagsrumslampa_hrn’), order=0, auto=True, assumed_state=True, friendly_name=all switches, hidden=True @

And here is when trying to switch it in frontend

16-10-08 13:33:34 homeassistant.components.http: Serving /api/services/homeassistant/turn_off to xx.xx.xx.xx (auth: True)
16-10-08 13:33:34 homeassistant.core: Bus:Handling <Event call_service[L]: service_data=entity_id=switch.rullgardin, domain=homeassistant, service_call_id=1977740304-3, service=turn_off>
16-10-08 13:33:34 homeassistant.core: Bus:Handling <Event call_service[L]: service_data=entity_id=[‘switch.rullgardin’], domain=switch, service_call_id=1977740304-4, service=turn_off>
16-10-08 13:33:34 homeassistant.core: BusHandler:Exception doing job
Traceback (most recent call last):
File “/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/core.py”, line 1164, in job_handler
func(*args)
File “/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/core.py”, line 1027, in _execute_service
service(call)
File “/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/core.py”, line 827, in call
self.func(call)
File “/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/components/switch/init.py”, line 88, in handle_switch_service
switch.turn_off()
File “/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/components/switch/tellduslive.py”, line 71, in turn_off
tellduslive.NETWORK.turn_switch_off(self._id)
File “/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/components/tellduslive.py”, line 211, in turn_switch_off
if self._check_request(‘device/turnOff’, id=switch_id):
File “/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/components/tellduslive.py”, line 192, in _check_request
response = self.request(what, **params)
File “/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/components/tellduslive.py”, line 155, in request
response = self._client.request(what, params)
File “/home/hass/.homeassistant/deps/tellive/client.py”, line 86, in request
raise TelldusLiveError(values[‘error’])
tellive.client.TelldusLiveError: Device “1252654” does not support method “2”

Is this with or without your modified version that sets supported_methods to include the TELLSTICK_UP and TELLSTICK_DOWN constants?

Have you tried playing with the API explorer at http://api.telldus.com/explore/devices/list to find out how to diffetrentiate between a switch and a blind/cover?

I get the same log with and without modified version.

I think the way to diffetrentiate between a switch and a blind/cover is to request what methods the device supports. Telldus just sends info on devices and/or sensors. It does not make a difference between switches for example, but in the methods it supports.

If a device returns it supports on and off (method 1 & 2) it’s a switch, if it returns it supports up and down (method 6 & 7) its a blind.

Take a look here at tdMethods():
http://developer.telldus.se/doxygen/

TellStick can control many different types of devices that support different features. For example, a bell does not support turning the on-signal and not all lamp switches support dimming. Call tdMethods() to find out what a specific device supports

I guess this is what needs to be implemented?

In your debug output above, methods: 3 seems to be returned by the server for both your switches as well as for your blinds. So if this does not change regardless if you changed supported_methods as suggested above, I’m not sure how to differentiate between the two kind of devices.

The tdMethods you are referring to is for the Tellstick/Tellstick Duo not, for the Tellstick Net/Telldus Live API.

I suggest you play around with the Telldus Live API explorer I linked above and see if you find something out.

I finally got a good result from the server.

16-10-09 11:57:30 homeassistant.components.tellduslive: got response {‘device’: [{‘methods’: 3, ‘editable’: 1, ‘id’: ‘1240861’, ‘state’: 1, ‘client’: ‘115954’, ‘statevalue’: ‘unde’, ‘online’: ‘1’, ‘clientName’: ‘Vardagsrum’, ‘type’: ‘device’, ‘ignored’: 0, ‘name’: ‘Lampa vardagsrum’, ‘clientDeviceId’: ‘8’}, {‘methods’: 384, ‘editable’: 1, ‘id’: ‘1252654’, ‘state’: 256, ‘client’: ‘115954’, ‘statevalue’: ‘0’, ‘online’: ‘1’, ‘clientName’: ‘Vardagsrum’, ‘type’: ‘device’, ‘ignored’: 0, ‘name’: ‘Rullgardin’, ‘clientDeviceId’: ‘15’}, {‘methods’: 19, ‘editable’: 1, ‘id’: ‘1241508’, ‘state’: 2, ‘client’: ‘115954’, ‘statevalue’: ‘68’, ‘online’: ‘1’, ‘clientName’: ‘Vardagsrum’, ‘type’: ‘device’, ‘ignored’: 0, ‘name’: ‘Sänglampa’, ‘clientDeviceId’: ‘10’}, {‘methods’: 19, ‘editable’: 1, ‘id’: ‘1241702’, ‘state’: 2, ‘client’: ‘115954’, ‘statevalue’: ‘234’, ‘online’: ‘1’, ‘clientName’: ‘Vardagsrum’, ‘type’: ‘device’, ‘ignored’: 0, ‘name’: ‘Taklampa sovrum’, ‘clientDeviceId’: ‘12’}, {‘methods’: 3, ‘editable’: 1, ‘id’: ‘1239723’, ‘state’: 1, ‘client’: ‘115954’, ‘statevalue’: ‘unde’, ‘online’: ‘1’, ‘clientName’: ‘Vardagsrum’, ‘type’: ‘device’, ‘ignored’: 0, ‘name’: ‘Vardagsrumslampa hörn’, ‘clientDeviceId’: ‘7’}, {‘methods’: 3, ‘editable’: 1, ‘id’: ‘573531’, ‘state’: 2, ‘client’: ‘115954’, ‘statevalue’: ‘unde’, ‘online’: ‘1’, ‘clientName’: ‘Vardagsrum’, ‘type’: ‘device’, ‘ignored’: 0, ‘name’: ‘Växtbelysning’, ‘clientDeviceId’: ‘6’}]}

As you can see, the blinds now returns 384 telling it supports up and down (up=128 + down=256) and also dimmable Device returns 19 telling it supports dim, on and off(on=1 + off=2 + dim=16)

:slight_smile:

Also if I change this:

def turn_switch_off(self, switch_id):
    """Turn switch on."""
    if self._check_request('device/turnOff', id=switch_id):
        from tellive.live import const
        self.get_switch(switch_id)['state'] = const.TELLSTICK_TURNOFF

to this:

   def turn_switch_off(self, switch_id):
            """Turn switch on."""
            if self._check_request('device/down', id=switch_id):
                from tellive.live import const
                self.get_switch(switch_id)['state'] = const.TELLSTICK_TURNOFF

Then I can use the off-button in HA to get the blinds down (of course it makes the on/off devices not working cause they don’t support down :))

Perfect, this makes sense. I think we will be able to enhance the Telldus Live support to include dimmers and covers then.

Really good news.
Great work guys.
Can’t wait till this will be available in HA.

Hey All,

Yes I would be VERY interested in seeing this improvement for all device types from Telldus. I have many dimmers and it’s the only thing that’s stopping me using Home Assistant at the moment! Would love to see this fixed.

@molobrakos - It does not matter if you don’t have devices to test with. The nice thing with the Telldus system is you can add a ‘fake’ / dummy device to your Telldus Live account, and see it change in the website. Perhaps this will be enough to expand the component?

I have been trying to compare this component with the tellstick one, and develop it however Python is not my strength - although I think my confusion comes mainly around how the code flows back into the HASS core.

I made an initial implementation here with support for covers/blinds and dimmable lights: https://github.com/home-assistant/home-assistant/pull/4645
Maybe someone with access to actual devices (@olskar, @mitsumaui, @xydix) could test and confirm if it works or not - also patches/bugfixes are welcome.

Awesome - Thanks so much @molobrakos I will download and try. I might come back if I get stuck with trying to pull it for testing. I’m still new to the Linux coding world!

Thanks for the support, it looks like it will be a great addition :), I would try to test it but I have no idea how, when I went to the git site there was no download option :frowning: so I have no idea what to do next?

As I suspected - I am rather stuck with how to pull these files into my environment for testing :blush:

I setup hass using on Ubuntu using the virtualenv setup here.

I managed to download the branch OK (@keithh666 you have to go here) however I have no idea how to ‘inject’ the changed tellduslive.py files into my existing install.

Any advice / support would be appreciated - as reading the dev fork section (info here) I am a little out of my depth!

TIA