jnimmo / pyIntesisHome

Python interface for IntesisHome devices
MIT License
35 stars 21 forks source link

[Home Assistant] Connection always lost with first command (after being turned off for some time) #43

Closed patrickvorgers closed 2 years ago

patrickvorgers commented 2 years ago

I have some automation rules in Home Assistant that will activate my Airconwithme airco for my room/office. In the morning when I start working the airco should be turned on automatically. Home Assistant does that for me but the first command always fails with a timeout. The system then tries to reconnect after a few minutes and the connection is established.

Capture

Would increasing the timeout help in this case?

FYI: When using Charles proxy between the Airconwithme app and the backend I see that the API version has changed as well the current API version is 1.8.1 instead of 1.6.2

Airconwithme API version

API version

jnimmo commented 2 years ago

Hi there, the timeout in question is controlled by the OS, but I suspect what is happening is when the command is being sent, the client discovers the connection is dead and needs to reconnect. When using Charles, do you notice if the app is sending any commands to the server on a periodic basis? We may need to just request a value every x minutes to keep the connection alive, or get pyIntesisHome to do a request before issuing a command so the connection has been re-established before it fails sending.

patrickvorgers commented 2 years ago

I did some testing and see that the API https://user.airconwithme.com/api.php/get/control is requested by the app each time the app is brought to the foreground or when the app gets focus from the OS (device goes into lockscreen and then gives the app the focus when the device unlocks).

I can't see whether a command is being sent in the meantime because sending a command is done via a different port (bytestream). Do you have a way of debugging the command stream which is established after the "get/control"?

So it seems that the app does perform a request in certain conditions to make sure that the connection is there and commands can be sent.

Jimmypl007 commented 2 years ago

Also having this issue. Although I can't confirm it's only when it's been 'off' for some time. I can see in the history log that "home assistant" gets temperature updates for about 2 hours after a reconnection (possibly a random amount of time) and then stays solid at whatever the last temperature it received before failing. Any attempt to send a command times-out and then after what seems to be a random time delay (it was 5 mins one time and 9 mins just now - I know you mentioned that's nothing to do with this). it retries and successfully connects, I am able to control the air-con perfectly fine until the next disconnect.

As mentioned above a full reboot (not just supervisor) does cause it to connect again. OR you can try to use it, have it timeout, wait for the connection attempt, and then use it again.. that works. (although incredibly annoying ;p)

I am also preeety certain that the device never loses connection to my router and I have used the specific mobile app just fine when the aircon is not connected in HA

If i can help with troubleshooting let me know, and thanks for the work you are doing.

jamhos commented 2 years ago

I've also had this one a couple of times - has been fine via the AC Cloud app at the same time.

I didn't get any further than @PatrickV2 with Charles, and the only more I can add is that the web interface (https://accloud.intesis.com/) calls a couple of things every minute on the minute, but I'm assuming this is just to refresh the panel data. 🤷‍♂️

image
jnimmo commented 2 years ago

Thanks both, mitmproxy may give some visibility of the TCP session that's established, I'll try and see if I have any old saved captures or if I can record some more to remind myself about how it works!

jnimmo commented 2 years ago

Can I confirm you're both running the custom component version from https://github.com/jnimmo/hass-intesishome ? This version of Intesishome sends a keepalive every 240 seconds (and will log it in the debug logs as 'sending keepalive to {device type}' - which I thought should solve this problem

Jimmypl007 commented 2 years ago

Can I confirm you're both running the custom component version from https://github.com/jnimmo/hass-intesishome ? This version of Intesishome sends a keepalive every 240 seconds (and will log it in the debug logs as 'sending keepalive to {device type}' - which I thought should solve this problem

I can confirm, i am not... All i did was add the lines to config. I Will try this asap ( its running at my parents home )

Update: after switching to the linked version (which I didn't know existed) I haven't had any issues for the whole day. Thanks for your time.

jamhos commented 2 years ago

Good question... I was, but switched back to the older version recently to help somebody else out. I'll switch forward again and see how it goes, thanks!

On Sat, 3 Sep 2022, at 10:36 AM, Jimmypl007 wrote:

Can I confirm you're both running the custom component version from https://github.com/jnimmo/hass-intesishome ? This version of Intesishome sends a keepalive every 240 seconds (and will log it in the debug logs as 'sending keepalive to {device type}' - which I thought should solve this problem

I can confirm, i am not... All i did was add the lines to config. I Will try this asap ( its running at my parents home )

— Reply to this email directly, view it on GitHub https://github.com/jnimmo/pyIntesisHome/issues/43#issuecomment-1236003707, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOGTGJQ2AXZO4H3XRD334QDV4KMQRANCNFSM5ZTLJDPQ. You are receiving this because you commented.Message ID: @.***>

patrickvorgers commented 2 years ago

Can I confirm you're both running the custom component version from https://github.com/jnimmo/hass-intesishome ? This version of Intesishome sends a keepalive every 240 seconds (and will log it in the debug logs as 'sending keepalive to {device type}' - which I thought should solve this problem

I was not running the custom component. I tried this evening to get it running but it doesn't work for me. During setup I get the following error: 2022-09-03 23:39:19.231 ERROR (MainThread) [pyintesishome] Error from API 'WRONG_USERNAME_PASSWORD'

I am using the correct username and password (copied it from configuration.yaml). I have selected airconwithme as devicetype.

After uncommenting the configuration in the configuration.yaml and removing the intesishome in the custom_components directory everything is working again.

Does the "internal" component conflict with the custom_components one? I did not install it via HACS because I could not find it in HACS.

jnimmo commented 2 years ago

Can you try configuring it through Config Flow (I.e the devices page and adding it through the UI)?

patrickvorgers commented 2 years ago

Can you try configuring it through Config Flow (I.e the devices page and adding it through the UI)?

That's what I did.

Steps

Jimmypl007 commented 2 years ago
  • tried to install it via HACS but failed to find it

I doubt it will help, but in future you can add a custom repository, by going to hacs and clicking the three dots in the top right and clicking "custom repository" then enter the address of the repository and select the type. (Integration - frontend) and add.

Than it will appear as a downloadable repository, just click and install. Restart and so on.

You did it manually and it sounds like it was working so this probs wont help with the password thing..

jnimmo commented 2 years ago

Very strange, thanks for detailing those steps. Would you mind creating a temporary user account on there for me to test? Seems like there might be an issue in the authentication flow and stepping it through the debugger might be the most efficient way to troubleshoot.

patrickvorgers commented 2 years ago

Very strange, thanks for detailing those steps. Would you mind creating a temporary user account on there for me to test? Seems like there might be an issue in the authentication flow and stepping it through the debugger might be the most efficient way to troubleshoot.

Sure np How best to send you a private message?

jnimmo commented 2 years ago

If you're on the Home Assistant community then could do via there https://community.home-assistant.io/u/jnimmo/ or you'll find my email https://github.com/jnimmo/pyIntesisHome/blob/master/setup.py

jnimmo commented 2 years ago

I just spotted a bug in the config flow which meant Airconwithme devices were hitting the IntesisHome endpoint, I've pushed 1.0.3 with a fix for this

patrickvorgers commented 2 years ago

I just spotted a bug in the config flow which meant Airconwithme devices were hitting the IntesisHome endpoint, I've pushed 1.0.3 with a fix for this

Great, version 1.03 fixes the authentication issue for me and I am now running the 1.03 version. I will test this version and see whether the issue stil occurs.

My airconwithme supports eco mode but I don't see it back in the UI. The same also applies to vertical vane position which I cannot set in the UI. I currently use a shell script to work around those issues and set them manually.

jnimmo commented 2 years ago

Hey @PatrickV2 I'll close this ticket if the original issue is now fixed; but please feel free to open a request for looking at the eco mode