core
core copied to clipboard
Niko home control button updating with delay - update 2023.8
The problem
Hi,
When pressing a button (tried mushroom light card and the default light card) it looks like the button is not working. But... the light does turn on. After a big while, 45sec or so.. the state of the button updates to the correct state.
Same thing for turning off lights, also a big delay on the button.
This issue is existing on the browser but also on our mobile app. And is applicable on any Niko home control light, dimmable and not dimmable.
Thank you.
What version of Home Assistant Core has the issue?
core-2023.8.3
What was the last working version of Home Assistant Core?
never worked
What type of installation are you running?
Home Assistant OS
Integration causing the issue
Niko home control
Link to integration documentation on our website
https://www.home-assistant.io/integrations/niko_home_control/
Diagnostics information
This integration is added via the configuration.yaml file so i dont realy have a card available where i can click the enable debug. Unless there is a different way.
Example YAML snippet
it's a simpel light card:
type: light
entity: light.lichtpunt_boven_eettafel
Anything in the logs that might be useful for us?
no errors as far as i know.
Additional information
Maybe some info on the attribute:
I have about 26 entities (lights) with this issue. (as my whole house is Niko) i have 2 types of lights, dimmable lights or not dimmable.
Below the 2 examples:
//Dimmable light// Entity: light.inbouwverlichting_plafond_keuken Keuken Inbouw verlichting
State: off
Attributes: supported_color_modes: brightness friendly_name: Keuken Inbouw verlichting supported_features: 0
//non-dimmable light// light.centraal_lichtpunt_inkom Inkom
State: off
Attributes: supported_color_modes: onoff friendly_name: Inkom supported_features: 0
i recorded the issue (FYI my video files were to big so i editted them and removed the "waiting period" so don't be fooled by the lenght of the video itself, updating the state of the button takes on avarage about 45 sec :)): Turning ON: https://github.com/home-assistant/core/assets/78316232/8fc396c7-d202-4f67-91d4-52f36f543fb4
Turning OFF: https://github.com/home-assistant/core/assets/78316232/18d3e6f9-7f59-4338-9a15-969e6645c8c1
1 weird thing: https://github.com/home-assistant/core/assets/78316232/8f757ac2-195a-4ee9-b673-cd2cde30789a
I noticed this before and looked into it. Basically, the NHC integration uses polling: every minute or so, it polls the gateway and updates the states. Off course, this means that there is a lag of at most 1 minute when you press a (physical or virtual) button.
To correct this, the integration should implement a monitor for the NHC gateway. This way, the integration would receive an event when an action is triggered in the NHC system, and can update the state accordingly.
This should not be very hard to do (I think), as the integration uses the niko_home_control Python library which supports this. But I currently lack the time to do so.
@jeroenvaes https://github.com/VandeurenGlenn/core-1/tree/integrate-nhc-cover-2 I added cover support and was working on switching to events but whatever I do they always end up blocking the thread so if you can figure out how it doesn't block then everything should work. (after a cleanup because at the end I was hopeless)
So hopeless I ended up making ui etc myself https://github.com/VandeurenGlenn/peace-ui
This is normal sadly, as the IOT class of Niko Home Control is Local Polling. Defintion: Offers direct communication with device. Polling the state means that an update might be noticed later.
There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.
This issue is still existing
Hi all, I confirm I have also the same case and was not able to solve it right now. So, if someone had the opportunity to solve it, I'm realy intersted. Many Thanks!
@AFRSdev sorry to hear you have the same issue as i do. As this integration only has 11 active installations the chance that someone from HA will fix this is slim. After some research and talking with loads of people.. i understand that we need a person with a very good understanding of python that could fix this issue for us. But this matter feels in our own hands.
Do you or someone you know have any python skills? :D Also.. please join the official Home assistant discord and send me a private message anyway, i do would like to share some more info to you. I have the same username as here.
@Peacem4kr I don't have any experience with developing for HomeAssistant and have some basic Python skills, I was looking at this project to augment those :). Maybe if we all work together we can get somewhere.
I have been using OpenHab for years and there it worked flawlessly, so it should be possible. The Python library also claims to support a listener. I did notice this addon uses an older version of the library, so upgrading it would be my first step.
I'll try to make some time somewhere next week to look into it, based on the work by @VandeurenGlenn . I'll share my insights and maybe we can work something out together.
@jeroenvaes any help is appreciated, i am up for helping too, but i dont know anything of coding, so suppose its more the testing part where i can join. But do let me know if there is something i can do!
I have been using OpenHab for years and there it worked flawlessly
Same here, thats why i am kind a frustrated, as this was working more then 5 (10?) years ago in OH, but i am no coder, so can't judge. But if i am correct.. OH doesnt use python, i understould that this is the issue.
@jellenijhof12 is maybe interested as well.
I have looked in to this but I was not able to fix this in a few minutes.
The problem and solution
I thinks the problem is with Niko Home Control, because HA requests a update after toggling a light but NHC responds with the old state. So the solution would be to listen to the events, but I have not been able to get that to work.
@jellenijhof12 I already have an events based implementation, the only issue now is that it blocks the thread https://github.com/NoUseFreak/niko-home-control/blob/b4243130c7bd51531844c030453c1b4a6214cc28/nikohomecontrol/nhcmonitor.py#L29
So we just need someone who knows how to run in seperate thread or maybe need to replace netcat with something that supports threading.
Hi guys, Sorry for the delay, time is missing on my side. Thank you for your comments. I also think working on events is part of the smart solution, but the workaround with automation triggered after switching the state of a light to update status looks comfortable for me. I would like to work on thermostat and energy integration. Any ideas on your side on that subjects? Thanks!
Hi guys, Sorry for the delay, time is missing on my side. Thank you for your comments. I also think working on events is part of the smart solution, but the workaround with automation triggered after switching the state of a light to update status looks comfortable for me. I would like to work on thermostat and energy integration. Any ideas on your side on that subjects? Thanks!
Automations seem to give issues when using the physical switch if I understand correctly, so we just need events (threading to work) and this issue can be closed.
After that I'll gladly add thermostat etc.
Hi Glenn, Indeed, automation doesn't help when using physical switches as status on HA is only refreshed on the standard looping time from NHC. Hope we can find a solution with events/threading.
I think the first step is to change the niko-home-control library to make it asynchronous. I'll take a stab...
https://github.com/NoUseFreak/niko-home-control/blob/b4243130c7bd51531844c030453c1b4a6214cc28/nikohomecontrol/nhcmonitor.py#L36 https://github.com/NoUseFreak/niko-home-control/blob/b4243130c7bd51531844c030453c1b4a6214cc28/nikohomecontrol/nhcconnection.py#L32 I think the best thing todo next is trying to replace netcat with a lib that has threading builtin or atleast option to have it threaded.
propably want the changes upstream, but for testing purposes I replaced it in hub for now
I don't think replacing netcat is necessary. One can use setTimeout(0) on the socket to make it non-blocking and run reading async. I would assume that it won't block then. I have some test code that seems to work, now I need to refactor the niko-home-control lib.
@jeroenvaes it isn't if someone has low level py knowledge but setting timeout is not a solution and the rest is async already.
Hi, Did you have the opportunity to work on events? On my side, no progress so far. Do you think we can go further adding thermostats? Many thanks for your support and expertise!
I think I'm on to something but I need time to test it further. I'll probably find some time this week.
Thanks @jeroenvaes !
Hi @VandeurenGlenn, I have a solution working outside of HomeAssistant but I want to add it to your version of the component. I took your code and put it in my development image. However, when I try to add the integration via configuration.yaml I get the error that it doesn't support this, and when I try to add it via the GUI HA says it doesn't support that. Any idea why this is happening? Thanks!
Hi @jeroenvaes make sure it's out of the yaml before trying to add the integration trough UI or maybe something else is going on, have a screenshot of the error?
Hi @jeroenvaes, great to read you were able to progress on it! Thank you for your work. Did you find a way to go further within HA?
Hi guys, Do you think I could help you by testing something to go further? It would be very great if we could fin a solution. By the way, I tried to integrate the the ventilation command of NHC, which is a 3/4 states switches, but using the integration it is view as a simple switch. Any idea on how to treat that? Many thanks!
Hi, sorry I didn't reply, I was away last week. I'll find some time this week to take another look at it. If I can't get it to work I'll just commit my code to my fork and someone else can try to test it.
The ventilation switch is just a standard 4-button switch I think. NHC exposes the actions not the switches, and IIRC it doesn't expose the predefined ventilation-action. I created 3 extra actions (ventilation_low, ventilation_medium and ventilation_high) and used this template to tie them together as a fan entity:
fan:
- platform: template
fans:
ventilatie:
friendly_name: "Ventilatie"
unique_id: "zehnder_comfod350"
value_template: "on"
turn_on:
- service: light.turn_on
target:
entity_id: light.ventilation_medium
turn_off:
- service: light.turn_on
target:
entity_id: light.ventilation_low
percentage_template: >
{% if is_state('light.ventilation_high', 'on') %}
100
{% elif is_state('light.ventilation_medium', 'on') %}
66
{% else %}
33
{% endif %}
speed_count: 3
set_percentage:
- service: light.turn_on
target:
entity_id: light.ventilation_{% if percentage >= 67 %}high{% elif percentage >= 34 %}medium{% else %}low{% endif %}
preset_modes:
- "low"
- "medium"
- "high"
preset_mode_template: >
{% if is_state('light.ventilation_medium', 'on') %}
medium
{% elif is_state('light.ventilation_high', 'on') %}
high
{% else %}
low
{% endif %}
set_preset_mode:
- service: light.turn_off
target:
entity_id: light.ventilation_low
- service: light.turn_off
target:
entity_id: light.ventilation_medium
- service: light.turn_off
target:
entity_id: light.ventilation_high
- service: light.turn_on
target:
entity_id: light.ventilation_{{ preset_mode }}
Hi @jeroenvaes Thanks a lot for this great which I implemented. This allows me to find the 4-button ventilation switch o my HA interface. After testing it today, I'm not able to send the actions through the HA interfaec to NHC ventilation module. To give more details ont the NHC ventilation module and associated physical switch : the first state in "low", the second is "medium", the third is "high" and the fourth is "boost" (meaning operating in high speed for a defined period of time ans then switching back to previous state). There is no "off" state. Can this help? In addition, did you have the opportunity to find time on refactoring the niko-home-control lib with your updated code? Thank you very much for your work!