deiger / AirCon

Scripts for controlling Air Conditioners, e.g. with HiSense modules.
GNU General Public License v3.0
195 stars 54 forks source link

AEH-W4G2 #160

Open jcbshw opened 2 years ago

jcbshw commented 2 years ago

Stumbled upon this looking to connect my new Hisense AC to home assistant. It has the W4G2 wifi module and uses the ConnectLife app. Nothing really comes up for this module when googling. I have attempted adding it to the other apps but the WiFi network is HIS-####### not HiSmart-####### or the other variations it is looking for.

Anything I can do to look at having support for this AC added?

EDIT: looks like the url the AC communicates with is ac-eu-link.hijuconn.com

Monacoslo commented 8 months ago

ConnectLife API development is in progress ;)

delumerlino commented 8 months ago

ConnectLife API development is in progress ;)

Ready to test it if you need a tester!

maschmann commented 8 months ago

Current state is here: https://community.home-assistant.io/t/adding-connectlife-support/486479/21 TL;DR;

https://api.connectlife.io/swagger/index.html

//

I was thinking about building a ESP-based solution that's using a RS384 board to connect to the modbus of the airconditioner. That's pretty default throughout the models. But no time to do more research at the moment. At least it would be cloudless and could have an open API and/or MQTT access.

Lineflyer commented 8 months ago

To whomever it might concern:

I found a valid workaround for my use case: I am using a Node Red instance for smart home management (connected to Tibber, Shelly, Tesla and various others). My Hisense split A/C (using AEH-W4G2 with ConnectLife) was connected via detour over Alexa cloud. As ConnectLife interworks with Amazon Alexa I firstly installed the corresponding skill on Alexa. Then I used this NodeRed plugin/flow to connect NodeRed to Alexa. This provides the ability to interact with my A/C to query parameters (current state, current room temp) and push actions (on/off, TargetTemp, etc.)..

maschmann commented 8 months ago

You should add, that it's the Applestrudel Version, becaus the old one does not work correctly with Alexa smart devices. Checked it out as a workaround, yesterday - it's a fine workaround if you already know node red and have it integrated.

Lineflyer commented 8 months ago

@maschmann Can you provide a link to what kind of problem the old ones have? I am currently not using the version you mentioned.

Sorry for offtopic.

maschmann commented 8 months ago

The old one just did not work with smart devices (for me) and was not updated for over two years. Using text-to-speech did work, though.

// OT: before any one else goes down that rabbithole: AMZ is rate-limiting the API in a very unfortunate way. If you trigger an action via the alexa API, you cannot trigger it again within 5 minutes. Very bad if you're just testing workflows in node-red

Lineflyer commented 7 months ago

FYI: Connect Life changed to a single sign on solution in November 2023. Since then I am able to get authorized to https://api.connectlife.io/swagger/index.html and also read some data out of it:

image

Anyway I have not so much experience in programming...maybe its helpful for someone here.. I would love to see some NodeRed integration

ekashuba commented 7 months ago

Since then I am able to get authorized to https://api.connectlife.io/swagger/index.html and also read some data out of it:

@Lineflyer, good find! What credentials did you use to authorize yourself? I've tried going to this login page and using my ConnectLife credentials and I get a "wrong username or password" error. Did you use one of the other OAuth services (like "Sign in with Google")?

Lineflyer commented 7 months ago

Did you already change to the new single-sign-on credential set? The ConnectLife app asked me to update last days and afterwards I had to choose a new password. Since then I can authorize to the login page you mention.

Lineflyer commented 7 months ago

BTW: I meanwhile have build a working integration using plaing https get/post nodes in Node Red. Once you authorized on the Swagger page you can easily C&P your Bearer Token and reuse it. Using it now for 48 hours and it seems it does not expire. Right now I can read and write all the properties of my HiSense units....thats all I need. Perfect if it keeps working reliable.

mattclar commented 7 months ago

@lineflyer can you share your node red setup?

On Sun, 19 Nov 2023, 9:08 am Lineflyer, @.***> wrote:

BTW: I meanwhile have build a working integration using plaing https get/post nodes in Node Red. Once you authorized on the Swagger page you can easily C&P your Bearer Token and reuse it. Using it now for 48 hours and it seems it does not expire. Right now I can read and write all the properties of my HiSense units....thats all I need. Perfect if it keeps working reliable.

— Reply to this email directly, view it on GitHub https://github.com/deiger/AirCon/issues/160#issuecomment-1817661289, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGNYD5MGVF6UKVKVNSZUJTYFEWU3AVCNFSM5VAVJ6L2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOBRG43DMMJSHA4Q . You are receiving this because you were mentioned.Message ID: @.***>

ekashuba commented 7 months ago

@Lineflyer, yep -- I also had to update the password for my account a few days ago. In fact, that ended up being something of a problem since all of my existing devices disappeared and I had to go through the entire set up process again for each device. I'm not having any problems using that new password in the app but I can't seem to get past that authentication screen. Weird. Can you verify that I'm using the correct login page?

ekashuba commented 7 months ago

@Lineflyer -- hmmmm.... I changed my password again just in case the special character that I'd used was somehow messing up the parser but I still can't log in. I wonder if the ConnectLife folks shut down access to the API at some point after you'd already gotten your token. I'd ask you to try logging in again but I'm afraid that might invalidate the token that you're using so it's probably not worth the risk.

Has anyone else besides @Lineflyer been able to log into this site using your newly-updated ConnectLife email address and password?

ekashuba commented 7 months ago

I got in! I didn't realize that the client_id and client_secret fields were getting passed to the logon page as part of the logon process so I was just going to that Logon page directly. Once I just went through the "Authorize" button in that modal window to get to the loon page I was able to log in. Looking back I have no idea why I didn't do it that way in the first place.

HassanElDessouki commented 7 months ago

Hey!I’ve just started following this topic and I would like to contribute as I’ve got a ClassPro Split AC that uses the AEH-W4G2 WiFi Modile & ConnectLife Application. I’m just confused here about getting to sign in. Where are you getting the login token?

ThanksSent from Yahoo Mail for iPhone

On Sunday, November 19, 2023, 6:01 AM, OzoneAction @.***> wrote:

I got in! I didn't realize that the client_id and client_secret fields were getting passed to the logon page as part of the logon process so I was just going to that Logon page directly. Once I just went through the "Authorize" button in that modal window to get to the loon page I was able to log in. Looking back I have no idea why I didn't do it that way in the first place.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.Message ID: @.***>

ekashuba commented 7 months ago

@HassanElDessouki, here's what I did to get my login token (and apologies if this is more detail than you were looking for):

HassanElDessouki commented 7 months ago

@ekashuba Thanks for the detailed reply! I was about to make a reply, too.

I have finally gotten access, and I am able to get the Appliance Name and current details and also the login token!

The question now: Is there a POST API that lets you update the current property values (Temperature, Mode, Fan Speed, Power, etc)?

Lineflyer commented 7 months ago

@HassanElDessouki, here's what I did to get my login token (and apologies if this is more detail than you were looking for):

That's exactly what I did. Thanks @ekashuba , you have been faster with your reply.

Lineflyer commented 7 months ago

The question now: Is there a POST API that lets you update the current property values (Temperature, Mode, Fan Speed, Power, etc)?

Sure that: image

You have to use the appliance ID as part of the POST request.

@Lineflyer can you share your node red setup?

I will make a copy and remove my tokens and post it in a GIST shortly.

Lineflyer commented 7 months ago

You can find an extract of my NodeRed flows towards ConnectLife API here: https://gist.github.com/Lineflyer/f2553ef3005f61956d2ac26def727cca

Feel free to comment under the GIST, feedback appreciated. Hope its understandable.

HassanElDessouki commented 7 months ago

I'm trying to obtain my appliance id (auid) by supplying my ID in image

I keep getting this error message though

"errorMessage": "JuConnect.NetCore.HttpServiceException\r\n at JuConnect.NetCore.Services.JuConnectServiceBase.ExecuteRequestAsync(HttpMethod method, String url, Object data, CancellationToken cancellationToken)\r\n at JuConnect.NetCore.Services.JuConnectServiceBase.ExecuteGetRestRequestAsync(TargetUrl targetUrl, String url, Object body, CancellationToken cancellationToken)\r\n at JuConnect.NetCore.Services.JuConnectServiceBase.ExecuteGetRestRequestAsync[T](TargetUrl targetUrl, String url, Object body, CancellationToken cancellationToken)\r\n at JuConnect.NetCore.Services.JuConnectServicesBase.ExecuteGetRestRequestAsync[T](TargetUrl targetUrl, String url, Object body, CancellationToken cancellationToken)\r\n at JuConnect.NetCore.Services.ConnectLifeService.GetApplianceProfileByAuid(String auid, CancellationToken cancellationToken)\r\n at ConnectLife.WebApi.Controllers.ApplianceController.GetApplianceProfile(String ids) in C:\Users\damir\Git\Gorenje\ConnectLifeApi\ConnectLife.WebApi\Controllers\ApplianceController.cs:line 872\r\n at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)\r\n at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Logged|12_1(ControllerActionInvoker invoker)\r\n at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)"

I'm scratching my head as I can use the same copied ID in getting the current property values. In fact, a few hours ago, I could obtain the AUID. I have tried to re-login but to no avail

ekashuba commented 7 months ago

@HassanElDessouki - I also get that error when I make that same call, but I think you might be calling the wrong API.

I'm guessing that you called the first API originally and now you're trying to call the second API.

Lineflyer commented 7 months ago

Just use this endpoint to get a array with all your devices and their IDs. image

HassanElDessouki commented 7 months ago

Aha! Alright, I got it just tested it.. I was able to finally get to update the AC temperature from the API :-))

I think this means we can currently start working on implementing it to AirCon (Homebridge), right?

mattclar commented 7 months ago

I'm (GPT-4) working on a custom component, not too hard, just need to enter your bearer token

Matthew Clarke Dentist

Toorak Dental Group (03) 9826 1337 1A Grange Rd Toorak 3142 VIC http://toorakdentalgroup.com.au

On Mon, 20 Nov 2023 at 13:56, Hassan ElDessouki @.***> wrote:

Aha! Alright, I got it just tested it.. I was able to finally get to update the AC temperature from the API :-))

I think this means we can currently start working on implementing it to AirCon (Homebridge), right?

— Reply to this email directly, view it on GitHub https://github.com/deiger/AirCon/issues/160#issuecomment-1818149451, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGNYD5RZEP3EVSJWBIJV2TYFLBGHAVCNFSM5VAVJ6L2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOBRHAYTIOJUGUYQ . You are receiving this because you were mentioned.Message ID: @.***>

delumerlino commented 7 months ago

I have received today both connectlife app update and firmware update. Something is updating?

HassanElDessouki commented 7 months ago

Hey! I've put some time into this day, and I've got some results

I worked on a nodeJS code that can get the data using ConnectLife's API, and then using the plugin (homebridge-http-advanced-accessory), I defined a new HeaterCooler Accessory, and accordingly, I defined each URL to my nodeJS routes.

I'll be uploading my code shortly. In the meantime, I've had some issues, though. 1: I am not able to get other modes (such as Dry/Fan) to add then 2: I cannot remove the Heat mode (my AC doesn't have a heater, it's only cooling 3: The ConnectLife v1 API does not have a property for SwingMode. I'm not sure if this would be added later on, 4: the status when the Current Room Temperature is equal to or less than the Desired Temperature changes from "Cooling" to "Cool to XX°" Isn't this supposed to show "Idle"?

Included in this URL are some pics: https://www.flickr.com/photos/197860237@N02/sets/72177720312933528/

HassanElDessouki commented 7 months ago

you can check the code and steps to run it here: Homebridge-ConnectLifeAC

maschmann commented 7 months ago

If you use the client_id and secret from the OpenAPI auth form, you could use the OAuth2 flow with the provided URLs. I'm fiddling with node-red at the moment (https://flows.nodered.org/node/node-red-contrib-oauth2) to do the auth stuff automated.

Lineflyer commented 7 months ago

@maschmann I failed to get it running in NodeRed to authenticate and - even more important - to get a refresh token before the bearer token expires. If you make any progress I would highly appreciate if you would share it here. I have no deep experience with oauth and seem to be to stupid :-)

maschmann commented 7 months ago

@Lineflyer I was not able to catch the secret from the form submission the OpenAPI makes to the login form. Thos two factors together create the bearer token. Without the secret, no way to do the login automatically.

Lineflyer commented 7 months ago

I contacted ConnectLife with the request regarding an way to retrieve needed authentication keys. This is their answer:


Thank you for reaching out to ConnectLife supporting team! We apologize for the inconvenience this causes you and we'll gladly assist you.

We understand that compatibility with a wide range of platforms is important for our users, and we want to ensure that ConnectLife meets your needs and preferences. Our developing Team is working on API access. Although we cannot provide an exact timeline for when it will be available at this moment, we want you to know that your patience and support are greatly appreciated.

We are aiming by the end of the year based on our current progress. However, I would like to emphasize that this is an estimation and may be subject to adjustments as we strive to deliver the best possible product.

andy2002a commented 7 months ago

Made this which has been working well when executed manually:

https://community.home-assistant.io/t/add-integration-for-hisense-devices-using-connectlife/459082/36?u=andy2002a

adude00 commented 7 months ago

Made this which has been working well when executed manually:

https://community.home-assistant.io/t/add-integration-for-hisense-devices-using-connectlife/459082/36?u=andy2002a

Hey did you delete the repo by any chance? I wanted to check it out and it's shows not found now :/

andy2002a commented 7 months ago

Made this which has been working well when executed manually: https://community.home-assistant.io/t/add-integration-for-hisense-devices-using-connectlife/459082/36?u=andy2002a

Hey did you delete the repo by any chance? I wanted to check it out and it's shows not found now :/

It will be back up on Monday, had to take it down temporarily.

andy2002a commented 7 months ago

Made this which has been working well when executed manually: https://community.home-assistant.io/t/add-integration-for-hisense-devices-using-connectlife/459082/36?u=andy2002a

Hey did you delete the repo by any chance? I wanted to check it out and it's shows not found now :/

back up now: https://github.com/andy2002a/HA-ConnectLife/blob/main/poc.py

vpaulos commented 7 months ago

Hi everyone, does this solution work for managing air conditioners and units now?

adude00 commented 6 months ago

back up now: https://github.com/andy2002a/HA-ConnectLife/blob/main/poc.py

Thanks. Am I doing something wrong or they just removed the whole appliance API?

andy2002a commented 6 months ago

Thanks. Am I doing something wrong or they just removed the whole appliance API?

~Yup... getting back a 404 now~

seems to be back up now

bartashevich commented 6 months ago

Hi all, I've successfully authenticated but when trying to get all my appliances (api/v1/appliance) I'm getting []. I only have Hisense Heat Pump. It works well with ConnectLife app, but I don't see it in API. Any ideas?

Lineflyer commented 6 months ago

One question to @andy2002a , @adude00 and maybe others: If I get you right, you managed to get a permanent working API connection in your home assistant, node red, etc. How is that possible without having a real key (which would allow to refresh the token)? The token derived from the Swagger page, which I used for my proof of concept has only some hours or days of validity.

Did I miss something?

andy2002a commented 6 months ago

One question to @andy2002a , @adude00 and maybe others: If I get you right, you managed to get a permanent working API connection in your home assistant, node red, etc. How is that possible without having a real key (which would allow to refresh the token)? The token derived from the Swagger page, which I used for my proof of concept has only some hours or days of validity.

Did I miss something?

I don't have permanent access. I just use the token from the page when testing.

It might be possible to refresh it with the https://api.connectlife.io/api/v1/debug/get-token/ query, but that hasn't worked for me.

adude00 commented 6 months ago

@Lineflyer you're right, the token is only valid for a while. It might be days, it might be hours, it's totally random.

Not only that, but the API is extremely unreliable: I was writing some simple bash script to use the API and I had to implement some retry system and even that sometimes it wouldn't work for 30 or more seconds continuous requests.

Also, the functionality is very basic as you're only allowed to choose mode, fan speed and temperature. No swing/silent/turbo/etc.

Personally I ended controlling it using trough Alexa since you can publish Alexa items on OpenHAB to control them.

Lineflyer commented 6 months ago

Thanks for both your feedback. I also experienced the issue with responsibility of the server and the randomness in validity. IMHO the get-token will not work as long as you don't have a key to get a new token.

Whatever let's then wait until ConnectLife hopefully makes this officially available, which they announced. I believe they are really working on it, as they already migrated the authentication in November to some single-sign-on, which from then on allowed using the API.

apphancer commented 6 months ago

I just found this issue a few minutes ago and had the same question @Lineflyer made only minutes ago. It's great to see there are at least some attempts by ConnectLife to provide an API, but it's unfortunate this cannot be used until they provide a way to create and refresh tokens outside of Swagger UI.

@adude00 is what you mentioned something that makes use of Alexa's Home API? https://developer.amazon.com/en-US/docs/alexa/device-apis/alexa-discovery.html#limits

adude00 commented 6 months ago

@adude00 is what you mentioned something that makes use of Alexa's Home API? https://developer.amazon.com/en-US/docs/alexa/device-apis/alexa-discovery.html#limits

Nope, I meant the Amazon Echo Control Bindings for OpenHAB. It allows to control not only Echo devices but also the items that the Echo itself sees.

Let's say you have a lamp that works on Alexa but doesn't work on OpenHAB: it can be controlled this way. I couldn't figure out the temperature tough, only on and off, but 'm sure there is a way as temperature can be changed by speaking to an echo device normally.

apphancer commented 6 months ago

While waiting for ConnectLife to release documentation and provide a system to allow creating one own's clientId and clientSecret, I managed to reverse-engineer the OAuth workflow for regenerating the bearer token when this has expired.

Information needed:

clientId: this is visible on Swagger UI page clientSecret: this is visible in the source code on the Swagger UI page (starts with 07swf...) access_token: this is returned after login on the Authorization URL. To get this, open the Network tab on Chrome's developer tools and before opening the Authorization URL. After successful Authentication, the Network tab should display the JSON for the request made to https://oauth-gateway.hijuconn.com/oauth/token expires_in: this values should always be 1440 seconds. The value is returned in the Network tab as described above refresh_token: the value is returned in the Network tab as described above.

Once you have the refresh_token, you can request new tokens when the previous if the token has expired by making further requests to https://oauth-gateway.hijuconn.com/oauth/token

Here's a very basic cURL request for this:

curl -X POST https://oauth-gateway.hijuconn.com/oauth/token \
    -d "grant_type=refresh_token" \
    -d "refresh_token=YOUR_REFRESH_TOKEN" \
    -d "client_id=YOUR_CLIENT_ID" \
    -d "client_secret=YOUR_CLIENT_SECRET" \
    -H "Content-Type: application/x-www-form-urlencoded"

Values YOUR_REFRESH_TOKEN, YOUR_CLIENT_ID and YOUR_CLIENT_SECRET would need to be replaced.

Lineflyer commented 6 months ago

Thanks @apphancer for the helpful reverse engineering. Refreshing tokens and using the (unofficial) API is now working for over a week.

While getting status and setting basic parameters is helpful, I still wonder why I am unable to

Any insights or helpful experience on this?

Samorja commented 6 months ago

Hello @Lineflyer, it your solution based on HA + node red by any chance? If so, can i ask you to share it? Im able to help with the testing maybe even with coding missing functionalities. Thanks