Now in your examples you have bulb.py and this is using ""class BulbDevice(Device):"" I see you have two types A and B for different DPS.
Now both the switch and lights work on the ""class OutletDevice(Device):"" for TreatLife and I can cycle both using the modified send_raw_dps_''_.py below.
##bulb.py does print its tasks with no actions when I pounded out line 34 else: and 35 d.set_version(3.1) to get it to run as BulbDevice. Now when I use OutletDevice it fails when calling d.set_white() with an attributeError as this type probably needs to be added as type C?
Next is my snapshot.json and the switches have a "devId" and the name for my one and only switch that is "name": "Office Outside Lights". This should make it easier to get them separated as I am writing separate control polyglot Node Servers one for lighting and the other switches/dimmers.
The lights do not have "devId" in their json listing between the "dps".
Now I am trying to build a modified wizard to bring in the DEVICEID, IP, KEY and the snapshot.py is a fantastic start I see you just added!
So I will create the json, parse the data for the control of each switch and of course the token with requests.
Have one running as a Universal Devices Node Server and it is cycling a switch with manual inputs for its DEVICE key id & ip upon a token refresh every 20 minutes, but it is not working at all for actual control, lol.
I hope you do not mind my long winded message and hope to ask you some more questions along my weary path. I am 60 so it is kind of old dog with new tricks to keep my brain young. Sometime I get stuck on the simplest fundamentals mostly string formatting, lol! So for me to Len or separate out all of the switches from a json, then grab the data for DEVICE, then create another class to push that to for control, takes some brain twisting!
What's that advertisement for jellyfish brain enhancers, Previgen? lol!
import tinytuya
import time
import os
import random
DEVICEID = "BLAAAA"
DEVICEIP = "BLAAAA"
DEVICEKEY = "BLAAAA"
DEVICEVERS = "us" ##This works? instead of 3.3 which they all are
# Check for environmental variables and always use those if available
DEVICEID = os.getenv("DEVICEID", DEVICEID)
DEVICEIP = os.getenv("DEVICEIP", DEVICEIP)
DEVICEKEY = os.getenv("DEVICEKEY", DEVICEKEY)
DEVICEVERS = os.getenv("DEVICEVERS", DEVICEVERS)
print("TinyTuya - Smart Bulb RGB Test [%s]\n" % tinytuya.__version__)
print('TESTING: Device %s at %s with key %s version %s' %
(DEVICEID, DEVICEIP, DEVICEKEY, DEVICEVERS))
# Connect to the device - replace with real values
d=tinytuya.OutletDevice(DEVICEID, DEVICEIP, DEVICEKEY)
d.set_version(3.3)
# Show status of device
data = d.status()
# Generate the payload to send - add all the DPS values you want to change here
payload1=d.generate_payload(tinytuya.CONTROL, {'20': False, '22': 100, '23': 10,})
#time.sleep(1)
print('\nCurrent Status of Bulb: %r' % data)
time.sleep(2)
payload2=d.generate_payload(tinytuya.CONTROL, {'20': True, '22': 100, '23': 10,})
#time.sleep(1)
print('\nCurrent Status of Bulb: %r' % data)
#time.sleep(2)
payload3=d.generate_payload(tinytuya.CONTROL, {'20': True, '22': 1000, '23': 236,})
#time.sleep(1)
print('\nCurrent Status of Bulb: %r' % data)
# Send the payload to the device
d._send_receive(payload1)
time.sleep(2)
d._send_receive(payload2)
time.sleep(2)
d._send_receive(payload3)
#print('\nCurrent Status of Bulb: %r' % data)`
import tinytuya
import time
import os
import random
DEVICEID = "BLAAAA"
DEVICEIP = "192.168.1.137"
DEVICEKEY = "BLAAAA"
DEVICEVERS = "us" ##This works? instead of 3.3 which they all are
# Check for environmental variables and always use those if available
DEVICEID = os.getenv("DEVICEID", DEVICEID)
DEVICEIP = os.getenv("DEVICEIP", DEVICEIP)
DEVICEKEY = os.getenv("DEVICEKEY", DEVICEKEY)
DEVICEVERS = os.getenv("DEVICEVERS", DEVICEVERS)
print("TinyTuya - Smart Bulb RGB Test [%s]\n" % tinytuya.__version__)
print('TESTING: Device %s at %s with key %s version %s' %
(DEVICEID, DEVICEIP, DEVICEKEY, DEVICEVERS))
# Connect to the device - replace with real values
d=tinytuya.OutletDevice(DEVICEID, DEVICEIP, DEVICEKEY)
d.set_version(3.3)
# Generate the payload to send - add all the DPS values you want to change here
#if data != [0]
#payload=d.generate_payload(tinytuya.CONTROL, {'1': False, '2': 50})
#time.sleep(2)
#payload=d.generate_payload(tinytuya.CONTROL, {'1': True, '2': 50})
#time.sleep(2)
payload1=d.generate_payload(tinytuya.CONTROL, {'1': False, '2': 50})
payload2=d.generate_payload(tinytuya.CONTROL, {'1': True, '2': 50})
# Send the payload to the device
d._send_receive(payload1)
time.sleep(2)
d._send_receive(payload2)
# Get the status of the device
#response = requests.request("GET", url, headers=headers, data=payload)
#print(str(d._send_receive(payload)))
#Command for
# Show status of device
data = d.status()
print('\nCurrent Status of Bulb: %r' % data)
{
"timestamp": 1613548219.2819111,
"devices": [
{
"name": "Under Cabinets",
"ip": "192.168.1.158",
"ver": "3.3",
"id": "BLAAAAAAAAAAAAA",
"key": "BLAAAAAAAAAAA",
"dps": {
"dps": {
"20": false,
"21": "scene",
"24": "007d007903e8",
"25": "05464601000003e803e800000000464601007803e803e80000000046460100f003e803e800000000464601003d03e803e80000000046460100ae03e803e800000000464601011303e803e800000000",
"26": 0
}
}
},
{
"name": "Office Outside Lights",
"ip": "192.168.1.137",
"ver": "3.3",
"id": "BLAAAAAAAAAA",
"key": "BLAAAAAAAA",
"dps": {
"devId": "BLAAAAAAAAAA",
"dps": {
"1": true,
"9": 0
}
}
},
{
"name": "Garage",
"ip": "192.168.1.138",
"ver": "3.3",
"id": "BLAAAAAAAAAA",
"key": "BLAAAAAAAAAA",
"dps": {
"dps": {
"20": true,
"21": "colour",
"22": 1000,
"23": 767,
"24": "00ac02c501f0",
"25": "000e0d0000000000000000c803e8",
"26": 0
}
}
},
{
"name": "Office Light",
"ip": "192.168.1.139",
"ver": "3.3",
"id": "BLAAAAAAAAAA",
"key": "BLAAAAAAAAAA",
"dps": {
"dps": {
"20": true,
"21": "white",
"22": 1000,
"23": 236,
"24": "00d60000026c",
"25": "000e0d0000000000000000c803e8",
"26": 0
}
}
}
]
}
{
"result": {
"category": "dj",
"functions": [
{
"code": "switch_led",
"desc": "switch led",
"name": "switch led",
"type": "Boolean",
"values": "{}"
},
{
"code": "work_mode",
"desc": "work mode",
"name": "work mode",
"type": "Enum",
"values": "{\"range\":[\"white\",\"colour\",\"scene\",\"music\",\"scene_1\",\"scene_2\",\"scene_3\",\"scene_4\"]}"
},
{
"code": "bright_value_v2",
"desc": "bright value v2",
"name": "bright value v2",
"type": "Integer",
"values": "{\"min\":10,\"scale\":0,\"unit\":\"\",\"max\":1000,\"step\":1}"
},
{
"code": "temp_value_v2",
"desc": "temp value v2",
"name": "temp value v2",
"type": "Integer",
"values": "{\"min\":0,\"scale\":0,\"unit\":\"\",\"max\":1000,\"step\":1}"
},
{
"code": "colour_data_v2",
"desc": "colour data v2",
"name": "colour data v2",
"type": "Json",
"values": "{}"
},
{
"code": "scene_data_v2",
"desc": "scene data v2",
"name": "scene data v2",
"type": "Json",
"values": "{}"
},
{
"code": "music_data",
"desc": "music data",
"name": "music data",
"type": "Json",
"values": "{}"
},
{
"code": "control_data",
"desc": "control data",
"name": "control data",
"type": "Json",
"values": "{}"
},
{
"code": "countdown_1",
"desc": "countdown 1",
"name": "countdown 1",
"type": "Integer",
"values": "{\"unit\":\"\",\"min\":0,\"max\":86400,\"scale\":0,\"step\":1}"
},
{
"code": "bright_value",
"desc": "bright value",
"name": "bright value",
"type": "Integer",
"values": "{\"min\":25,\"scale\":0,\"unit\":\"\",\"max\":255,\"step\":1}"
},
{
"code": "temp_value",
"desc": "temp value",
"name": "temp value",
"type": "Integer",
"values": "{\"min\":0,\"scale\":0,\"unit\":\"\",\"max\":255,\"step\":1}"
},
{
"code": "flash_scene_1",
"desc": "flash scene 1",
"name": "flash scene 1",
"type": "Json",
"values": "{\"h\":{\"min\":1,\"scale\":0,\"unit\":\"\",\"max\":360,\"step\":1},\"s\":{\"min\":1,\"scale\":0,\"unit\":\"\",\"max\":255,\"step\":1},\"v\":{\"min\":1,\"scale\":0,\"unit\":\"\",\"max\":255,\"step\":1}}"
},
{
"code": "flash_scene_2",
"desc": "flash scene 2",
"name": "flash scene 2",
"type": "Json",
"values": "{\"h\":{\"min\":1,\"scale\":0,\"unit\":\"\",\"max\":360,\"step\":1},\"s\":{\"min\":1,\"scale\":0,\"unit\":\"\",\"max\":255,\"step\":1},\"v\":{\"min\":1,\"scale\":0,\"unit\":\"\",\"max\":255,\"step\":1}}"
},
{
"code": "flash_scene_3",
"desc": "flash scene 3",
"name": "flash scene 3",
"type": "Json",
"values": "{\"h\":{\"min\":1,\"scale\":0,\"unit\":\"\",\"max\":360,\"step\":1},\"s\":{\"min\":1,\"scale\":0,\"unit\":\"\",\"max\":255,\"step\":1},\"v\":{\"min\":1,\"scale\":0,\"unit\":\"\",\"max\":255,\"step\":1}}"
},
{
"code": "flash_scene_4",
"desc": "flash scene 4",
"name": "flash scene 4",
"type": "Json",
"values": "{\"h\":{\"min\":1,\"scale\":0,\"unit\":\"\",\"max\":360,\"step\":1},\"s\":{\"min\":1,\"scale\":0,\"unit\":\"\",\"max\":255,\"step\":1},\"v\":{\"min\":1,\"scale\":0,\"unit\":\"\",\"max\":255,\"step\":1}}"
},
{
"code": "scene_select",
"desc": "scene select",
"name": "scene select",
"type": "Enum",
"values": "{\"range\":[\"1\",\"2\",\"3\",\"4\",\"5\"]}"
},
{
"code": "read_time",
"desc": "read time",
"name": "read time",
"type": "Integer",
"values": "{\"unit\":\"minute\",\"min\":1,\"max\":60,\"scale\":0,\"step\":1}"
},
{
"code": "rest_time",
"desc": "rest time",
"name": "rest time",
"type": "Integer",
"values": "{\"unit\":\"minute\",\"min\":1,\"max\":60,\"scale\":0,\"step\":1}"
},
{
"code": "switch_health_read",
"desc": "switch health read",
"name": "switch health read",
"type": "Boolean",
"values": "{}"
},
{
"code": "colour_data",
"desc": "colour data",
"name": "colour data",
"type": "Json",
"values": "{}"
},
{
"code": "scene_data",
"desc": "scene data",
"name": "scene data",
"type": "Json",
"values": "{}"
},
{
"code": "rhythm_mode",
"desc": "rhythm mode",
"name": "rhythm mode",
"type": "Raw",
"values": "{\"maxlen\":255}"
},
{
"code": "wakeup_mode",
"desc": "wakeup mode",
"name": "wakeup mode",
"type": "Raw",
"values": "{\"maxlen\":255}"
},
{
"code": "power_memory",
"desc": "power memory",
"name": "power memory",
"type": "Raw",
"values": "{\"maxlen\":255}"
},
{
"code": "debug_data",
"desc": "debug data",
"name": "debug data",
"type": "String",
"values": "{\"maxlen\":255}"
},
{
"code": "sleep_mode",
"desc": "sleep mode",
"name": "sleep mode",
"type": "Raw",
"values": "{\"maxlen\":255}"
}
]
},
"success": true,
"t": 1613549900843
}