MindrustUK / Heatmiser-for-home-assistant

Heatmiser Neo-Hub / Neostat support for home-assistant.io
88 stars 33 forks source link

BUG: Multiple instances of the integration / Heatmiser hubs cause the integration to break. #170

Closed rholighaus closed 1 month ago

rholighaus commented 2 months ago

Hi,

I have two parts of my house, a guest house and the main house. We added Heatmiser Neo intergration for the guest house and it worked find.

I have then added a second Heatmiser Neo for the main house (obviously on another IP address) and that works fine, but all entities of the first integration are now no longer working.

Has the integration been tested with more than one instance?

MindrustUK commented 2 months ago

Hi @rholighaus sorry, only just had a chance to reply to this.

An interesting use case, you have two Heatmiser NeoHub on one installation...

To answer your question, no I haven't tested this. Although it happens that I've just ended up with a second hub temporarily so I'll give this a go myself. I suspect the issue is overlapping entity names...

Have you tried the Dev branch of the code and can you confirm if it's still broken there?

Ordinarily I'd suggest using range extenders, or neoplugs acting as repeaters to expand the underlying Heatmiser Network but it sounds like you've effectively got two distinct properties in one Home Assistant installation, which is a use case I didn't expect.

rholighaus commented 2 months ago

Looks like a reboot of Home Assistant fixed the issue!

rholighaus commented 2 months ago

Looks like the problem still exists. Happy to help debug.

Sharing a few screenshots.

Clicking on the "devices" list for both instances once only showing the devices for that instance (it's the lower one with IP ending 104), the other (malfunctioning) one the same devices (wrong) plus the ones in that instance (but not working).

I clicked on the "gatehouse hallway" device to show what it looks like.

cheers Ralf

Screenshots of the heatmiser app show all thermostats are online in both instances.

image

image

image

image

image

image

baxgit commented 2 months ago

I've got the same use case, i.e. two separate buildings meaning unfortunately I have to use two Heatmiser hubs. Some time ago I made a number of attempts to use the integration with both hubs at the same time and concluded it would only ever work with one at once - I could 'add' both hubs but only the most recently added hub would work (the other would show as offline). Possibly wrongly, I concluded I'd need to manually install a second instance of the integration, but have never got round to it! Instead I use the second hub via the standard Homekit integration - not as good, but works

rholighaus commented 2 months ago

Happy to assist @MindrustUK to debug if they want to open up the integration to support more than one hub.

MindrustUK commented 2 months ago

Hi @rholighaus Did you try the dev branch? Is this happening with that version of the code too? I have a second hub temporarily so as soon as I get a chance I'll try and re-create this.

rholighaus commented 2 months ago

Sorry, could you please let me know how to install the dev branch for testing?

MindrustUK commented 2 months ago

@rholighaus Dev branch available here: https://github.com/MindrustUK/Heatmiser-for-home-assistant/tree/dev installation instructions are in the read me. Let me know how you get on.

MindrustUK commented 2 months ago

I've managed to replicate the issue. I'll investigate and see if I can pin down the cause then come up with a plan to fix.

rholighaus commented 2 months ago

I have installed the dev branch but won't test until you tell me.

MindrustUK commented 2 months ago

I've isolated the faulty logic which is causing this;

During device setup I effectively iterate through all devices returned by the Heatmiser NeoHub API. Usually something like 1 to "n" depending on the number of attached devices, and then configure the relevant device attributes etc. Assigning something like ID 1_hold_time_sensor already where ID 1 is the first device, in this example a NeoStat.

This falls apart when there are multiple hubs, as there can be multiple devices with ID 1. I need to add some additional logic to generate unique ID's based on serial number or alternative logic like combining the upstream hub's ID with the downstream devices which will again make them unique.

Will update once I've got something a bit more solid. Thanks to the good work by the HomeAssistant team this showed up in the logs almost immediately.

MindrustUK commented 2 months ago

It appears I can't programmatically retrieve the Hub's Serial number. I've requested the feature via the Heatmiser Developer Forum: https://dev.heatmiser.com/t/no-method-to-retrive-serial-nubmer-for-neohub-in-api/1298

In the interim I'll have to do something like use the IP address of the Hub to generate a Unique ID for the hubs...

MindrustUK commented 1 month ago

This should now be fixed along with a few enhancements.

@rholighaus Please give the latest commit to dev a go. I've had to re-generate the Unique ID's so you may want to delete the existing integration from home-assistant and re-provision to avoid duplicates etc.

@baxgit if you'd like to give this another go I'd welcome further testing and feedback.

baxgit commented 1 month ago

I've tested the dev branch (having removed the existing integration) and it seems to work a treat with the two hubs. There's no log errors and I seem to be able to view / control the various devices as I'd expect. Great work, thank you

rholighaus commented 1 month ago

I have tested as well and seems to work excellent - great job @MindrustUK thank you very much!!!!

MindrustUK commented 1 month ago

Excellent, thanks for the testing and feedback both! Closing ticket as complete.

rholighaus commented 1 month ago

Unfortunately, the one I added first now has lost all entities again after a home assistant restart.

And strangely, in the logfile are complaints about the instance that is actually working:

2024-09-30 18:32:54.168 ERROR (MainThread) [homeassistant.components.climate] Platform heatmiserneo does not generate unique IDs. ID Gatehouse Kitchen already exists - ignoring climate.gatehouse_kitchen

climate.gatehouse_kitchen is fully functional...

rholighaus commented 1 month ago

2024-09-30 18:32:54.227 WARNING (MainThread) [homeassistant.helpers.frame] Detected code that calls async_forward_entry_setup for integration heatmiserneo with title: 10.27.1.104:4242 and entry_id: 01J8YM69HM9PV8S8A50G7TETS3, during setup without awaiting async_forward_entry_setup, which can cause the setup lock to be released before the setup is done. This will stop working in Home Assistant 2025.1. Please report this issue.

The device ending with 104 is the one no longer working...

MindrustUK commented 1 month ago

Interesting, I've not had that error. I'll investigate further...

rholighaus commented 1 month ago

I did add two thermostats to the (still functioning) hub… Maybe that has triggered it?

Added 3rd Oct:

I removed the malfunctioning hub from the integration and restarted HA. Tgen added it again & all entities showed again. Restarted HA and they are gone again.

I think restarting HA causes the problem. Do you want log entries?

MindrustUK commented 1 month ago

I found some issues in testing to do with duplicate ID's, I didn't unique the entries correctly. I've hopefully fixed these now. At least so much as I can't re-create any further bugs in my testing.

As for the lock entry, I fixed that in a much older patch. I'm assuming you still have some stale files somewhere?

Can you please ensure the Heatmiser integration is removed from /config/custom_components/ entirely, clear out the integration in Home Assistant, restart Home Assistant and then re-clone the dev branch and re-configure.

This should hopefully resolve all your issues, let me know how you get on.

rholighaus commented 1 month ago

Tested and seems to do the trick, surviving the restart, too! Thank you very much for fixing!!

MindrustUK commented 1 month ago

@rholighaus Great, glad it's all working. If you bump into anything else please feel free to raise tickets as needed. And thank you very much for your support on the sponsorship program! Closing issue.