skydiver / ewelink-api

eWeLink API for JavaScript
https://www.npmjs.com/package/ewelink-api
MIT License
264 stars 108 forks source link

Payloads #134

Open foulek57 opened 3 years ago

foulek57 commented 3 years ago

Hi @skydiver

I use this API a lot of time now, and send payload over the ws for the device that are not in this api. Now the time to share you all what i have, so if you want to add function... I'm not specialist in nodejs to pull a request, so sorry ...

The getDevicePowerUsage no more work by me, have captured the request of the app :

For the data of the day :

{
   "action":"update",
   "deviceid":"",
   "apikey":"eeb35fc4-6c51-4cd9-83fc-",
   "userAgent":"app",
   "sequence":"1609967674818",
   "params":{
      "oneKwh":"get"
   },
   "tempRec":""
}

Result :

{
   "error":0,
   "deviceid":"",
   "apikey":"eeb35fc4-6c51-4cd9-83fc-",
   "config":{
      "oneKwhData":"0.00"
   },
   "sequence":"1609967657102"
}

For the data of the last 100 days :

{
   "action":"update",
   "deviceid":"",
   "apikey":"eeb35fc4-6c51-4cd9-83fc-",
   "userAgent":"app",
   "sequence":"1609967676602",
   "params":{
      "hundredDaysKwh":"get"
   },
   "tempRec":""
}

Result :

{
   "error":0,
   "deviceid":"",
   "apikey":"eeb35fc4-6c51-4cd9-83fc-",
   "config":{
      "hundredDaysKwhData":"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006000000000000000000000003000000000000000000000000000000000000000000000000000000000000000000000000000000000404000303000000000000000000000000000000000000000006000502000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005000005000000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
   },
   "sequence":"1609966908717"
}

Note : Have not a lot of power usage this last 100 days, the data are format by 6 So 000404 = 0.44 kWh 000303 = 0.33 kWh 010203 = 1.23 kWh

...

Sonoff B1

Cold :

payload.params.channel0 = '255';
                payload.params.channel1 = '0';
                payload.params.channel2 = '0';
                payload.params.channel3 = '0';
                payload.params.channel4F = '0';
                payload.params.type = 'cold';

Warm :

payload.params.channel0 = '0';
                payload.params.channel1 = '255';
                payload.params.channel2 = '0';
                payload.params.channel3 = '0';
                payload.params.channel4 = '0';
                payload.params.type = 'warm';

RGB :

var r = 255; // 0-255
var g = 255;
var b = 255;
payload.params.channel0 = '0';
                payload.params.channel1 = '0';
                payload.params.channel2 = r;
                payload.params.channel3 = g;
                payload.params.channel4 = b;
                payload.params.type = 'middle';

IFAN :

Fan on :

payload.params = {};
                payload.params.switches = [];
                var switches1 = {};
                switches1.switch = 'on';
                switches1.outlet = 1;
                var switches2 = {};
                switches2.switch = 'off';
                switches2.outlet = 2;
                var switches3 = {};
                switches3.switch = 'off';
                switches3.outlet = 3;
                payload.params.switches.push(switches1);
                payload.params.switches.push(switches2);
                payload.params.switches.push(switches3);

Fan off :

payload.params = {};
                payload.params.switches = [];
                var switches1 = {};
                switches1.switch = 'off';
                switches1.outlet = 1;
                var switches2 = {};
                switches2.switch = 'off';
                switches2.outlet = 2;
                var switches3 = {};
                switches3.switch = 'off';
                switches3.outlet = 3;
                payload.params.switches.push(switches1);
                payload.params.switches.push(switches2);
                payload.params.switches.push(switches3);

Speed 1 :

payload.params = {};
                payload.params.switches = [];
                var switches1 = {};
                switches1.switch = 'on';
                switches1.outlet = 1;
                var switches2 = {};
                switches2.switch = 'off';
                switches2.outlet = 2;
                var switches3 = {};
                switches3.switch = 'off';
                switches3.outlet = 3;
                payload.params.switches.push(switches1);
                payload.params.switches.push(switches2);
                payload.params.switches.push(switches3);

Speed 2 :

payload.params = {};
                payload.params.switches = [];
                var switches1 = {};
                switches1.switch = 'on';
                switches1.outlet = 1;
                var switches2 = {};
                switches2.switch = 'on';
                switches2.outlet = 2;
                var switches3 = {};
                switches3.switch = 'off';
                switches3.outlet = 3;
                payload.params.switches.push(switches1);
                payload.params.switches.push(switches2);
                payload.params.switches.push(switches3);

Speed 3 :

payload.params = {};
                payload.params.switches = [];
                var switches1 = {};
                switches1.switch = 'on';
                switches1.outlet = 1;
                var switches2 = {};
                switches2.switch = 'off';
                switches2.outlet = 2;
                var switches3 = {};
                switches3.switch = 'on';
                switches3.outlet = 3;
                payload.params.switches.push(switches1);
                payload.params.switches.push(switches2);
                payload.params.switches.push(switches3);

Sonoff POW :

To get the instant data of the Sonoff Pow just send

payload.params = {};
                payload.params.uiActive = 60;

all 60 sec.

Note : uiActive = 60 sec. i send it all the 60 sec, it is what the app do, it is possible to change this value, but have not tested for >long time.

Switch "Kingart Q" (for the store)

Set the % of closing :

var setClose = 100; // 0-100%
payload.params = {};
                payload.params.setclose = setClose;

Note : If SetClose = 70 % : The shutter will be 70% closed.

Pause :

payload.params = {};
            payload.params.switch = 'pause';

I hope this can help someone.

bwp91 commented 3 years ago

I also have payloads for other devices if you can interpret my code for my homebridge plugin:

https://github.com/bwp91/homebridge-ewelink/tree/latest/lib/device

MarioDBianchi commented 2 years ago

Hi @foulek57 how do you send that payload to ewelink? Can you please provide an example

Thanks in advance

foulek57 commented 2 years ago

Hi,

After you open the socket, Just using ​socket​.​send​(​payload)​; Need to convert the payload to string before you send it with the socket const​ ​string​ ​=​ ​JSON​.​stringify​(​payload​)​; Then socket​.​send​(​string)​;

Sorry I using my mobile phone to write. So I don't have any examples by hand.