[EDGE] [ALPHA] Ewelink LAN control using edge driver

I have written an edge driver GitHub - mystifier-gh/sonoff-edge
Currently it supports only switch/light and brightness control.

Everyone is welcome to use it and perhaps maintain it as well.

eWelink (sonoff and other brands) smartthings edge driver

eWelink devices broadcast their status on mDNS (which works on LAN) and can be send commands on LAN. This edge driver uses mDNS to update device state and http commands over LAN to set device states.

eWelink encrypts the communication, both mDNS broadcasts and http commands for non-DIY mode devices. The decryption key is devicekey and can be retrived from eWelink server using eWelink credentials. Each device type is identified using uiid and can be used to configure the devices in greater detail. uiid can also be retrived along with devicekey and lots of other device data from eWelink server. devicekey and uiid possibily never change during the lifetime of device.

Steps to install

Install the driver and search for the virtual hub

Subscribe to channel and install the driver ewelink LAN Driver (0a4bfd5c-adb0-404f-8da4-acc5287372ef)

Then open Smartthings app, Add deviceSearch nearby. You will see a device ewelink virtual hub Click Done.

You will also see the ewelink devices in 30 seconds. But these devices maynot work as they require encryption key.

Update the devices with eWelink data

Download script ewelink.js

Ensure node version is v20 or newer. It may run in earlier versions as well.

node -v 
v20.6.1

then run the script

node ewelink.js username password region [port]

where

username is your username at eWelink.

password is your password at eWelink.

region is your server at eWelink. one of us, cn, eu or as

port is the local port to listen to. Optional, default to 8003.

You should see a lot of json

{
    "xxxxxxxxxx": {
        "name": "Hallway light",
        "deviceid": "xxxxxxxxxx",
        "apikey": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx",
        "extra": {
            "uiid": 1,
            "description": "20191112004",
            "brandId": "5c4c1aee3a7d24c7100be054",

followed by

    serving at http://10.0.0.41:8003/

From the above json data, extract the device key and set it in the settings.

  • Feed from the server:

    Open Smartthings app, find the device ewelink virtual hub , select it and click 3 dots and select settings . In Url enter the your server URL from above (eg. http://10.0.0.41:8003/ ) and save. You should now see the devices added.

    Stop the server and we do not need it anymore. All stuff from now happens on LAN.

  • Set the device key

    Extract the device key from the above output and set it on corresponding device

To add support for a device

The types of device supported by ewelink is identified by uiid. In the above json dump you will see the value for each of the devices at data.thingList.itemData.extra.uiid

For example:

{
    "error": 0,
    "msg": "",
    "data": {
        "thingList": [
            {
                "itemType": 1,
                "itemData": {
                    "name": "Hallway light",
                    "deviceid": "xxxxxxxxx",
                    "extra": {
                        "uiid": 1,
                        "description": "xxxxxxxx",
                        "brandId": "5c4c1aee3a7d24c7100be054",

Each uiid is explained in UIIDProtocol

Add a smartthings device profile for the uiid and corresponding handlers.

Go ahead and enjoy !!!

2 Likes

Is that means that you can connect ewelink devices straight to smartthings app?

Could you post the link to your driver channel so people can easily install your driver?

Yes. eWelink devices broadcast their status on mDNS locally and can be send commands locally. This edge driver uses mDNS to update device status and local http commands to set its status.
But there information like device key and device type that are required to create the devices. These information never change. Users run a python server locally on computer to seed this information to driver once. The server can stop after that forever.
Everything for then runs on LAN.

1 Like

I am not sure the steps to publish my channel. I will try to figure it out and post it.

1 Like
1 Like

A “read me” file in github with the setup Instructions would be helpful also. :sunglasses:

1 Like

Done. Hopefully with enough info :slight_smile:

3 Likes

I get 403 Forbidden error when I try to access my your channel. @nayelyz any thoughts on how to fix this.

Anyone been able to get this up and running?

No, were you able to install the Edge Driver?

No, same error

1 Like

The 403 error in this context is almost always because it’s the wrong link, usually the one used after you’ve subscribed to the channel. The channel author needs to publish the link used to accept new subscriptions. That’s available in the CLI.

1 Like

thanks. I create a link using edge:channels:invites:create and updated url. perhaps this will work

2 Likes

That fixed it.

I was able to enroll my hub, add driver and create the eWeLink virtual hub. When I get home tomorrow I will try to complete the setup.

Thank you for creating and sharing this driver.

2 Likes

Enrollment has been fixed.

2 Likes

@Mystifier I have the ewelink driver installed and the “ewelink virtual hub” in the mobile app.

Now I am lost at the next part, I am using a windows 10 laptop:

To run server download hub.zip and run ---- I downloaded hub.zip and extracted it. Hub.zip and the extracted folder “hub” both currently resides in my download folder. Is this correct?

python hub.zip -u -p --region --port

username - I assume this is my ewelink user name with is an e-mail address.
password - I assume this is my ewelink password
region - I am in the US what would this be? I have seen both Americas and US listed on different websites.
port - what port I am looking for?

When I try to run

python hub.zip -u -p --region --port

with the information filled in I get an error “The system cannot find the file specified.”

Guidance would be appreciated.

EDIT:
I played with this a little more.

When I run python.exe I get a window and I pasted in your command from the 1st post I get “invalid syntax”

I think you might not have python dependencies. aiohttp and pycryptodome.

Do not extract hub.zip. Python knows how to extract and run zip file :slight_smile:

set -u your username and -p password of ewelink
set port to 8003 (or something that does not conflict with you existing apps )
set region to ‘us’ if its us otherwise ‘cn’ or ‘eu’ or ‘as’

use python hub.zip --help to see more info

I have updated the driver to find devices with server url (from mDNS only) . It will require device key later though in settings. I have a js script as well as python script (hub.zip) to download the device keys. Its in github but will package it and share soon.

js script usage
ewelink.js

node ewelink.js  "<your username>" "<your password>" "<your region. one of us, cn,eu or as>"
1 Like

I have some iFan04 at home that should be great to be added.

Once we get over the initial hiccups it should be easy add!!

1 Like