luisllamasbinaburo / EwelinkNET

eWeLink API for .NET Standard (Windows, Linux and Mac)
https://www.luisllamas.es
Apache License 2.0
35 stars 9 forks source link

EwelinkNET

EwelinkNET is an API writen in .NET Standard to interact directly with eWeLink API using your regular credentials. Compatible with Windows, Linux and MAC.

Key features

Basic usage

var ewelink = new Ewelink(Email, Password, Region);
await ewelink.GetCredentials();
await ewelink.GetDevices();

var device = ewelink.Devices.First(x=> x.deviceid == deviceId) as SwitchDevice;
device.TurnOn();

Get Credentials

Use Email, Password and Region to get Ewelink credentials, that includes required information to perform actions.

var ewelink = new Ewelink(Email, Password, Region);
var credentials = await ewelink.GetCredentials();

Alternately, you can save credentials to avoid login.

ewelink.StoreCredenditalsFromFile();

And later restore with,

ewelink.RestoreCredenditalsFromFile();

Custom API_ID

EwelinkNET uses a hardcoded API_ID and API_SECRET to authenticate. But Ewelink is changing their Auth process. So you can log into official https://dev.ewelink.cc/ and generate your own API_ID and API_SECRET

var ewelink = new Ewelink(Email, Password, YOUR_API_ID, YOUR_API_SECRET, Region);
var credentials = await ewelink.GetCredentials();

Get Devices

Get Devices registered in you Ewelink account.

var ewelink = new Ewelink(Email, Password, Region);
await ewelink.GetCredentials();
await ewelink.GetDevices();

Devices are converted to one of the following classes.

All of them are derived classes of generic Device class.

Interact with devices

Each class provides there own methods to perform actions or retrieve measurement. For example, ThermostatDevice provides

And, MultiSwitchDevice provides

Listen to device changes

Changes in devices status are obtain through websocket connection, and provided events.

ewelink.OnDeviceChanged += (s, e) => Console.WriteLine(e.AsJson());
ewelink.OpenWebSocket();

Loaded devices states are updated accordly with new state.

Zeroconf (LAN mode)

It's possible to interact with eWelink devices throught LAN mode, without the need of internet connection or access to eWelink cloud.

For LAN mode to work, a ArpTable (and list or the Mac - Ip relationship) has to be provided, to allow find the device Ip.

ewelink.RestoreArpTableFromFile();

Todo