Velux Component for KLF 200 problem

Hi! I try to geht the Velux component on HassIO to work. I’ve configured the Velux KLF200 and it works at its own as it should. But the Velux Component reports an error. I have not changed the default password of the KLF200 and I am sure that I’ve configured the component properly. Any idea how to fix this?

2017-10-18 19:42:20 ERROR (MainThread) [homeassistant.components.velux] Can't connect to velux interface: Invalid Token
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/homeassistant/components/velux.py", line 37, in async_setup
    yield from hass.data[DATA_VELUX].async_start()
  File "/usr/lib/python3.6/site-packages/homeassistant/components/velux.py", line 66, in async_start
    yield from self.pyvlx.load_scenes()
  File "/usr/lib/python3.6/site-packages/pyvlx/pyvlx.py", line 24, in load_scenes
    await self.scenes.load()
  File "/usr/lib/python3.6/site-packages/pyvlx/scenes.py", line 37, in load
    json_response = await self.pyvlx.interface.api_call('scenes', 'get')
  File "/usr/lib/python3.6/site-packages/pyvlx/interface.py", line 17, in api_call
    await self.refresh_token()
  File "/usr/lib/python3.6/site-packages/pyvlx/interface.py", line 62, in refresh_token
    json_response = await self.api_call('auth', 'login', {'password': self.config.password}, add_authorization_token=False)
  File "/usr/lib/python3.6/site-packages/pyvlx/interface.py", line 20, in api_call
    return await self.api_call_impl(verb, action, params, add_authorization_token)
  File "/usr/lib/python3.6/site-packages/pyvlx/interface.py", line 34, in api_call_impl
    return await self.do_http_request(url, body, headers)
  File "/usr/lib/python3.6/site-packages/pyvlx/interface.py", line 39, in do_http_request
    return await self.do_http_request_impl(url, body, headers)
  File "/usr/lib/python3.6/site-packages/pyvlx/interface.py", line 56, in do_http_request_impl
    self.evaluate_response(json_response)
  File "/usr/lib/python3.6/site-packages/pyvlx/interface.py", line 94, in evaluate_response
    Interface.evaluate_errors(json_response)
  File "/usr/lib/python3.6/site-packages/pyvlx/interface.py", line 112, in evaluate_errors
    raise InvalidToken(first_error)
pyvlx.exception.InvalidToken: Invalid Token
2017-10-18 19:42:20 ERROR (MainThread) [homeassistant.setup] Setup failed for velux: Component failed to initialize.

I also have a problem with the KLR200 setup. In my case I simply do not geting any responce from Home Assistant. Almost as the configuration line is ignored. (I even tried to change from Hass.IO to Hassbian, in order to try if this would change anything).

I’m relative new to Home Assistant, and just to makes sure where did you find the log you posted above?
This is not to Hi-jack you post, but there is not much going on in regards to the VELUX option, so I hope to join forces and find a solution together.

Hi, you can find the logs in the webinterface under “developer toots” -> “info” or via ssh on the command line. You can find more on how to use ssh with hass.io here -> https://home-assistant.io/developers/hassio/debugging/

I have not had time to worry about the problem yet. If I find a solution I’ll post it here for the community.

Did anybody figure out a solution for this? I am running into the same issue, but…

  • When I run HA on my local machine in dev mode, everything works
  • If I run a sample pyvlx script, everything works

Only running this thing from hass.io results in InvalidToken…

Any luck here? I’m experiencing the same problem.

FWIW, I as also getting InvalidToken and Setup Failed errors - make sure you’re logged out of the web interface (for Velux) before you load Hassio.

That said, still can’t get anything for Velux to show up in HA.

Just for info - official API is coming for the KLF 200

openHAB Community – 1 Oct 18

Io-homecontrol / velux - something’s in the bush

Hello guys, As you already have noticed VELUX has released a software update for KLF200. Unfortunately, we are still in the progress of setting up our systems to provide a pleasant experience for this, so we have some work to do. Currently we are…

Hello everyone - is there an updated version of the velux component planned that supports the official api? I have purchased the KLF 200 and upgraded the firmware first to 2.0.0.71 - big mistake because now I am not able to use it via HA. It took me a few hours to figure out what is “wrong”…
The link for the official API and the firmware: https://www.velux.com/api/klf200
I’m no programmer, so I’m of no use here unfortunately…

I have the sane issue, running 0.80.3 and latest KLF200 firmware, HA component just returns an error

2018-11-06 21:51:46 WARNING (MainThread) [homeassistant.setup] Setup of velux is taking over 10 seconds.
2018-11-06 21:51:46 ERROR (MainThread) [homeassistant.components.velux] Can’t connect to velux interface: Request timeout when talking to VELUX API
Traceback (most recent call last):
File “/usr/local/lib/python3.6/site-packages/pyvlx/interface.py”, line 51, in do_http_request_impl
async with session.post(url, data=json.dumps(body), headers=headers) as response:
File “/usr/local/lib/python3.6/site-packages/aiohttp/client.py”, line 855, in aenter
self._resp = await self._coro
File “/usr/local/lib/python3.6/site-packages/aiohttp/client.py”, line 370, in _request
timeout=timeout
File “/usr/local/lib/python3.6/site-packages/aiohttp/connector.py”, line 445, in connect
proto = await self._create_connection(req, traces, timeout)
File “/usr/local/lib/python3.6/site-packages/aiohttp/connector.py”, line 757, in _create_connection
req, traces, timeout)
File “/usr/local/lib/python3.6/site-packages/aiohttp/connector.py”, line 862, in _create_direct_connection
req=req, client_error=client_error)
File “/usr/local/lib/python3.6/site-packages/aiohttp/connector.py”, line 822, in _wrap_create_connection
return await self._loop.create_connection(*args, **kwargs)
File “uvloop/loop.pyx”, line 1871, in create_connection
File “uvloop/loop.pyx”, line 1860, in uvloop.loop.Loop.create_connection
concurrent.futures._base.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/usr/local/lib/python3.6/site-packages/pyvlx/interface.py”, line 39, in do_http_request
return await self.do_http_request_impl(url, body, headers)
File “/usr/local/lib/python3.6/site-packages/pyvlx/interface.py”, line 58, in do_http_request_impl
return json_response
File “/usr/local/lib/python3.6/site-packages/async_timeout/init.py”, line 45, in exit
self._do_exit(exc_type)
File “/usr/local/lib/python3.6/site-packages/async_timeout/init.py”, line 92, in _do_exit
raise asyncio.TimeoutError
concurrent.futures._base.TimeoutError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/usr/src/app/homeassistant/components/velux.py”, line 35, in async_setup
await hass.data[DATA_VELUX].async_start()
File “/usr/src/app/homeassistant/components/velux.py”, line 61, in async_start
await self.pyvlx.load_scenes()
File “/usr/local/lib/python3.6/site-packages/pyvlx/pyvlx.py”, line 24, in load_scenes
await self.scenes.load()
File “/usr/local/lib/python3.6/site-packages/pyvlx/scenes.py”, line 37, in load
json_response = await self.pyvlx.interface.api_call(‘scenes’, ‘get’)
File “/usr/local/lib/python3.6/site-packages/pyvlx/interface.py”, line 17, in api_call
await self.refresh_token()
File “/usr/local/lib/python3.6/site-packages/pyvlx/interface.py”, line 62, in refresh_token
json_response = await self.api_call(‘auth’, ‘login’, {‘password’: self.config.password}, add_authorization_token=False)
File “/usr/local/lib/python3.6/site-packages/pyvlx/interface.py”, line 20, in api_call
return await self.api_call_impl(verb, action, params, add_authorization_token)
File “/usr/local/lib/python3.6/site-packages/pyvlx/interface.py”, line 34, in api_call_impl
return await self.do_http_request(url, body, headers)
File “/usr/local/lib/python3.6/site-packages/pyvlx/interface.py”, line 41, in do_http_request
raise PyVLXException(“Request timeout when talking to VELUX API”)

are you running the 2.x firmware? they switched ports, disabled the webui on the LAN Port, etc. and implemented an official API which seems to work differently then the “unofficial” API in Firmware 1.x

I will switch my klf 200 with firmware 2.x to one with a 1.x (downgrade is not possible afaik) in a couple of days (a velux employee switches his PERSONAL KLF with mine - very nice :slight_smile: ) and will wait for an updated HA component which works with firmware 2.x…

Thanks for that! I suspected the firmware was the cause, you’ve confirmed that. Yes my KLF 200 is brand new and has the latest firmware from the factory, so it looks like I need the updated component.

My existing KLF type unit is 8 years old and I operate it using a Gira KNX binary actuator, it is very simple: All windows open or closed and only one-way communications, so the new unit will add a lot of functionality.

The other issue is that 0.81.6 will not run (something to do with Cards) in my Lovelace environment, so I am stuck (for now) on 0.80.3

I have now received the KLF with 1.x firmware and it basically works. As a proof of concept I have now created two basic scenes for opening and closing all of my windows (we have 12…) , which works fine and without noticable delay via HA.
It is a bit clumsy because the KLF config UI is not perfectly designed. E.g.: you can only add new programs/scenes (e.g. opening the blinds) using an existing remote, not directly in the KLF web UI. Changing means deleting a program/scene and re-adding it using the remote… Also there is no backchannel from the windows (which I was aware of and should not be a big deal). I have to test it a bit more over the weekend to get a hang of it and find the limits/possibilites.
Maybe someone with more experience can share the wisdom here :slight_smile:

  • should I configure every single action in the KLF as a program (e.g. opening closing of every single window/blind) and configure the rest in HA using a lot of scenes or
  • should I define more complex programs already in the KLF… (e.g. copy the “ventilate for 10 min” program from my KLR Remotes to the KLF) and have less scenes in HA to deal with…
    Well, one thing is for sure - I’ll annoy my g/f with constantly opening/closing the windows/blinds over the coming days :smiley:

Hi there,

i released an updated version of pyvlx (the python library for connecting to KLF 200) with support for the new API. It needs some more testing before i will do a PR: https://github.com/julius2342/pyvlx

But you can check it out by your own by manually updating the version within home-assistant/homeassistant/components/velux.py

Sounds great.

I haven’t had the time to look at your code, and don’t know if you have implemented a kind of state polling… if yes, I think it must handle battery products differently. They sleep to save battery, and if woken all the time, they might drain the battery faster than it is being charged.

Use the ‘remaining time’ to estimate when to check the state.

Made a WIP-PR: https://github.com/home-assistant/home-assistant/pull/18738

I’d love to test - but I have only recently got my KLF200 switched to a 1.x Firmware and I don’t want to risk anything by upgrading it again to 2.0 for a beta integration… Currently it works with 1.x and I have some automations already set up (open windows when air is bad, close blinds behind the tv when tv is on during the day, etc.

If it is more or less foolproof and works stable I may give it a go. So are there already users using the new component?

The component is now ready to be tested :slight_smile:

Thank you Julius, for your work. Can anyone here describe, how to update home assistant to get the new velux comonent? I am at version 0.85.1 and there is still the old component. On another test station I installed the dev branch 0.86.0.dev0 but there is still the same old version of velux that requires pyvlx 0.1.3.
Btw. I managed to connect to the KLF200 with pyvlx 0.2.7 and the demo.py, but I found that I have to give the wlan password and not the ‘velux123’.
Connected to: KLF 200: Software version: 0.2.0.0.71.0, hardware version: 6, protocol version: 3.14