tuya-iot-python-sdk icon indicating copy to clipboard operation
tuya-iot-python-sdk copied to clipboard

get energy stats?

Open fhempy opened this issue 3 years ago • 3 comments

Hi, is there a way to get the energy statistics of the device via this API or via general cloud API calls? That would be really great, as that is an important feature for most of the users.

Thx!

fhempy avatar Oct 09 '21 20:10 fhempy

I found this one: https://developer.tuya.com/en/docs/cloud/device-data-statistic?id=Ka7g7nvnad1rm

Unfortunately I don't know which service needs to be authorized to allow the usage. Currently I get code 1004 as result.

fhempy avatar Oct 10 '21 08:10 fhempy

1004 means the signature is invalid. Can you provide your code and logs?

tsutsuku avatar Oct 15 '21 03:10 tsutsuku

I added the following code before this line (https://github.com/tuya/tuya-iot-python-sdk/blob/83f1e999d75ef87b2170ffbbb239ca8651dab0c3/tuya_iot/device.py#L577):

    def get_device_stats(self, device_id: str) -> dict[str, Any]:
        response = self.api.get(f"/v1.0/devices/{device_id}/statistics/hours")
        return response

Do I need to use a different api to access such endpoints?

fhempy avatar Oct 21 '21 15:10 fhempy