Tuyapower

Tuya Cloud expired

消費電力が確認できるGosundスマートプラグtinytuyaを使ってモニタリングをしていたのだが、気がついたら消費電力が採れなくなっていた。

調べてみるとtinytuya.OutletDeviceで

{'Error': 'Unexpected Payload from Device', 'Err': '904', 'Payload': None}

というエラーになっている状況はわかったものの、原因はピンとこない。

試しにtinytuya wizardしたところ、

yano@haswell:~$ python3 -m tinytuya wizard
TinyTuya Setup Wizard [1.13.2]
    Existing settings:
        API Key=acvwux..........p55y
        Secret=3b81eb715...................3819
        DeviceID=1826...........b47b
        Region=us
    Use existing credentials (Y/n): 
~~
Error from Tuya server: Error from Tuya Cloud: Code 28841002: '**No permissions. Your subscription to cloud development plan has expired.**'
Check DeviceID and Region
yano@haswell:~$

となった。

Tuya Cloudを使っているつもりは無いんだけどなー、とは思ったが、ここで駄々をこねても仕方がないのでSmart LifeTuya Cloudのアカウントを作り直し、Tuya Cloud 操作をやり直してLocalKeyを更新する事で、無事にtinytuya.OutletDeviceからも

{'devId': '1826...........b47b', 'dps': {'1': True, '9': 0, '18': 81, '19': 40, '20': 1008, '21': 1, '22': 735, '23': 31250, '24': 21478, '25': 970}}

という応答が返ってくるようになり、やれやれ。

tinytuyaとtuyapi

消費電力が確認できるGosundスマートプラグの続報。

Python API for Tuya WiFi smart devices using a direct local area network (LAN) connection or the cloud (TuyaCloud API).

jasonacox/tinytuyaより

デバイスID'18261828c4dd57XXXXXX’とローカルキー'7e5f08badbYYYYYY’が取得できたので、クラウドではなくLAN経由に対応している(らしい)tinytuyaにトライ。

まずはpython3とtinytuyaをインストールし、"tinytuya scan"でスマートプラグのIPアドレスを調査。

yano@haswell:~$ sudo apt install python3 python3-pip
yano@haswell:~$ python3 -m pip install tinytuya
yano@haswell:~$ python3 -m tinytuya scan
TinyTuya (Tuya device scanner) [1.7.2]
Scanning on UDP ports 6666 and 6667 for devices (15 retries)...
Unknown v3.3 Device   Product ID = keyneruwsdethu7u  [Valid payload]:
    Address = 172.16.NN.MM,  Device ID = 1826182870039fXXXXXX, Local Key = ,  Version = 3.3, MAC =
    No Stats for 172.16.NN.MM: DEVICE KEY required to poll for status
Unknown v3.3 Device   Product ID = keyneruwsdethu7u  [Valid payload]:
    Address = 172.16.NN.MM,  Device ID = 18261828c4dd57XXXXXX, Local Key = ,  Version = 3.3, MAC =
    No Stats for 172.16.NN.MM: DEVICE KEY required to poll for status
Scan Complete!  Found 2 devices.
>> Saving device snapshot data to snapshot.json
yano@haswell:~$

"tuyapower"だとこんな感じ。