jasonacox / tinytuya

Python API for Tuya WiFi smart devices using a direct local area network (LAN) connection or the cloud (TuyaCloud API).
MIT License
867 stars 157 forks source link

Cloud command #485

Open kstelios opened 2 months ago

kstelios commented 2 months ago

Using Cloud.py example, whenever i put a value other than 0 on countdown_1, the result always toggles state regardless of switch_1 'value' (True or False). My project: i created two batch commands to run cloud_on, cloud_off, but after some delay of 30 seconds. It could be better to use only one py file and check with If state and arguments but i am not familiar to do this.

import tinytuya

c = tinytuya.Cloud( apiRegion="xx", apiKey="xxxxxx", apiSecret="xxxxxx")

id = "xxxxxx"

commands = { 'commands': [{ 'code': 'switch_1', 'value': False }, { 'code': 'countdown_1', 'value': 0 }] } result = c.sendcommand(id,commands)`

jasonacox commented 2 months ago

I suspect the countdown command expects you want to turn on the device until countdown is reached at which it will turn it off. Have you tried just sending the countdown?

import tinytuya

c = tinytuya.Cloud(
    apiRegion="xx",
    apiKey="xxxxxx",
    apiSecret="xxxxxx"
)

device_id = "xxxxxx"  # Replace this with your actual device ID

commands = {
    'commands': [
        {'code': 'countdown_1', 'value': 0}
    ]
}

result = c.sendcommand(device_id, commands)

You can poke around the iot.tuya.com developer portal to see if gives any guidance. I would also try different combinations of sequencing different commands to see what they do.