majki09 / domoticz_lg_thinq_plugin

Domoticz plugin for LG ThinQ devices.
MIT License
21 stars 7 forks source link

Restart Plugin #15

Closed rnollen closed 1 year ago

rnollen commented 1 year ago

Hi I am using this plugin with two LG Airconditioning units using Domoticz 2023.1. The setup of this plugin is pretty straight forward and works OK. The problem that I have is that it works OK for around 2 hours. After this period of time, the plugin stops responding. The solution is then to restart the Domoticz service or I can disable and re-enable the plugin in the Hardware tab of Domoticz.

Funny thing is; I have two LG airco's (multisplit) and therefore I have 2 hardware devices listed in Domoticz using this plugin. When it stops working; both airco's cannot be controlled with Domoticz anymore, but the funny part is that disabling and re-enabling one LG hardware unit in Domoticz will make that one work again. But the strange part is that the Airco is still not working, also by disabling and re-enabling the plugin will it responds back. Is this a bug with the Domoticz plugin?

A snippit of what I see in the Domoticz logging:

Error: LG: Call to function 'onCommand' failed, exception details:
Error: LG: Traceback (most recent call last):
Error: LG: File "/home/<username>/domoticz/plugins/domoticz_lg_thinq_plugin/plugin.py", line 575, in onCommand
Error: LG: _plugin.onCommand(Unit, Command, Level, Hue)
Error: LG: File "/home/<username>/domoticz/plugins/domoticz_lg_thinq_plugin/plugin.py", line 201, in onCommand
Error: LG: self.lg_device.set_on(True)
Error: LG: File "/home/<username>/domoticz/plugins/domoticz_lg_thinq_plugin/wideq/ac.py", line 327, in set_on
Error: LG: self._set_control("airState.operation", op_value, command="Operation")
Error: LG: File "/home/<username>/domoticz/plugins/domoticz_lg_thinq_plugin/wideq/client.py", line 470, in _set_control
Error: LG: self.client.session.device_control(
Error: LG: File "/home/<username>/domoticz/plugins/domoticz_lg_thinq_plugin/wideq/core.py", line 601, in device_control
Error: LG: res = self.post(controlPath, data)
Error: LG: File "/home/<username>/domoticz/plugins/domoticz_lg_thinq_plugin/wideq/core.py", line 492, in post
Error: LG: return thinq_request(
Error: LG: File "/home/<username>/domoticz/plugins/domoticz_lg_thinq_plugin/wideq/core.py", line 281, in thinq_request
Error: LG: raise API_ERRORS
Error: LG: wideq.core.NotLoggedInError: 0102

Basically it says not logged in I guess; but the plugin uses that Wideq file for authentication. I don't know exactly how this works, but I would not suggest that restarting a service of Domoticz (or the hardware) should fix the issue. So I think there something else causing the failture after some time.

majki09 commented 1 year ago

Hi @rnollen! Thanks for your issue. I didn't tested the plugin with more than one LG device so far (I have only one LG Airco in my home). Anyway I will try to look into the code to resolve this issue. I will let you know when I will find some more free time, will you be able to do some tests then? Thanks.

rnollen commented 1 year ago

@majki09 Awesome Thanks! I think this issue in my case would also occur with one Airco unit. but not quite sure. Bu I cannot understand why disabling and re-enabling the LG Thinq Hardware in Domoticz would cause the plugin to work again or that one LG device works and the second Airco is not working yet until I restart that one also. So the question is why Domoticz gives this error after a while? If I need to test something, just let me know. I am very glad that you look into it.. Awesome Thanks!!

majki09 commented 1 year ago

@majki09 Bu I cannot understand why disabling and re-enabling the LG Thinq Hardware in Domoticz would cause the plugin to work again or that one LG device works and the second Airco is not working yet until I restart that one also. So the question is why Domoticz gives this error after a while?

I suppose you have 2 separate instances of plugin running at the same time in your Domoticz. They are both running, authorizing, polling the LG servers (and so on) at the same time, so maybe solution is that this should be done only once, for all instances. Also, plugin uses special token to communicate with LG servers and it's changing with some time, maybe around 2 hours though. So maybe it works until next token refresh... 🤔 But I need to look into this and find real cause.

For this moment I don't have more LG devices than this one I have now, so I'm unable to test it by myself. However, I will start with checking if the problem also exists with two plugin instances for only one LG device. I suppose I will get doubled communication with server like you have now. At least it should give me some conclusion. After that, when it will be needed I will ask you for help, OK?

Thanks

rnollen commented 1 year ago

@majki09 Awesome. Thank you very much; hopefully we will get somewhere and I would like to thank you that you're helping me. What you mentioned with the token; what I haven't tested yet. I have disabled the plugin for 1 airco unit in Domoticz; so that would suggest that only one hardware type is communicating with the LG servers by using the plugin. I would expect that this one will stay working over some time. I will come back with the results.

Edit -> Two hours further. Unfortunately with one Airco unit disabled; the other airco also stops working after two hours. So it is something with the token I guess; but restarting the plugin fixes it. ?

rnollen commented 1 year ago

@majki09 I did a clean reinstallation of the plugin yesterday. Deleted and reinstalled the plugin into Domoticz with only one active device in the Domoticz hardware tab. After 2 hours it stopped again. So everything looks like the refresh of the token does not work for me; but restarting the plugin within Domoticz triggers something that it is working back again. Hopefully that will help in any way in order to investigate the issue. Thanks in advance!

sixzeroone commented 1 year ago

Hi majki09, first of all thank you for all your job developing this plugin! I have the same issueof rnollen, after the last update both my LG aircondition got stuck after a while with the same logs message. furthermore when I start them with the remote controller, it doesn't update the status of devices on DZ. if you need more info I'll be glad to help you. any update or fix is appreciated

rnollen commented 1 year ago

@sixzeroone Thanks. Then I know that I am not the only one facing this issue. I haven't tested it completely with the earlier version of Domoticz, because my airco was installed just one month before 2023.1 was released @majki09 Any updates regarding this issue?

sixzeroone commented 1 year ago

I hope @majki09 figure out what cause the problem.

majki09 commented 1 year ago

Fixed with 59d40e8 commit.

rnollen commented 1 year ago

Seems to work OK :) Thanks for the effort! :)

sixzeroone commented 1 year ago

great job Majki09 ! I've updated the plugin three hours ago and seems to working fine so far, no more error and devices status are properly updated and sync.

Thank you for your time

PvdGulik commented 1 year ago

Same for me, thanks!

majki09 commented 1 year ago

Seems to work OK :) Thanks for the effort! :)

@rnollen, is it now working for your both 2 ACs? I suppose it is, but just to make sure 😉

rnollen commented 1 year ago

Seems to work OK :) Thanks for the effort! :)

@rnollen, is it now working for your both 2 ACs? I suppose it is, but just to make sure 😉

Yes! Works perfectly.

sixzeroone commented 1 year ago

Seems to work OK :) Thanks for the effort! :)

@rnollen, is it now working for your both 2 ACs? I suppose it is, but just to make sure 😉

Yes, I confirm it's working on both AC devices and both status are being update. thanks