ndg63276 / smartathome

GNU General Public License v3.0
50 stars 15 forks source link

[FEATURE REQUEST] Show power information for smart sockets #4

Open KaMyKaSii opened 2 years ago

KaMyKaSii commented 2 years ago

I would like to be able to see this information without relying on my smartphone. Thank you.

ndg63276 commented 2 years ago

What model number do you have?

KaMyKaSii commented 2 years ago

This one. If you need the Smart Life app private traffic I can provide it for you.

ndg63276 commented 2 years ago

If you open the developer console (F12 key usually) and type

device_list

You should get a list of your devices. If you expand the details for the smart socket, you could see if the information is already in the data the website gets from Smartlife. If it is, I can add it to the website. If not, I can't.

webmake commented 2 years ago

I think my needs match the author's feature request. So I analyzed library scripts, and I see that only 3endpoints are used: auth.do access.do skill

But for measuring consumption, there is "logs" endpoint. I used tuya cloud explorer. From documentation: GET /v1.0/devices/xxxid/logs?start_row_key=xxxx_1&type=1,2&start_time=1545898159931&end_time=1545898159935&size=20

or real example: curl --request GET "https://openapi.tuyaeu.com/v1.0/devices/xxxx_1/logs?end_time=1761779264392&start_time=0&type=7" --header "sign_method: HMAC-SHA256" --header "client_id: xxxxx" --header "t: 1661293844933" --header "mode: cors" --header "Content-Type: application/json" --header "sign: yyyyyy" --header "access_token: zzzz"

where 7 data point report, (Types supported by log query. Supports query of multiple event types, separated by commas (,), must be transmitted. (1 online, 2 offline, 3 device activation, 4 device reset, 5 instructions Issue, 6 firmware upgrade, 7 data point report, 8 device semaphore, 9 device restart, 10 timing information))

and results are paginated.

My device is: "model": "SMART PLUG-WIFI-D", "name": "SMART PLUG",

Could you add support for visualizing power consumption? That's what I managed to draw from logs via excel image It seems data is enough for that

Thanks

ndg63276 commented 2 years ago

Oooh, nice work. Gonna be hard though, my site is using an old API set up for homeassistant, https://px1.tuyaeu.com/homeassistant/. Can you point me towards the documentation you mention? Did you have to register to use openapi.tuyaeu.com? And what smart plug do you have?

KaMyKaSii commented 2 years ago

@webmake from where you get the access_token value? I'm intercepting the Smart app (Android) traffic with ssl pinning disabled but with the calls to https://a1.tuyaus.com/log.json I can only get other parameters like cliendId, sign, deviceId, sid, ttid...