pawlizio / my_velux

Custom component of velux integration for Home Assistant
31 stars 9 forks source link

[Bug?] KLF200 need's to be restarted regularly (every 24-30h) to stay connected. #11

Closed 10bn closed 1 year ago

10bn commented 2 years ago

Hi, thank you very much for providing this integration since the newer firmware is currently not supported by HomeAssistant.

I currently need to restart the KLF regularly to keep it functional. Is there something I could try to make it more reliable and which information would be useful to debug this?

thx jaddel

pawlizio commented 2 years ago

Did you try an automation? The integration provides a service which automatically force your KLF to reboot. You can call this service when you shutdown your homeassistant, i.e. during a reboot. Below is the yaml:

alias: KLF reboot on hass stop event
description: Reboots the KLF200 in order to avoid SSL Handshake issue
trigger:
  - platform: homeassistant
    event: shutdown
condition: []
action:
  - service: velux.reboot_gateway
mode: single

Are your problems only if you reboot home assistant or do you loose also the connection without rebooting?

10bn commented 2 years ago

I'm already using that automation to force a reboot when HA reboots.

Are your problems only if you reboot home assistant or do you loose also the connection without rebooting?

I'm loosing the connection without rebooting.

pawlizio commented 2 years ago

Hmm... I don't have such problems. Maybe you can try to add another automation which periodically force the KLF to reboot. How often this happens?

10bn commented 2 years ago

I'll give it a try and otherwise connect a smart plug as a workaround for now to force a reboot every 24h. :sweat_smile:

It currently happens almost every day.

pawlizio commented 2 years ago

What kind of devices are in between home assistant ul and klf? Do you use a switch or are they connected through your router? What type of router you use?

Maybe try another setup, like connect them via switch, if they are now connected through your router.

10bn commented 2 years ago

Thx for the suggestion, I'll give it a try and report back.

They are currently connected via a FRITZ!Box 7590.

rohrsh commented 2 years ago

The reboot idea isn't ideal

  1. It doesn't help you once your KLF is already unresponsive
  2. Home Assistant's on-reboot functionality is broken for some users, including me --> https://community.home-assistant.io/t/home-assistant-stop-automation-not-working/231384
neildsb commented 2 years ago

2022.5 my KLF gateway has been stable for ~4 days (only just installed), this morning it was not responsive, added a smart plug to reboot, what time period should I set 24hr - 48hr? setup - all devices are connected on a L2 VLAN via a few switches. on a side note are Velux updating the FW regularly?

rohrsh commented 2 years ago

Yes, the power cycle is the only answer for me.

You could try an automation like this:


alias: POE cycle Velux if a blind is unavailable - check once each hour
trigger:
  - platform: time_pattern
    minutes: '0'
condition:
  - condition: state
    entity_id: cover.ensuite_blind
    state: unavailable
action:
  - service: script.poe_cycle_velux
10bn commented 2 years ago

I ended up connecting the KLF via a smart plug which resets (power cycles) the device every night.

neildsb commented 2 years ago

thanks for the replies, i have added a state 'unavailable' in my node red to power cycle the plug

image

neildsb commented 2 years ago

Yes, the power cycle is the only answer for me.

You could try an automation like this:

alias: POE cycle Velux if a blind is unavailable - check once each hour
trigger:
  - platform: time_pattern
    minutes: '0'
condition:
  - condition: state
    entity_id: cover.ensuite_blind
    state: unavailable
action:
  - service: script.poe_cycle_velux

one quick question, how often does HA poll the KLF’s state to determine if its unavailable? i have disconnected the Ethernet cable and checking the dev tools and it still reports open….ie the last state

pawlizio commented 2 years ago

With release 2.2 I've added a sensor which increments with each new established connection to KLF200. The sensor will be reset on each HA restart. However you can use this sensor in order to try some workarounds to fix your issue. In the below example you can reboot KLF200 on each second connection which is established between HA and KLF200.

alias: Reboot KLF200 every second connection
trigger:
  - platform: state
    entity_id: sensor.klf200_connection_counter
condition:
  - condition: template
    value_template: >-
      {{states('sensor.klf200_connection_counter') | float(default = 1) % 2 == 0}}
action:
  - service: velux.reboot_gateway
    data: {}

Finally I'm not sure if this will help, but you can try.

pawlizio commented 2 years ago

However may you can share the sensor value once the KLF becomes unresponsive. I'd like to understand how many times Home Assistant can reconnect to KLF200 before it becomes unresponsive.

neildsb commented 2 years ago

I raised a ticket with Velux, and received the following -

Unfortunately, we are unable assist in debugging the API interface for KLF 200. We can only ask that you refer to the documentation on https://www.velux.com/klf200 and what can be found on various web forums. On below documentation, this is describing the TCP/IP connection. If the socket is not used for more than 15 minutes, it will automatically close down the connection.

image

neildsb commented 2 years ago

I guess in my Node Red flows I am triggering an event state (light levels) every 5 mins to check the KLF200's state (Open/Closed) keeping the connections open? TBH I am not sure....

image

pawlizio commented 2 years ago

Finally the KLF200 keeps unresponsive even after 15 minutes, that seems to be a bug. However I assume the problem is mainly caused by lost connections. Does someone tried the new version with the connections counter sensor? I would like to know the sensor value in case the KLF200 becomes unresponsive. I'm a bit worried that the bug is becoming a problem if you have some connection interruptions caused by FritzBox or similar Routers. In my case I use a separate Switch, not a Router between HA and KLF200 and I don't have any connection looses.

neildsb commented 2 years ago

I have only one connection counter increment, but have rebooted HA a few times for other reasons, I have two switches (Meraki and Netgear) between the KLF and HA over one vlan, via a trunk, my router is upstream....I will try not to reboot for a few days and report back

pawlizio commented 2 years ago

But have you configured the automation to force an KLF200 reboot, before you stop/reboot HA?

Like this:

alias: KLF reboot on hass stop event
description: Reboots the KLF200 in order to avoid SSL Handshake issue
trigger:
  - platform: homeassistant
    event: shutdown
condition: []
action:
  - service: velux.reboot_gateway
    data: {}
mode: single
neildsb commented 2 years ago

I have, however it only ran a few days ago, so I guess it's not triggered - 13 February 2022, 8:43 am

image

Ps the sun has just risen here in the UK :-) and my shutter automation is all working ok

alias: KLF reboot on hass stop event description: '' trigger:

I will change to your example

pawlizio commented 2 years ago

Actually this automation should force KLF200 to reboot if you restart your HA.

stephanseitz commented 2 years ago

I also have these described connection problems again and again. I have therefore installed the connection counter a few days ago and observed. Until now, I still have a connection, but the connections are increasing continuously. See also the screenshot attached.

Bildschirmfoto 2022-02-21 um 22 15 29
pawlizio commented 2 years ago

@stephanseitz, so you had 48 reconnections without forcing the KLF to reboot in the meantime? Or do you have an automation to reboot the KLF200? In which cases the KLF200 becomes unresponsive, only on HA reboots or also without restarts of HA?

stephanseitz commented 2 years ago

please excuse my late reply. I have restarted everything once so far since last time (for other reasons - updates). Amazingly, I have now had no problems since 02/19/2022 (after setting up the counter). However, the connections continue to just jump up sometimes (to 115 so far), for whatever reason. Everything can still be controlled. I have not set up an automatic restart of the Velux KLF box yet.

Bildschirmfoto 2022-02-28 um 11 13 09

Regarding your question when the error occurred so far: independent of a reboot. The last time I had the error in the middle of normal operation after 3 hours.

stephanseitz commented 2 years ago

image Update, the covers are still working! But there seems to be a connection leak somewehere.

stephanseitz commented 2 years ago

Hmm strange. Just now the velux klf box stopped working. I had about 160 connections in the counter for days. I had to turn the box off and on to get it to work again.

pawlizio commented 2 years ago

Please update to my latest version and check if this Issue is still present, thx.

neildsb commented 2 years ago

i will remove my daily reboot and report back :-)

stephanseitz commented 2 years ago

I have now also installed the latest master. I can also imagine that by commit "Throttle multiple requests to the velux gateway" the problem may also be eliminated.

stephanseitz commented 2 years ago

I am sorry to report that the problem has reoccurred. This morning I had to restart the box so that the control is possible again.

pawlizio commented 2 years ago

Can you debug pyvlx and share the logs?

Jeltel commented 2 years ago

I've been having this connection issue with the HA standard integration for some while now. I'm going to try this one. Thanks for this custom component!

pawlizio commented 1 year ago

Does someone has still problems with not responding KLF otherwise I will close this, as there was no activity here for a long time.

Jeltel commented 1 year ago

I migrated to the KIG300 homekit device. That works flawless.

pawlizio commented 1 year ago

OK, sounds interesting. However I think there will be more interesting solutions in the future with Matter.

stephanseitz commented 1 year ago

I still have the problem once a week. In the logs, unfortunately, I can not see anything that indicates this problem. As soon as the box hard start (I have a switchable socket installed) it goes after the startup again. Something seems to overflow in the box.

Jeltel commented 1 year ago

I migrated to the KIG300 homekit device. That works flawless.

OK, sounds interesting. However I think there will be more interesting solutions in the future with Matter.

Would it be possible to directly link the Velux devices to a matter hub (so Home Assistant)?

Besides that in my case a reboot did not solve the connection issue. It was just to unreliable. The KIG300 has not had any issue yet. And also responds way faster than the KLF200. So I can just say open window to 50% and not have to check if the window indeed did what I wanted.

pawlizio commented 1 year ago

Actually I don't know how Somfy or Velux will support Matter, but I assume like many other companies they will just support Matter through their Gateways, like Tahoma, KLF200 or your KIG300. As far as I know the current actuators with io-homecontrol operates on 868.95 MHz frequency, so that devices will not be able to communicate via Thread (lower level communication protocol of fully Matter supporting devices) which uses 2,4 Ghz. I don't have contact to Velux or Somfy, so I don't know if they will also open the actuators to directly communicate via Thread to other Matter hubs directly. I just know that Somfy is part of the Matter initiative.