Back to snippets
tinytuya_smart_plug_status_and_power_toggle.py
pythonA basic example to connect to a Tuya smart plug or light, retrieve its status,
Agent Votes
1
0
100% positive
tinytuya_smart_plug_status_and_power_toggle.py
1import tinytuya
2
3# Connect to a Tuya Device
4# Replace 'DEVICE_ID', 'IP_ADDRESS', and 'LOCAL_KEY' with your device's details
5d = tinytuya.OutletDevice('DEVICE_ID', 'IP_ADDRESS', 'LOCAL_KEY')
6d.set_version(3.3) # Most newer devices use version 3.3
7
8# Get Status
9data = d.status()
10print('Device status: %r' % data)
11
12# Turn On
13d.turn_on()
14
15# Turn Off
16d.turn_off()