Difference between revisions of "Eufy API"
Michael.mast (talk | contribs) (Created page with "==Purpose== To programatically work with Eufy products. <br><br> In the following example I want to turn on a smart plug that is attached to a HEPA air filter. I want this to...") |
Michael.mast (talk | contribs) (→API) |
||
(2 intermediate revisions by the same user not shown) | |||
Line 5: | Line 5: | ||
==API== | ==API== | ||
− | <ref>https://community.anker.com/t/open-api/70397/6</ref>I am having a hard time finding official documentation, but I did find a forum post with some information. | + | <ref>https://community.anker.com/t/open-api/70397/6</ref>I am having a hard time finding official documentation, but I did find a forum post with some information. There is also a great project on github that was able to point me in the right direction<ref>https://github.com/BnMcG/PyRobovac/blob/master/robovac/robovac.py</ref> |
===Authenticating=== | ===Authenticating=== | ||
+ | This was rather confusing. Pulling from various sources I realized that all existing projects pull from the same source. Someone had decrypted the API calls<ref>https://github.com/google/python-lakeside/blob/master/lakeside/__init__.py</ref> and hardcoded the following for headers. My guess is that Eufy uses this for most calls and it is required. | ||
+ | <pre> | ||
+ | client_id = "eufyhome-app" | ||
+ | client_secret = "GQCpr9dSp3uQpsOMgJ4xQ" | ||
+ | </pre> | ||
+ | ===Working with Devices=== | ||
+ | In order to work with the devices, you have to encrypt the commands and send directly to the device. This means you must be able to route to the device and not simply control it over the internet, like you would with the mobile app. | ||
+ | ===Turn switch on/off=== | ||
+ | Using the lakeside project<ref>https://github.com/google/python-lakeside</ref> I was able to lookup the switch in question, then turn it on and off. | ||
+ | |||
+ | <pre> | ||
+ | git clone https://github.com/google/python-lakeside.git | ||
+ | cd python-lakeside | ||
+ | </pre> | ||
+ | Write the script to call the functions | ||
+ | <pre> | ||
+ | #!/usr/bin/python3 | ||
+ | import lakeside, json | ||
+ | |||
+ | test=lakeside.get_devices('email address', 'password') | ||
+ | for i in test: | ||
+ | if i['name'] == 'Filter': | ||
+ | ip=i['address'] | ||
+ | code=i['code'] | ||
+ | dev=i['type'] | ||
+ | switch=lakeside.switch(ip, code, dev) | ||
+ | switch.connect() | ||
+ | switch.set_state(power=False) | ||
+ | </pre> |
Latest revision as of 13:48, 30 April 2020
Purpose
To programatically work with Eufy products.
In the following example I want to turn on a smart plug that is attached to a HEPA air filter. I want this to be turned on when the PM in the air gets to a high enough level. The filter works well in filtering the air, but it can be loud and I don't want it running 24/7.
API
[1]I am having a hard time finding official documentation, but I did find a forum post with some information. There is also a great project on github that was able to point me in the right direction[2]
Authenticating
This was rather confusing. Pulling from various sources I realized that all existing projects pull from the same source. Someone had decrypted the API calls[3] and hardcoded the following for headers. My guess is that Eufy uses this for most calls and it is required.
client_id = "eufyhome-app" client_secret = "GQCpr9dSp3uQpsOMgJ4xQ"
Working with Devices
In order to work with the devices, you have to encrypt the commands and send directly to the device. This means you must be able to route to the device and not simply control it over the internet, like you would with the mobile app.
Turn switch on/off
Using the lakeside project[4] I was able to lookup the switch in question, then turn it on and off.
git clone https://github.com/google/python-lakeside.git cd python-lakeside
Write the script to call the functions
#!/usr/bin/python3 import lakeside, json test=lakeside.get_devices('email address', 'password') for i in test: if i['name'] == 'Filter': ip=i['address'] code=i['code'] dev=i['type'] switch=lakeside.switch(ip, code, dev) switch.connect() switch.set_state(power=False)