Velux Component for KLF 200 doesn't support the new API with Firmware 2.0.0.71

found a hackish solution to the issue I have with all of my velux covers initially reporting a position of -23 %

I edited “\config\custom_components\velux_init_.py”

async def async_start(self):
“”“Start velux component.”""
_LOGGER.info(“velux interface started”)
await self.pyvlx.load_scenes()
await self.pyvlx.load_nodes()

    # the actual fix.
    for node in self.pyvlx.nodes:
      _LOGGER.info("stopping node: " + str(node))
      await node.stop(wait_for_completion=False)

it seems sending a stop command to a velux device makes it report its actual correct state.
Luckily this is only done once at component start up :slight_smile:

I would have gone deeper into the pyvlx sources but as stated above I couldn’t make it connect at all. So my programming adventure ends with editing the files outside of pyvlx.
I’m almost sure a better fix is available within the pyvlx package itself.

Feel free to try it out :slight_smile:

Can someone with a working KLF200 [Firmware 2.0.0.71] confirm if WebGui is responding from LAN port? I had two boxes i upgraded and only can connect to native Wifi ?
I impossible to trace the error if i dont know if the box i broken or this is normal behavior

Hi,

Web GUI works only on WiFi if I am not mistaken on new firmware.

1 Like

Does anyone now if @gibman fix had been introduced in the mainstream Velux component?

i can confirm i’m seeing the same thing. web gui works only on wifi. lan appears not to respond but integration works when connected to HA.

1 Like

@gibman I do have the rebooting issue you reported.
I am trying your patch, but I don’t see any improvement
I do see messages in the HA log telling me I have the custom velux component.

 [pyvlx] Connected to: KLF 200: Software version: 0.2.0.0.71.0, hardware version: 5, protocol version: 3.14


hass_io_kitchen_blinds
hass_io_kitchen_windowss

I just realized that the sliders for the non window specific velux devices within hass.io does not correspond with how it’s rendered in the official Velux touch remote.

Ive uploaded an example of my kitchen blinds/windows as seen from the velux remote control point of view as well as the corresponding view as seen in hass.io.

the current physical state of the window is : Fully closed (shut)
the current physical state of the blind is : Fully open, light is entering the room

Now my OCD is severely triggered.

Also regarding the arrow buttons for the covers on the hass.io UI:
Looking it at the velux remote control manual for the KLR100 model we have:

Arrow Key Up:
OPEN/UP

Arrow Key Down:
CLOSE/DOWN

The buttons seems to be correct for both windows and blinds

How it should work:

  1. The blinds (gardin køkken 1) should be position: 0 for the blinds fully open
  2. The blinds (gardin køkken 1) should be position: 100 for the blinds fully closed

the windows scenario seems to get it right, so no changes needed there.

also, shutters, awning blinds are also wrong.
so we just need a small fix to inverse the order of the position for these cover types.

Hmm, I dont see the KLF200 showing me anything relevant about the open / close state.
Even using just the KLF200 I open and close the blind on the skylight and it show the same thing either way (and I note this is a single blind not a group which could be more complicated).

Skylights are similar for me.

Earlier in this thread there is comment about being unable to restart HA with the new Velux code.
I am still using the custom component from gibman.
I had this again just now; only it not only failed to restart HA, it wouldnt start even after power cycling the Raspberry Pi. I never had that before. I’ve always been able to power cycle to get HA back up.
=> I had to power cycle the KLF200 to get it HA going again.

I can confirm @gibman custom component helps but does not solve completely the issue.

Here is another image of one blind being operated from open / 0 to half closed / 49.

You are right… the klf200 does not maintain the status of the bottom slider as well as the digit /49. As long as the blind is being operated the status and digit are shown. Once its in place its hidden.

But it does seem like from the point of view of the velux remote that 100 indicates a fully closed blind and 0 being open.

Its reversed on the cover component within hass.io.

I did a few changes locally in covers.py for the velux component and was able to reverse the slider making it corresponding with the velux remote. But sadly this reversed the buttoms also.
So the arrow down button would close the blind / blinds going down. And vice versa for the up button.

So an even worse situation now.

hi… same here…

Anyone with KLF200 connection problems upon rebooting hass.io could you please try this fix in:

remember this import in the top of the file:
from homeassistant.const import (CONF_HOST, CONF_PASSWORD, EVENT_HOMEASSISTANT_STOP)

replace the def init with:
`
def init(self, hass, config):
“”“Initialize for velux component.”""

async def on_hass_stop(event):
	"""Close connection when hass stops."""
	_LOGGER.info("velux interface terminated")
	await self.pyvlx.disconnect()                    

hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, on_hass_stop)
#from custom_components.pyvlx import PyVLX                
from pyvlx import PyVLX
host = config[DOMAIN].get(CONF_HOST)
password = config[DOMAIN].get(CONF_PASSWORD)
self.pyvlx = PyVLX(
	host=host,
	password=password)

`

I’ve done 8 consecutive reboots and no problems so far :slight_smile:
Latest file for reference is here:
https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/components/velux/init.py

I’ll create a branch a pull request for this if others are seeing good results :slight_smile:

edit: here’s a link for the lazy ones that contains all the code.
It contains the latest version of pyvlx and is currently running on hass.io 0.93.0
https://drive.google.com/file/d/15rEu_0wQOlpgQQ8YvpQPz2VEImP5EB2x/view?usp=sharing

The archive also contains a few other fixes that I’m running locally (described in the this thread).

just put it into the customs_components folder as described in this thread previously.

Hi guys,

I´m willing to buy a KLF 200 to control one window and two blinds but I’m currently confused. Is the KLF now working or not?

Thanks a lot,

Flo

mostly…it is but not very robust on reboots

Hmm…what do you mean with not very robust on reboots?

read above: it has been covered

there is a custom component which mitigates the issue

Just getting back to this thread and I have picked up velux_patch2. Thanks @gibman.

For your reference, when I ran the first patch I was running 0.88.1 on Hasbian (this install died with a flash card failure).

I had been running a clean 0.93.2 without too many reboot problems, but then I got one today and came back to this thread. I installed the updated patch and rebooted and I immediately got the failure below.

I don’t think its worth tracking down (for now at least). It cleared up after rebooting the KLF, so something in the original failure may have been the root cause.

BTW - What do you use to extract the rar? I’ve been using windows and some snarky extractor and moving the files over SAMBA. Is there a unix utility I can use on hassio to extract rar?

2019-06-16 14:42:54 WARNING (MainThread) [homeassistant.loader] You are using a custom integration for velux which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you do experience issues with Home Assistant.
2019-06-16 14:43:02 ERROR (MainThread) [homeassistant.components.device_tracker] Unable to load /config/known_devices.yaml: Config file not found: /config/known_devices.yaml
2019-06-16 14:44:01 ERROR (MainThread) [homeassistant.setup] Error during setup of component velux
Traceback (most recent call last):
File “/usr/local/lib/python3.7/site-packages/homeassistant/setup.py”, line 153, in _async_setup_component
hass, processed_config)
File “/config/custom_components/velux/init.py”, line 35, in async_setup
await hass.data[DATA_VELUX].async_start()
File “/config/custom_components/velux/init.py”, line 70, in async_start
await self.pyvlx.load_scenes()
File “/usr/local/lib/python3.7/site-packages/pyvlx/pyvlx.py”, line 87, in load_scenes
await self.scenes.load()
File “/usr/local/lib/python3.7/site-packages/pyvlx/scenes.py”, line 51, in load
await get_scene_list.do_api_call()
File “/usr/local/lib/python3.7/site-packages/pyvlx/api_event.py”, line 22, in do_api_call
await self.send_frame()
File “/usr/local/lib/python3.7/site-packages/pyvlx/api_event.py”, line 34, in send_frame
await self.pyvlx.send_frame(self.request_frame())
File “/usr/local/lib/python3.7/site-packages/pyvlx/pyvlx.py”, line 70, in send_frame
await self.connect()
File “/usr/local/lib/python3.7/site-packages/pyvlx/pyvlx.py”, line 45, in connect
await self.connection.connect()
File “/usr/local/lib/python3.7/site-packages/pyvlx/connection.py”, line 89, in connect
ssl=self.create_ssl_context())
File “uvloop/loop.pyx”, line 1945, in create_connection
File “uvloop/loop.pyx”, line 1942, in uvloop.loop.Loop.create_connection
ConnectionAbortedError: SSL handshake is taking longer than 60.0 seconds: aborting the connection
2019-06-16 14:44:32 ERROR (MainThread) [frontend.js.latest.201905140] http://192.168.2.240:8123/frontend_latest/chunk.8abe6b9573af3d1ad82d.js:2875:1345 Uncaught TypeError: Cannot read property ‘isOff’ of undefined
2019-06-16 14:44:32 ERROR (MainThread) [frontend.js.latest.201905140] http://192.168.2.240:8123/frontend_latest/chunk.8abe6b9573af3d1ad82d.js:2875:1345 Uncaught TypeError: Cannot read property ‘isOff’ of undefined
2019-06-16 14:47:26 ERROR (MainThread) [homeassistant.components.hassio.handler] Timeout on /homeassistant/restart request

I’ve been rebooting a lot this evening and with patch 2 I have had no trouble with velux hanging.
I’ll continue to monitor

1 Like

I received this error trace on a reboot today, and I needed to restart the Velux hub.

2019-07-06 19:42:58 ERROR (MainThread) [homeassistant.setup] Error during setup of component velux
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/homeassistant/setup.py", line 153, in _async_setup_component
    hass, processed_config)
  File "/config/custom_components/velux/__init__.py", line 35, in async_setup
    await hass.data[DATA_VELUX].async_start()
  File "/config/custom_components/velux/__init__.py", line 70, in async_start
    await self.pyvlx.load_scenes()
  File "/usr/local/lib/python3.7/site-packages/pyvlx/pyvlx.py", line 87, in load_scenes
    await self.scenes.load()
  File "/usr/local/lib/python3.7/site-packages/pyvlx/scenes.py", line 51, in load
    await get_scene_list.do_api_call()
  File "/usr/local/lib/python3.7/site-packages/pyvlx/api_event.py", line 22, in do_api_call
    await self.send_frame()
  File "/usr/local/lib/python3.7/site-packages/pyvlx/api_event.py", line 34, in send_frame
    await self.pyvlx.send_frame(self.request_frame())
  File "/usr/local/lib/python3.7/site-packages/pyvlx/pyvlx.py", line 70, in send_frame
    await self.connect()
  File "/usr/local/lib/python3.7/site-packages/pyvlx/pyvlx.py", line 45, in connect
    await self.connection.connect()
  File "/usr/local/lib/python3.7/site-packages/pyvlx/connection.py", line 89, in connect
    ssl=self.create_ssl_context())
  File "uvloop/loop.pyx", line 1945, in create_connection
  File "uvloop/loop.pyx", line 1942, in uvloop.loop.Loop.create_connection
ConnectionAbortedError: SSL handshake is taking longer than 60.0 seconds: aborting the connection

anyway the latest patch definetly improves the behavior.

@gibman will this be implemented into the official component?