It seems that it will be charged from 2020/11/1. I've used it on webhooks so far, but it doesn't work. There is no choice but to develop alternatives. When I looked it up, it seems that it can be controlled by python, so I tried it.
I wasn't using it all the time, I just wanted to be able to turn the power on and off, so my motivation was to take the trouble to receive a paid service.
Basically, if you can use tinytuya, you can control it from python. However, in order to control with tinytuya, Device ID (= virtual ID), IP Addr, local key are required. Therefore, tuyapower (Python3) and tuya-cli (node) are required. There are many front stages and it is troublesome.
--Get IP Addr, virtual id with tuyapower --Get a local key with tuyacli (registration to iot.tuya.com required) --Control the target switch with tinytuya
Most of it is still written on tinytuya's github etc. Also called mere Japanese localization.
tinytuya / tuyapower / tuya-cli
# Install required libraries
$ sudo apt-get install python-crypto python-pip # for RPi, Linux
$ python3 -m pip install pycryptodome # or pycrypto, pyaes or Crypto
$ python3 -m pip install tinytuya # or pytuya
$ python3 -m pip install tuyapower # this tuyapower module
$ npm i @tuyapi/cli -g
Only tuya-cli is npm.
Device ID, IP address
$ python3 -m tuyapower
TuyaPower (Tuya compatible smart plug scanner) [0.0.25] tinytuya [1.0.3]
Scanning on UDP ports 6666 and 6667 for devices (15 retries)...
FOUND Device [Valid payload]: 192.168.x.xx
ID = 02xx11xxbcxxc2xxffxx, product = xxSUxxTWxx8ExxTw, Version = 3.1
Stats: on=False [Timeout polling device]
FOUND Device [Valid payload]: 192.168.x.xx
ID = 02xx77xxbcxxc2xx99xx, product = xxSUxxTWxx8ExxTw, Version = 3.1
Stats: on=False [Timeout polling device]
FOUND Device [Valid payload]: 192.168.1.62
ID = 03xx01xxdcxx22xxccxx, product = xx0VxxFcxxBTxxWt, Version = 3.1
Stats: on=True, W=0.1, mA=0.0, V=0.0 [OK]
Scan Complete! Found 3 devices.
We have 3 smartlife devices, so 3 will be displayed. The important thing is the ID and IP Address. Enter this ID as the tuya-cli virtual ID.
local key Tuya API key / Tuya secret
From iot.tuya.com, go to cloud Development and get the Tuya API and Tuya secret.
Access ID = Tuya API key Access Secret = Tuya secret
local key
Get it by running tuya-cli wizard. Targets key terms in json format.
$ tuya-cli wizard
? The API key from tuya.com: nnxxxxxxxxxxxxxxxxur
? The API secret from tuya.com 53xxxxxxxxxxxxxxxxxxxxxxxxxxxxa3
? Provide a 'virtual ID' of a device currently registered in the app: 03xxxxxxxxxxxxxxxx08
[
{
name: 'Note A',
id: 'XXXXXXXXXXXXXXXXXXXX',
key: 'YYYYYYYYYYYYYYYY'
},
{
name: 'Note B',
id: 'XXXXXXXXXXXXXXXXXXXX',
key: 'YYYYYYYYYYYYYYYY'
},
{
name: 'Note C',
id: 'XXXXXXXXXXXXXXXXXXXX',
key: 'YYYYYYYYYYYYYYYY'
}
]
Well, this is Pakuri. We will use the information that we have struggled with above.
DEVICE_ID_HERE: Device ID, Virtual ID (obtained at tuyapower / tuya-cli) IP_ADDRESS_HERE: IP address (obtained at tuyapower) LOCAL_KEY_HERE: key (obtained at tuya-cli)
import tinytuya
d = tinytuya.OutletDevice('DEVICE_ID_HERE', 'IP_ADDRESS_HERE', 'LOCAL_KEY_HERE')
d.set_version(3.3)
data = d.status() # NOTE this does NOT require a valid key vor version 3.1
# Show status of first controlled switch on device
print('Dictionary %r' % data)
print('State (bool, true is ON) %r' % data['dps']['1'])
# Toggle switch state
switch_state = data['dps']['1']
data = d.set_status(not switch_state)
data = d.status()
print('State (bool, true is ON) %r' % data['dps']['1'])
If you just want to get the status (data = d.status ()), you don't need a local key. When calling d.set_status, an error will be returned if the correct local key is not set. If set correctly, it works as follows. After passing set_status (not switch_status), the energized state has changed from False to True.
$ python3 sample.py
Dictionary {'devId': '02XXXXXXXXXXXXXXXXeb', 'dps': {'1': False, '2': 0}}
State (bool, true is ON) False
State (bool, true is ON) True
The meross system is controlled by another method. It's easier to control from python.
The end
Recommended Posts