shenxn / ha-dyson

HomeAssitant custom integration for dyson
MIT License
307 stars 59 forks source link

Get credentials #5

Closed proatwork closed 3 years ago

proatwork commented 3 years ago

Update:

@shenxn: https://github.com/shenxn/ha-dyson/issues/5#issuecomment-791887983

I've added 2FA support to libdyson (https://github.com/shenxn/libdyson). Download or clone the repo, then run python3 get_devices.py to get credentials. You may also need to install some dependencies using pip3 install -r requirements.txt.

Old

Not an actual issue, but wanted to make this available for other people

I've managed to get credentials in two ways:

1. Using libpurecool

Use this fork of libpurecool (fix_auth branch): https://github.com/bfayers/libpurecool/tree/fix_auth python3 -m pip install https://github.com/bfayers/libpurecool/archive/fix_auth.zip

  1. Create a new file called whatever.py
  2. Paste this in:

    #!/usr/bin/python3
    from libpurecool.dyson import DysonAccount
    
    dyson_account = DysonAccount("email","password","lang")
    logged = dyson_account.login()
    
    if not logged:
        print('Unable to login to Dyson account')
        exit(1)
    devices = dyson_account.devices()
    for device in devices:
        print(device.serial);
        print(device.name);
        print(device.credentials);
        print(" ");
  3. Open your DysonLink app and stare at the welcome screen :)
  4. python3 whatever.py
  5. Cross your fingers 🤞 and hope it works.

⚠️ Don't try to loging in too fast/spam the script or you'll get IP blocked by Dyson I've also noticed that I'm getting immediately denied login if I'm going through a VPN

2. Using an Android phone

You can probably do this with an iOS device, but I haven't tested (https://stackoverflow.com/a/8512455)

  1. Download the Packet Capture app from Google Playstore (https://play.google.com/store/apps/details?id=app.greyshirts.sslcapture&hl=en&gl=US)
    1. Open Dyson Link and leave it running in the background
    2. Run the Packet Capture app, allow it to create a VPN if you're prompted
    3. Hit the play button with the 1 and choose the Dyson Link app
    4. Switch to the Dyson Link app, it will probably do a quick refresh of the welcome page
    5. Switch back to Packet Capture and stop capturing
    6. Look through the captured packets for something like this: Screenshot_20210305-024635
ripburger commented 3 years ago

Thx! But I am still stuck on getting the credentials. I am running Home Assistant on a PI4, and have no idea how to get them. Any suggestions? :)

proatwork commented 3 years ago

@ripburger you need to run that python code snippet (quoted above) after installing the libpurecool library from bfayers (linked above). https://adamj.eu/tech/2019/03/11/pip-install-from-a-git-repository/

python -m pip install https://github.com/bfayers/libpurecool/archive/fix_auth.zip

soffes commented 3 years ago

@proatwork I keep getting Unable to login to Dyson account. I can use the email and password I supplied to sign in on the website. I can also curl https://appapi.cp.dyson.com/v1/userregistration/userstatus and see that my account is active with the US country.

Any tips?

proatwork commented 3 years ago

Hey @soffes Are you using the libpurecool fork above? The credentials should be the ones you use for the Dyson mobile app If I have some free time tomorrow I will write a step by step of how I managed to make it work

soffes commented 3 years ago

@proatwork I tried this:

$ python3 -m pip install https://github.com/bfayers/libpurecool/archive/fix_auth.zip
$ python3 dyson.py

dyson.py is your script from above. From reading the integration documentation it says US is a known working language. From reading the libpurecool code it actually passes the "language" as a country in the URL so I think US is correct.

I verified that the credentials I used work in the iOS app and can control my fan.

Any help would be awesome. Super appreciate your time on this! :)

proatwork commented 3 years ago

@soffes

pi@raspberrypi:[~]$ python3.7 -m pip install https://github.com/bfayers/libpurecool/archive/fix_auth.zip

Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting https://github.com/bfayers/libpurecool/archive/fix_auth.zip
  Using cached https://github.com/bfayers/libpurecool/archive/fix_auth.zip
Requirement already satisfied: netifaces in /home/pi/.local/lib/python3.7/site-packages (from libpurecool==0.6.4) (0.10.9)
Requirement already satisfied: paho_mqtt in /home/pi/.local/lib/python3.7/site-packages (from libpurecool==0.6.4) (1.5.1)
Requirement already satisfied: pycryptodome in /home/pi/.local/lib/python3.7/site-packages (from libpurecool==0.6.4) (3.10.1)
Requirement already satisfied: requests<3,>=2 in /usr/lib/python3/dist-packages (from libpurecool==0.6.4) (2.21.0)
Requirement already satisfied: six in /usr/lib/python3/dist-packages (from libpurecool==0.6.4) (1.12.0)
Building wheels for collected packages: libpurecool
  Running setup.py bdist_wheel for libpurecool ... done
  Stored in directory: /tmp/pip-ephem-wheel-cache-gm2k7gt0/wheels/7f/8a/a5/8fa837fd233e6ab9b9c1fa2d26046d8db278c5279547827ba9
Successfully built libpurecool
Installing collected packages: libpurecool
Successfully installed libpurecool-0.6.4

pi@raspberrypi:[~]$ python3.7 ~/test.py

yZZpyItgEttmmWqzUxY5HzC+y66j4K51u/O****Kpt5n6DrbrDDBtilqbImu7BcUJNPyBBy6ZIxqd+TTZsI3w==
krazar commented 3 years ago

@soffes

pi@raspberrypi:[~]$ python3.7 -m pip install https://github.com/bfayers/libpurecool/archive/fix_auth.zip

Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting https://github.com/bfayers/libpurecool/archive/fix_auth.zip
  Using cached https://github.com/bfayers/libpurecool/archive/fix_auth.zip
Requirement already satisfied: netifaces in /home/pi/.local/lib/python3.7/site-packages (from libpurecool==0.6.4) (0.10.9)
Requirement already satisfied: paho_mqtt in /home/pi/.local/lib/python3.7/site-packages (from libpurecool==0.6.4) (1.5.1)
Requirement already satisfied: pycryptodome in /home/pi/.local/lib/python3.7/site-packages (from libpurecool==0.6.4) (3.10.1)
Requirement already satisfied: requests<3,>=2 in /usr/lib/python3/dist-packages (from libpurecool==0.6.4) (2.21.0)
Requirement already satisfied: six in /usr/lib/python3/dist-packages (from libpurecool==0.6.4) (1.12.0)
Building wheels for collected packages: libpurecool
  Running setup.py bdist_wheel for libpurecool ... done
  Stored in directory: /tmp/pip-ephem-wheel-cache-gm2k7gt0/wheels/7f/8a/a5/8fa837fd233e6ab9b9c1fa2d26046d8db278c5279547827ba9
Successfully built libpurecool
Installing collected packages: libpurecool
Successfully installed libpurecool-0.6.4

pi@raspberrypi:[~]$ python3.7 ~/test.py

yZZpyItgEttmmWqzUxY5HzC+y66j4K51u/O****Kpt5n6DrbrDDBtilqbImu7BcUJNPyBBy6ZIxqd+TTZsI3w==

Hello, I have the same problem,

I reproduced what you described ☝️ and I get "Unable to login to Dyson account".

I still can logout and login to the mobile app with those credentials. I also tried with a new account without success.

Are there any other step to take into account ? Thank you.

proatwork commented 3 years ago

@krazar I created my account through https://www.dyson.com/your-dyson, if that makes any difference 🤷

you might want to make sure that you have the bfayers fork lib installed and not etheralm or CharlesBlonde

krazar commented 3 years ago

That's really strange.

I can connect with my account on the dyson website (from my region) And, to be sure, I uninstalled libpurecool and reinstall the version from bfayers from the snippet above. Nothing changes.

soffes commented 3 years ago

Same here @krazar. The bfayers fork was working for me until the most recent HA update :/

eiddor commented 3 years ago

Not able to get credentials here, either - I finally managed to get get_devices.py to run :-)

I have tried the mobile login/logout process already.

bash-5.0# python get_devices.py                                                 
Please choose your account region                                               
1: Mainland China
2: Rest of the World
Region [1/2]: 2
Region code: US
Email: my@email.com
Password: 
Traceback (most recent call last):
  File "/config/custom_components/libdyson-main/libdyson/cloud/account.py", line 127, in login_email_password
    response = self.request(
  File "/config/custom_components/libdyson-main/libdyson/cloud/account.py", line 109, in request
    raise DysonInvalidAuth
libdyson.exceptions.DysonInvalidAuth

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "get_devices.py", line 23, in <module>
    account.login_email_password(email, password, region)
  File "/config/custom_components/libdyson-main/libdyson/cloud/account.py", line 138, in login_email_password
    raise DysonLoginFailure
libdyson.exceptions.DysonLoginFailure
kintaroju commented 3 years ago

ok, i'm new to this don't shoot me, but when i enter into the bash session inside my home assistant docker session, i've tried to execute the bfayers python code, except i get the following:

bash-5.0# python3 dyson.py
Traceback (most recent call last):
  File "dyson.py", line 12, in <module>
    from .dyson_pure_cool import DysonPureCool
ImportError: attempted relative import with no known parent package

is the path for the package correct:

/usr/local/lib/python3.8/site-packages/libpurecool

I think I am missing something here to get the credential info, any help is appreciated!

eiddor commented 3 years ago

@kintaroju I managed to get get_devices.py from https://github.com/shenxn/libdyson/ to run.

Still having a problem logging in, but that's a different problem.

kintaroju commented 3 years ago

@eiddor i am guessing it's related to the new 2FA issue? lol

eiddor commented 3 years ago

@eiddor i am guessing it's related to the new 2FA issue? lol

Yeah, that's what I suspect.

kintaroju commented 3 years ago

@eiddor totally hear you. I think if the developer can somehow trigger the 2FA email and integrate the 2FA value I think we can be in the clear.

eiddor commented 3 years ago

@eiddor totally hear you. I think if the developer can somehow trigger the 2FA email and integrate the 2FA value I think we can be in the clear.

That may work ok for Dyson Local and grabbing the credentials once, but I don't know how well it would scale for the native HA Dyson implementation or @shenxn's Dyson Cloud.

I'm not a dev, so maybe I'm missing something - I think it's more a matter of Dyson catching their API up with their mobile app.

kintaroju commented 3 years ago

@eiddor , you are right, but let's see what developer can do.

if the developer can figure this out, big thank you in advance!

monsieurlatte commented 3 years ago

I manually copied the github folder and when I go into the libepurcool folder and run dyson.py I get this.

C:\Python\libpurecool\libpurecool>python dyson.py Traceback (most recent call last): File "dyson.py", line 12, in from .dyson_pure_cool import DysonPureCool ImportError: attempted relative import with no known parent package

proatwork commented 3 years ago

@monsieurlatte you're not supposed to run that :) create a new .py file and paste the snippet from the first comment then run that

monsieurlatte commented 3 years ago

Thanks, that helps a ton, figured it out, now I just get the same as everyone else with the whole unable to log into dyson account.

proatwork commented 3 years ago

I also managed to get the credentials by using my android phone. https://play.google.com/store/apps/details?id=app.greyshirts.sslcapture&hl=en&gl=US

I used this to monitor the Dyson app for a couple of seconds (by pressing the triangle icon with the 1, and selecting Dyson Link), and lo and behold, the credentials. The serial and credentials are separated by an X, at least in my case

Screenshot_20210305-024635

monsieurlatte commented 3 years ago

I also managed to get the credentials by using my android phone. https://play.google.com/store/apps/details?id=app.greyshirts.sslcapture&hl=en&gl=US

I used this to monitor the Dyson app for a couple of seconds (by pressing the triangle icon with the 1, and selecting Dyson Link), and lo and behold, the credentials. The serial and credentials are separated by an X, at least in my case

Screenshot_20210305-024635

that's awesome, dont see anything for iOS in my first look through the app store.

proatwork commented 3 years ago

Haven't tested, but maybe you can make it work with Bluestacks

proatwork commented 3 years ago

@monsieurlatte this might help if you've used Wireshark before https://stackoverflow.com/a/8512455

shenxn commented 3 years ago

I'll work on the new 2FA over the weekend. Hopefully that will fix the problem.

monsieurlatte commented 3 years ago

@monsieurlatte this might help if you've used Wireshark before https://stackoverflow.com/a/8512455 Thanks, I'll look into that!

monsieurlatte commented 3 years ago

So here's something, I updated the App on my phone, opened the dyson link app on the phone made sure it connected and all that. Then I just added in the HACS Dyson Cloud integration and now it works? Seems like you need the new Dyson app to trigger something to allow it to work.

soffes commented 3 years ago

Confirmed! Just opening the app and then rerunning the script with no changes fixed it for me! Thanks so much ❤️

shenxn commented 3 years ago

I've added 2FA support to libdyson (https://github.com/shenxn/libdyson). Download or clone the repo, then run python3 get_devices.py to get credentials. You may also need to install some dependencies using pip3 install -r requirements.txt.

krazar commented 3 years ago

Now, I can get the credentials. Thank you !

kintaroju commented 3 years ago

Just tried your libdyson and it works like hot cakes. Do you plan to integrate it with your Dyson local implementation @shenxn to simplify the process?

shenxn commented 3 years ago

@kintaroju Use ha-dyson-cloud (https://github.com/shenxn/ha-dyson-cloud). Set up Dyson Cloud with your account first, then all your devices will be shown as discovered entities.

Anto79-ops commented 2 years ago

hey, nice managed to get my dysons fans connected using the packet readrer on my Android phone. Question, for some, I have:

Dyson Purifier Hot+Cool Formaldehyde HP09 Dyson Pure Hot+Cool™ HP04

  1. What is the difference between "Dyson Pure Hot+Cool (new)" and "Dyson Pure Hot+Cool"?
  2. Also, I manged to add the HP09 as a "Dyson Pure Hot+Cool (new)" seems to work...but definitly not seeing the formaldehyde numbers nor the catalyst life for the formaldehyde..I guess a future update?
ghost commented 2 years ago

managed to get my dysons fans connected using the packet readrer on my Android phone

How did you do this? I have been unable to get credentials using libdyson after months of trying.

I have credentials for Homebridge, but there doesn't seem to be a way to convert them to work in Homeassistant.

Anto79-ops commented 2 years ago

managed to get my dysons fans connected using the packet readrer on my Android phone

How did you do this? I have been unable to get credentials using libdyson after months of trying.

I have credentials for Homebridge, but there doesn't seem to be a way to convert them to work in Homeassistant.

Scroll up to the instructions from monsierlatte, and that's what I followed. Once I got the username and credentials, sometimes I had to try a couple of times before it actually submitted successfully probably due to Wi-Fi connection to the fan.

ghost commented 2 years ago

cheers.

I am on iOS so was looking for it's equivalent, but Apple won't let you do it (security).

Anto79-ops commented 2 years ago

cheers.

I am on iOS so was looking for it's equivalent, but Apple won't let you do it (security).

Probably, You may wish to make friends with Android people LOL

ghost commented 2 years ago

You may wish to make friends with Android people

Ha, yes! 👍

erd82 commented 1 year ago

Maybe this post helps you: https://github.com/shenxn/ha-dyson/issues/178