krahabb / meross_lan

Home Assistant integration for Meross devices
MIT License
417 stars 45 forks source link

Transfer an ms100 from one Hub to another cause duplicate sensors #119

Closed robertolamm closed 2 years ago

robertolamm commented 2 years ago

Dear all, I tranferred an MS100 sensor (humidity and temperature) from an Hub to Another. The new sensor is added in the new Hub, but it is not deleted from the old one. So I got duplicated entities names.....

Latest version of Meross LAN is installed, Windows docker with HA 2021.11.5

deleted a MS100 sensor (temperature and humidity) from an Hub (using the Meross app), and I associate the same sensor to another Hub. When I go in Home Assistant I see the sensor in both the Hub configuration.

Seems that the sensor is not deleted (or refreshed) so I can see it in both my Hub configuration.

To explain better I attached two pictures:

image --> Could be that I am wrong, somebody has faced (and solved) the same problem ?

Thanks a lot cheers Roberto

krahabb commented 2 years ago

Hello @robertolamm , This is expected since in meross_lan entities are 'uniquelly' binded to the root device so when you move a 'subdevice' like an ms100 to another hub, even though the hw device is the same, meross_lan identifies its child entities as new under the other hub. The old entity entries too are not automatically deleted because I didn't figure out a stable mechanism to intercept the unbind from the old one so, my impression is that a missing device from one hub could be an offline one. This later assumption is not really sure on my side: I'll try to check if it's possible to detect this kind of event but for the time, being this what I guess an 'edge' case you're left with manual deletion of the old entities (HA should allow this but I'm not sure for this case since I've never had a chance to try it) Also, I've never seen any integration able to automatically delete 'stale' entities and, from my knowledge, this is also an HA core design choice since these 'stale' entities could have some data in the recorder and the user must be aware and make a 'responsible choice' about deleting these.

robertolamm commented 2 years ago

Hello @krahabb, I tried to delete the entities from the HA section but unfortunately it's not possible: when I select the entity and push "delete" HA says me that these entities are controlled by an integration so is not possible to perform the action.

I think would be great, if possible, add the function to delete them manually from the integration itself.

Thanks a lot!

krahabb commented 2 years ago

Yeah..that must be manually possible so I'll definitely check why it still thinks they're on the old hub too. Did you already restarted HA? sometimes it need to reconfigure the integration to detach the 'stale' entities. You could just reload the old hub integration without the full HA restart (I guess so)

robertolamm commented 2 years ago

Yes, I tried to restart HA and also to restart the Integration. I can try to delete the integration and reinstall it, but only thinking to this option make me cry, because I renamed all the entities (15 x 3 sensors) and I have a lot of automation and related sensors in my configuration :) I am pretty sure that after the reinstall, I will obtain the "original" names :)

krahabb commented 2 years ago

Yeah..wait a bit:) you can try disable them if not done yet..I'm checking a bit more on this I'm sometimes struggling too to delete 'vanished' entities (and I'm not sure this is only related to meross_lan but I don't want to be too selfish here) I remember I have to explicitly disable them form UI and then after some 'restarts' I can finally delete them. Maybe this is only happening on meross_lan so I'm trying to get more serious at it ;)

In order to be sure the old hub is not still publishing those lost entities (which could happen since I've never seen an unbind procedure for hub attached devices) I would need a trace from both in order to check if these entities still appear twice because both the hubs are publishing them

robertolamm commented 2 years ago

Ok, I am available for any thing you need. Only let me know how (if) I can be helpful.

Thx

krahabb commented 2 years ago

Yeah thank you :) Just go to the integration configuration panel for both of the hubs and enable the 'tracing' checkbox. You will find the captured files (1 for each device trace) under 'custom_components/meross_lan/traces' meross_lan will collect data for 10 minutes so, after this time, upload those files to this thread so I can check them

robertolamm commented 2 years ago

Hello, these are the two files.

I only checked on for the 2 integrations the checkbox, I reloaded the Integration w/out restart HA.

I hope it is enough, be free to ask me for other tasks.

msh300-1638020203.csv msh300-1638020212.csv

krahabb commented 2 years ago

Thank you, will look at it for sure.

krahabb commented 2 years ago

Hello @robertolamm , I guess I've found the issue in code preventing the removal of stale entities (either manually or not: at the time meross_lan still thinks they're in place) The only two options are:

robertolamm commented 2 years ago

Hi @krahabb thank you so much.

I will wait for your patch since I am not stopped :) , in the meantime I will to install the new release (I seen there is a new one available from yesterday).

Cheers from Milan :)

robertolamm commented 2 years ago

Hello @krahabb, I installed the new version and restarted HA.

I have manually deleted the orphan entities with the button "delete", but the removed devices are visible again in the integration. So the problem seems to be partially solved.

I attached some pictures, in who we have one ms100 sensor removed from the app, and not installed in every hub (named free).

image

image

Maybe I have to do more ?

Thanks alot Roberto

krahabb commented 2 years ago

Hello Roberto, Yes I was aware of this since deleting a device entity is not easily achieved (the UI too does not allow to delete an orphan device so you're likely left with manually editing the HA core files under '.storage') I didn't investigate this too much anyway, since I thought the device (ms100) should have been 'grabbed' (HA internal configuration-wise) from the new hub on which it is now binded and so I thought your case would have been resolved this way. I can't promise anything now since it is a bit hard to test but I'll try to give some 'care' to this issue since I don't really like 'unclean' behaviours in code

robertolamm commented 2 years ago

Hello @krahabb naturally this is not a problem because I can use the devices correctly. I've seen also the .storage directory but this is too much complex to edit for my HA skills :) I duplicated the file, edited as I understood but the HA was freezed at the restart. I restored the old file and is came back to be ok. So I am scared to edit manually anymore the files 😵

Could be possible to let the user to manually delete the orphan devices in the GUI ? Or maybe is too much difficult to realize ?

However thanks a lot for your effort :)

Keep in touch. Roberto