Eufy API

From Michael's Information Zone
Revision as of 13:48, 30 April 2020 by Michael.mast (talk | contribs) (→‎API)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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)