nocmt / ewelink-api-next

CoolKit v2 API Official Library
MIT License
19 stars 4 forks source link

setThingStatus - not working as expected #21

Closed carylewis closed 2 months ago

carylewis commented 3 months ago

I am trying to use the controlDeviceDemo.js, and have have successfully logged in and have a valid token.js.

The client.device.getAllThingsAllPages returns my device, which is a 2 channel switch. I have configured the first relay as an inching switch

I can't get the setThingStatus method to work:

let r = await client.device.setThingStatus({ type: 1, id: thingList[0].itemData.deviceid, params: { "switches": [ { "switch": "on", "outlet": 0 }, { "switch": "off", "outlet": 1 } ] } })

this returns an error:

{ status: 200, responseTime: 5141, error: 4002, msg: '控制失败', data: {} }

Can someone please let me know how I can toggle the first switch for a 500ms on/off, e.g. inching.

carylewis commented 3 months ago

I forgot to put quotes around the params, and you have to specify 4 switches, even though the module I have only has 2 relays, and is UUID type 2.

Here is the updated and corrected code:

let r = await client.device.setThingStatus({ type: 1, id: thingList[0].itemData.deviceid, "params": { "switches": [ { "switch": "on", "outlet": 0 }, { "switch": "off", "outlet": 1 }, { "switch": "off", "outlet": 2 }, { "switch": "off", "outlet": 3 } ] } })

carylewis commented 3 months ago

FYI - on occasion I still get

{ status: 200, responseTime: 5193, error: 4002, msg: '控制失败', data: {} }

but sometimes the relay switches and sometimes it doesn't.

nocmt commented 2 months ago

FYI - on occasion I still get

{ status: 200, responseTime: 5193, error: 4002, msg: '控制失败', data: {} }

but sometimes the relay switches and sometimes it doesn't.

This error indicates that the device is offline. Please check the status of the device