joleys / niko-home-control-II

Home Assistant Custom Integration for Niko Home Control II
MIT License
74 stars 21 forks source link

Lost connection between HA and NCH2 #114

Closed studioblabla closed 7 months ago

studioblabla commented 8 months ago

I use virtual devices to trigger WIFI-switches with NHC2 hardware button. It went well until last week...

Strange behavior: The initial connection is okay. (Sometimes I need to re-insert UTP or reboot NHC2 to find NHC2 from HA) After some time (1-2 hours), I can't control lights anymore, and HA doesn't show updates in status when operated from NHC2 (app or buttons).

Or I get the message to reboot HA telling me the config is updated (latest controller config) Or I get the message 'not available' ("Deze entiteit is niet meer beschikbaar vanuit de nhc2 integratie. Wanneer de entiteit niet meer in gebruik is, kan deze vanuit de instellingen verwijderd worden.")

Some days ago, Google Home lost connection too, but this is ok again.

Modem rebooted, router rebooted,... And Niko support was very friendly, telling me that they don't give support on the API.

user152306 commented 8 months ago

A wild guess here, your NHC2 controller is sometimes getting new IP-address from DHCP. Try to lock the address for your controller in your "router". If you can't do that, set a static IP-address on the NHC2 controller (if that is possible).

studioblabla commented 8 months ago

It's static bij DHCP...

tijsverkoyen commented 8 months ago

@studioblabla how stable is the connection? Could it be that the Niko Home Controller disconnect sometimes? The message that the config is updated is one that happens when Home Assistant and Niko Home Controller (re)connect.

studioblabla commented 8 months ago

I changed the UTP cable and plugged it in directly to the router (rebooted the modem). I'll try other lanport on the NHC. (edit: must be the WAN port!)

It looks like, but I'm not sure, that the configuration changes the first time I open a dashboard with all the lights. Like HA is sending something and NHC reacts with a changed config.

Keep you posted.

studioblabla commented 8 months ago

HA is receiving the status from NHC2, but doesn't react on it, like seen in the DEBUG. (So problem is not NHC2, but HA.)

024-01-25 10:16:38.884 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry hobby (192.168.168.16) for switch Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/config_entries.py", line 406, in async_setup result = await component.async_setup_entry(hass, self) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/switch/init.py", line 99, in async_setup_entry return await component.async_setup_entry(entry) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 188, in async_setup_entry raise ValueError("Config entry has already been setup!") ValueError: Config entry has already been setup! 2024-01-25 10:16:38.894 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry hobby (192.168.168.16) for update Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/config_entries.py", line 406, in async_setup result = await component.async_setup_entry(hass, self) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/update/init.py", line 122, in async_setup_entry return await component.async_setup_entry(entry) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 188, in async_setup_entry raise ValueError("Config entry has already been setup!") ValueError: Config entry has already been setup! 2024-01-25 10:17:18.884 DEBUG (Thread-5 (_thread_main)) [custom_components.nhc2.nhccoco.devices.controller] Controller changed (hobby/control/devices/evt == /control/devices/rsp). 2024-01-25 10:17:18.886 DEBUG (Thread-5 (_thread_main)) [custom_components.nhc2.nhccoco.devices.relay_action] VLedWaskotAction changed. Topic: hobby/control/devices/evt | Data: {'Uuid': '3350cea2-6a3f-4965-934c-629130aea521', 'Properties': [{'Status': 'On'}]} 2024-01-25 10:17:18.886 DEBUG (Thread-5 (_thread_main)) [custom_components.nhc2.nhccoco.devices.flag_action] VLedWaskot changed. Topic: hobby/control/devices/evt | Data: {'Uuid': '041aad41-8d0b-4260-bd77-415cbd850829', 'Properties': [{'Status': 'True'}]} 2024-01-25 10:17:20.062 DEBUG (Thread-5 (_thread_main)) [custom_components.nhc2.nhccoco.devices.controller] Controller changed (hobby/control/devices/evt == /control/devices/rsp). 2024-01-25 10:17:20.064 DEBUG (Thread-5 (_thread_main)) [custom_components.nhc2.nhccoco.devices.relay_action] VLedWaskotAction changed. Topic: hobby/control/devices/evt | Data: {'Uuid': '3350cea2-6a3f-4965-934c-629130aea521', 'Properties': [{'Status': 'Off'}]} 2024-01-25 10:17:20.065 DEBUG (Thread-5 (_thread_main)) [custom_components.nhc2.nhccoco.devices.flag_action] VLedWaskot changed. Topic: hobby/control/devices/evt | Data: {'Uuid': '041aad41-8d0b-4260-bd77-415cbd850829', 'Properties': [{'Status': 'False'}]} 2024-01-25 10:17:21.132 DEBUG (Thread-5 (_thread_main)) [custom_components.nhc2.nhccoco.devices.controller] Controller changed (hobby/control/devices/evt == /control/devices/rsp). 2024-01-25 10:17:21.133 DEBUG (Thread-5 (_thread_main)) [custom_components.nhc2.nhccoco.devices.relay_action] VLedWaskotAction changed. Topic: hobby/control/devices/evt | Data: {'Uuid': '3350cea2-6a3f-4965-934c-629130aea521', 'Properties': [{'Status': 'On'}]} 2024-01-25 10:17:21.134 DEBUG (Thread-5 (_thread_main)) [custom_components.nhc2.nhccoco.devices.flag_action] VLedWaskot changed. Topic: hobby/control/devices/evt | Data: {'Uuid': '041aad41-8d0b-4260-bd77-415cbd850829', 'Properties': [{'Status': 'True'}]} 2024-01-25 10:17:22.183 DEBUG (Thread-5 (_thread_main)) [custom_components.nhc2.nhccoco.devices.controller] Controller changed (hobby/control/devices/evt == /control/devices/rsp). 2024-01-25 10:17:22.185 DEBUG (Thread-5 (_thread_main)) [custom_components.nhc2.nhccoco.devices.relay_action] VLedWaskotAction changed. Topic: hobby/control/devices/evt | Data: {'Uuid': '3350cea2-6a3f-4965-934c-629130aea521', 'Properties': [{'Status': 'Off'}]} 2024-01-25 10:17:22.186 DEBUG (Thread-5 (_thread_main)) [custom_components.nhc2.nhccoco.devices.flag_action] VLedWaskot changed. Topic: hobby/control/devices/evt | Data: {'Uuid': '041aad41-8d0b-4260-bd77-415cbd850829', 'Properties': [{'Status': 'False'}]}

Will try a fresh install on a non RASP-deivce...

tijsverkoyen commented 8 months ago

In the integration there is nothing implemented to handle a reconnect at the moment. Except for providing an update entity that you should restart Home Assistant.

In most cases the problem is not the controller itself. But the connection (stability).

2024-01-25 10:17:22.183 DEBUG (Thread-5 (_thread_main)) [custom_components.nhc2.nhccoco.devices.controller] Controller changed (hobby/control/devices/evt == /control/devices/rsp).

Is a debug statement that is shown when a message for the controller itself is received. See https://github.com/joleys/niko-home-control-II/blob/master/custom_components/nhc2/nhccoco/devices/controller.py#L28. This does not mean per se that the connection is lost.

The behaviour you describe, that Home Assistant is not reacting anymore on any changes for the Niko entities. Happens when the Niko Home Controller republishes the device list. And that is when the update entity should indicate that you need to restart Home Assistant. The republish of the device list, normally, and to my knowledge only happens when the Niko Home Controller restarts, a new version is uploaded to the controller (and restarts) or when the controller lost its connection and reconnects. But as said: the republish of the device list is not handled in this integration as it can be that new entities should be created.

To be frank: At the moment I don't have the time to look into this specific issue due to work obligations.

studioblabla commented 8 months ago

No prob Tijs!

dimitridelanghe commented 8 months ago

@studioblabla @tijsverkoyen i found out, every time you are uploading a new config from the NHC software u need to reboot the HA, at least for me it's needed!

studioblabla commented 8 months ago

@dimitridelanghe: Rebooting was not the solution for me. I need to remove the NHC2 and reinstall it. Even unplug the NHC from the switch and reconnect it to connect to the NHC2.

I tried this week different hardware (Now HA is running on a RPI3, but tried old CPU generic HA, on the CPU Linux + VirtualBox, a recent Windows + VirtualBox), but all had the same behavior. There is a new config and after some time the device is lost in HA. For some time it looked like a VirtualBox on my macbook worked more stable, but after 2 days, it had the same behavior.

Now a changed my router (from ddwrt linksys WRT32000 to a low-cost linksys stock firmware) and it's now running for more than 24 hours without issues. I'll update you all in the next few days.

tijsverkoyen commented 8 months ago

@studioblabla any update?

studioblabla commented 8 months ago

It was running fine for 3 days on a separate small network with its own router. Now placed the router and the NHC2 in 'the big' network, and NHC2 'changed config' after 24 hours.

So what is causing the config-change of the NHC2... Can it be the switch? There are Unifi AP with controller on the network? So now thinking about replacing the switch... Maybe I have a spare laying around.

dimitridelanghe commented 8 months ago

i have a full unifi setup and don't have that issue, but it must be something locally

tijsverkoyen commented 8 months ago

I also have a full Unify setup and no issues at all. Are you using a static IP for the Niko Home Controller? Could it be that some other device is trying to use the same IP?

studioblabla commented 8 months ago

Static lease for NHC2 outside the dhcp range. Tomorrow, a new ubi-switch will arrive. @tijsverkoyen Where is your HA running on? Keep you posted!

tijsverkoyen commented 8 months ago

Raspberry PI 4 in a docker container

studioblabla commented 7 months ago

The new switch did the job. Everything is working stable. This topic can be closed!