magico13 / PyEmVue

Python Library for the Emporia Vue Energy Monitor
MIT License
185 stars 36 forks source link

Outlet API to set Outlets #56

Closed Chris-656 closed 4 months ago

Chris-656 commented 7 months ago

I have a question ? Is there a new API documentation für emporia ?

I studied the API documentation. Are there any news regarding the outlets ? I am using node 18.x for creating iobroker.adapter

Is the outlet API working ? GET /customers/outlets

[ { "deviceGid": 1234, "outletOn": false, "parentDeviceGid": null, "parentChannelNum": null } ]

I get the error code 403. To get the list of outlets I used const url = "https://api.emporiaenergy.com/customers/devices/status"; const params = { headers: { authtoken: this._tokens.IdToken }, method: "GET", };

But is there a way to PUT the data over API in oder to set an outlet On or Off

Used Environment: Javascript, Node in Iobroker, Adapter creation

magico13 commented 7 months ago

I don't always keep that API docs file up to date. You've found the right GET call but the outlets endpoint should still work for PUT.

Get outlets (and more): GET customers/devices/status

Update outlet: PUT devices/outlet

{
    "deviceGid": 12345,
    "outletOn": true
}
Chris-656 commented 7 months ago

I don't always keep that API docs file up to date. You've found the right GET call but the outlets endpoint should still work for PUT.

Get outlets (and more): GET customers/devices/status

Update outlet: PUT devices/outlet

{
    "deviceGid": 12345,
    "outletOn": true
}

This my javascript code. Do i make an error in the request. The request return statusCode 400.

EDIT: Changed a view things and with this it works now !!!

async putOutletPromise(devideGid, value) {
        const url = `https://api.emporiaenergy.com/devices/outlet?deviceGid=${deviceGid}&outletOn=${value}`;
        const params = {
            headers: {
                authtoken: this._tokens.IdToken
            },
            method: "PUT"
        };
        return new Promise((resolve, reject) => {
            request(url, params, (error, response, body) => {
                if (!error) {
                    const data = JSON.parse(body);
                    resolve([response.statusCode, data]);
                } else {
                    reject(error);
                }
            });
        });
    }

this version worked for me best Regards Chris