Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Able to read status. But cannot turn on smart plug #506

Open
krishgcek opened this issue Jun 10, 2024 · 15 comments
Open

Able to read status. But cannot turn on smart plug #506

krishgcek opened this issue Jun 10, 2024 · 15 comments
Labels
tuya_device Support for specific Tuya Devices

Comments

@krishgcek
Copy link

I have 16 a smart plug. I have used tuya cutter and gor local keys. I can read status.

d.set_socketPersistent(True)
d.turn_on()
d.set_value(True,1,False)
data=d.status()
print(data)
print (data)
But the dp 1 value is always false.

@krishgcek krishgcek changed the title Able read to read status. But cannot turn on smart plug Able to read status. But cannot turn on smart plug Jun 10, 2024
@jasonacox jasonacox added the tuya_device Support for specific Tuya Devices label Jun 11, 2024
@jasonacox
Copy link
Owner

Can you share the data you get back from d.status()? Sometimes the switch value is in a different position (DPS).

@krishgcek
Copy link
Author

Can you share the data you get back from d.status()? Sometimes the switch value is in a different position (DPS).

DEBUG:decrypted 3.x payload='{"dps":{"1":false,"9":0,"18":0,"19":0,"20":2214,"21":1,"22":591,"23":24585,"24":13476,"25":3090,"26":0,"38":"memory","39":false,"40":"relay","41":false,"42":"","43":"","44":""}}'
DEBUG:payload type = <class 'str'>
DEBUG:decoded results='{"dps":{"1":false,"9":0,"18":0,"19":0,"20":2214,"21":1,"22":591,"23":24585,"24":13476,"25":3090,"26":0,"38":"memory","39":false,"40":"relay","41":false,"42":"","43":"","44":""}}'
DEBUG:status() received data={'dps': {'1': False, '9': 0, '18': 0, '19': 0, '20': 2214, '21': 1, '22': 591, '23': 24585, '24': 13476, '25': 3090, '26': 0, '38': 'memory', '39': False, '40': 'relay', '41': False, '42': '', '43': '', '44': ''}}

@jasonacox
Copy link
Owner

Wow, that's a big list for a smart plug! Did you run the setup wizard? If so, you should have a devices.json file that will have the mapping of these DPS to function and type. Take a look at that and especially zoom in to 1, 39 and 41. Those seem like boolean values. You can try to set those.

d.set_value(True,1,False)

This is the wrong arguments for set_value() but you might have meant set_status(). You could try:

d.set_value(1, True)
d.set_value(39, True)
d.set_value(41, True)

@krishgcek
Copy link
Author

Wow, that's a big list for a smart plug! Did you run the setup wizard? If so, you should have a devices.json file that will have the mapping of these DPS to function and type. Take a look at that and especially zoom in to 1, 39 and 41. Those seem like boolean values. You can try to set those.

d.set_value(True,1,False)

This is the wrong arguments for set_value() but you might have meant set_status(). You could try:

d.set_value(1, True)
d.set_value(39, True)
d.set_value(41, True)

I got same status,
DEBUG:status() received data={'dps': {'1': False, '9': 0, '18': 0, '19': 0, '20': 2124, '21': 1, '22': 591, '23': 24585, '24': 13476, '25': 3090, '26': 0, '38': 'memory', '39': False, '40': 'relay', '41': False, '42': '', '43': '', '44': ''}}
{'dps': {'1': False, '9': 0, '18': 0, '19': 0, '20': 2124, '21': 1, '22': 591, '23': 24585, '24': 13476, '25': 3090, '26': 0, '38': 'memory', '39': False, '40': 'relay', '41': False, '42': '', '43': '', '44': ''}}
I can see that '1' becomes True if I manually press the switch on the plug. It is 16amp 1 ch plug with energy monitoring

@krishgcek
Copy link
Author

krishgcek commented Jun 11, 2024

Dp 20 value is volt. So reading is correct

@jasonacox
Copy link
Owner

Try this:

import tinytuya
import time

tinytuya.set_debug(True)

d = tinytuya.OutletDevice(DEVICEID, DEVICEIP, DEVICEKEY)
d.set_version(3.3)

# Show status of device
data = d.status()
print('\nCurrent Status of Plug: %r' % data)

# Power Control Test
print('\nPower Control Test')
print('    Turn off')
d.set_value(1, False)
# Show status of device
data = d.status()
print('\nCurrent Status of Plug: %r' % data)

time.sleep(2)
print('    Turn on')
d.set_value(1, True)
# Show status of device
data = d.status()
print('\nCurrent Status of Plug: %r' % data)

You can also try to pull latest dev version and try again.

pip install tinytuya==1.14.1.dev0

@krishgcek
Copy link
Author

Try this:

import tinytuya
import time

tinytuya.set_debug(True)

d = tinytuya.OutletDevice(DEVICEID, DEVICEIP, DEVICEKEY)
d.set_version(3.3)

# Show status of device
data = d.status()
print('\nCurrent Status of Plug: %r' % data)

# Power Control Test
print('\nPower Control Test')
print('    Turn off')
d.set_value(1, False)
# Show status of device
data = d.status()
print('\nCurrent Status of Plug: %r' % data)

time.sleep(2)
print('    Turn on')
d.set_value(1, True)
# Show status of device
data = d.status()
print('\nCurrent Status of Plug: %r' % data)

You can also try to pull latest dev version and try again.

pip install tinytuya==1.14.1.dev0

Same here,
Current Status of Plug: {'dps': {'1': False, '9': 0, '18': 0, '19': 0, '20': 2134, '21': 1, '22': 591, '23': 24585, '24': 13476, '25': 3090, '26': 0, '38': 'memory', '39': False, '40': 'relay', '41': False, '42': '', '43': '', '44': ''}}

@jasonacox
Copy link
Owner

Maybe this device doesn't allow local control. Have you tried pulling the plug to remove power for 10s or so and then try again? Every smart plug I have (all 60 of them) works with that simple script.

What do you get with:

python -m tinytuya scan

Would be good to confirm the device version. That could cause a problem if you are selecting the wrong one. I would also still recommend looking at the devices.json file to see if it reveals anything clever about the plug DPS.

@krishgcek
Copy link
Author

After I manually turned on,
Current Status of Plug: {'dps': {'1': True, '9': 0, '18': 0, '19': 0, '20': 2249, '21': 1, '22': 591, '23': 24585, '24': 13476, '25': 3090, '26': 0, '38': 'memory', '39': False, '40': 'relay', '41': False, '42': '', '43': '', '44': ''}}
Turn on

@jasonacox
Copy link
Owner

I understand that. Unfortunately, without any more information (e.g. scan results or devices.json) I'm not able to help further. You might try tuyapi or local_tuya to see if you have more success.

@krishgcek
Copy link
Author

I am not in home . I am using a remote connector to connect my home lan. So udp is not accessible. I will the scan after reaching home (mostly this weekend) and update you.

@jasonacox
Copy link
Owner

It would be helpful to see:

  • Your devices.json file or the section related to this device (feel free to redact the key)
  • The output (or a section related to the device) of python -m tinytuya scan -debug

@krishgcek
Copy link
Author

Here is what I got.

Unknown v3.3 Device Product ID = keyjup78v54myhan [Valid Broadcast]:
Address = 192.168.0.112 Device ID = lmKxZ1Vi8mO4kpll9VUz (len:20) Local Key = Version = 3.3 Type = default, MAC =
No Stats for 192.168.0.112: DEVICE KEY required to poll for status
DEBUG:Received valid UDP packet: {'ip': '192.168.0.112', 'gwId': 'lmKxZ1Vi8mO4kpll9VUz', 'active': 2, 'ablilty': 0, 'encrypt': True, 'productKey': 'keyjup78v54myhan', 'version': '3.3'}

@krishgcek
Copy link
Author

ice.active&et=1&t=109&uuid=2M81Krr1iyiI&v=4.4&sign=e6a86de76fe68eb518c1e39abbbbd783', version='HTTP/1.1', remote_ip='10.42.42.40')
[06:40:46.831987 LOG (Client)] ==== Request body ===
{"token":"9kwbwC1h","softVer":"1.1.8","productKey":"keyjup78v54myhan","protocolVer":"2.2","baselineVer":"40.00","productKeyStr":"keyjup78v54myhan","devId":"tIZccYzRuLW1tr57hsZC","hid":"b8060d192605","modules":"[{"otaChannel":9,"softVer":"1.1.8","online":true}]","devAttribute":579,"cadVer":"1.0.3","cdVer":"1.0.0","options":"{"isFK":true,"otaChannel":0}","t":109}
[06:40:46.832036 LOG (Client)] ==== End request body ===
[06:40:46.832897 LOG (Server)] Response: {'result': {'schema': '[{"type":"obj","mode":"rw","property":{"type":"bool"},"id":1},{"type":"obj","mode":"rw","property":{"min":0,"max":86400,"scale":0,"step":1,"type":"value"},"id":9},{"mode":"ro","property":{"min":0,"max":50000,"scale":3,"step":100,"type":"value"},"id":17,"type":"obj"},{"mode":"ro","property":{"min":0,"max":30000,"scale":0,"step":1,"type":"value"},"id":18,"type":"obj"},{"mode":"ro","property":{"min":0,"max":80000,"scale":1,"step":1,"type":"value"},"id":19,"type":"obj"},{"mode":"ro","property":{"min":0,"max":5000,"scale":1,"step":1,"type":"value"},"id":20,"type":"obj"},{"mode":"ro","property":{"min":0,"max":5,"scale":0,"step":1,"type":"value"},"id":21,"type":"obj"},{"mode":"ro","property":{"min":0,"max":1000000,"scale":0,"step":1,"type":"value"},"id":22,"type":"obj"},{"mode":"ro","property":{"min":0,"max":1000000,"scale":0,"step":1,"type":"value"},"id":23,"type":"obj"},{"mode":"ro","property":{"min":0,"max":1000000,"scale":0,"step":1,"type":"value"},"id":24,"type":"obj"},{"mode":"ro","property":{"min":0,"max":1000000,"scale":0,"step":1,"type":"value"},"id":25,"type":"obj"},{"mode":"ro","property":{"type":"bitmap","maxlen":6},"id":26,"type":"obj"},{"type":"obj","mode":"rw","property":{"range":["off","on","memory"],"type":"enum"},"id":38},{"mode":"rw","property":{"type":"bool"},"id":39,"type":"obj"},{"type":"obj","mode":"rw","property":{"range":["relay","pos","none","on"],"type":"enum"},"id":40},{"type":"obj","mode":"rw","property":{"type":"bool"},"id":41},{"type":"obj","mode":"rw","property":{"type":"string","maxlen":255},"id":42},{"type":"obj","mode":"rw","property":{"type":"string","maxlen":255},"id":43},{"mode":"rw","property":{"type":"string","maxlen":255},"id":44,"type":"obj"}]', 'devId': 'lmKxZ1Vi8mO4kpll9VUz', 'resetFactory': False, 'timeZone': '+02:00', 'capability': 1025, 'secKey': 'xxxx', 'stdTimeZone': '+01:00', 'schemaId': '000004rr2q', 'dstIntervals': [], 'localKey': 'xxxxxx'}, 'success': True, 't': 1718260846}

i got above from tuya cutter. key masked

@krishgcek
Copy link
Author

I was able to solve it by using i was able to solve it by using antela-spl-w-ty-pm-fr-ry-plug-with-energy-monitoring-cb2s-v1.1.8 profile in tuya cloud cutter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tuya_device Support for specific Tuya Devices
Projects
None yet
Development

No branches or pull requests

2 participants