tuyanet icon indicating copy to clipboard operation
tuyanet copied to clipboard

Newbie Trying to control a single switch device

Open mrrcomp opened this issue 6 months ago • 1 comments

hi

Using this code i can get the devspec of the device Console.WriteLine($"Device: {device.Name}, device ID: {device.Id}, local key: {device.LocalKey}");

            var dev = new TuyaDevice(ip: device.Ip, localKey: device.LocalKey, deviceId: device.Id    );
             
            var devspec = await api.RequestAsync(TuyaApi.Method.GET, $"/v1.1/devices/{device.Id}/specifications");

This returns the following specs.

"category": "tdq", "functions": [ { "code": "switch_1", "dp_id": 1, "type": "Boolean", "values": "{}" }, { "code": "countdown_1", "dp_id": 9, "type": "Integer", "values": "{"unit":"s","min":0,"max":86400,"scale":0,"step":1}" }, { "code": "relay_status", "dp_id": 38, "type": "Enum", "values": "{"range":["0","1","2"]}" }, { "code": "light_mode", "dp_id": 40, "type": "Enum", "values": "{"range":["relay","pos","none"]}" }, { "code": "child_lock", "dp_id": 41, "type": "Boolean", "values": "{}" }, { "code": "cycle_time", "dp_id": 42, "type": "String", "values": "{"maxlen":255}" }, { "code": "random_time", "dp_id": 43, "type": "String", "values": "{"maxlen":255}" } ], "lang_config": {}, "status": [ { "code": "switch_1", "dp_id": 1, "type": "Boolean", "values": "{}" }, { "code": "countdown_1", "dp_id": 9, "type": "Integer", "values": "{"unit":"s","min":0,"max":86400,"scale":0,"step":1}" }, { "code": "relay_status", "dp_id": 38, "type": "Enum", "values": "{"range":["0","1","2"]}" }, { "code": "light_mode", "dp_id": 40, "type": "Enum", "values": "{"range":["relay","pos","none"]}" }, { "code": "child_lock", "dp_id": 41, "type": "Boolean", "values": "{}" }, { "code": "cycle_time", "dp_id": 42, "type": "String", "values": "{"maxlen":255}" }, { "code": "random_time", "dp_id": 43, "type": "String", "values": "{"maxlen":255}" } ] }

I am attempting to switch the device to off using this but there is no reaction from the device?

            TuyaLocalResponse response = await dev.SendAsync(TuyaCommand.UPDATE_DPS ,dev.FillJson("{\"dps\":{\"Switch_1\":false}}"));

Hope some can tell me what i'm doing wrong...

Regards Meir

mrrcomp avatar Aug 12 '24 11:08 mrrcomp