personalapps
Member
I am using python 'tinytuya' module to control my smart plug using this python snippet. Can this be converted to wok with pybridge?
count down smart plug python code:
import time
import tinytuya
# device info
DEVICE_ID = "xxxxxxxxxxxxx"
DEVICE_IP = "1xxxxx123x"
LOCAL_KEY = "xxxxxxx"
# Connect to the device
plug = tinytuya.OutletDevice(DEVICE_ID, DEVICE_IP, LOCAL_KEY)
plug.set_version(3.4) # Most Tuya devices use version 3.3
# Get current status
status = plug.status()
is_on = status.get("dps", {}).get("1", False) # Check if plug is ON
# Turn ON the plug if it’s OFF
if not is_on:
print("Plug is OFF. Turning it ON...")
plug.set_value(1, True) # Turn ON
time.sleep(2) # Wait for 2 seconds to ensure it's on
# Start the countdown (10 minutes = 600 seconds)
print("Starting 1-minute countdown...")
plug.set_value(9, 60)
# Wait for the countdown to finish
print("Waiting for countdown to complete...")
time.sleep(60) # Wait for 1 minutes
# Check final status
final_status = plug.status()
is_final_on = final_status.get("dps", {}).get("1", False) # Check if plug is still ON
if not is_final_on:
print("Countdown finished. Plug is now OFF.")
else:
print("Countdown finished, but the plug is still ON!")