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

Can't get .status() from switch #3

Closed
k-0 opened this issue Nov 6, 2020 · 6 comments
Closed

Can't get .status() from switch #3

k-0 opened this issue Nov 6, 2020 · 6 comments

Comments

@k-0
Copy link

k-0 commented Nov 6, 2020

Hi,

i can get the status from my 10 lamps, but when I try to get a status from a switch, i get the following error. This is my code:

a = tinytuya.OutletDevice('here_is_my_key', '192.168.178.46', 'secret_key_here')
a.set_version(3.3)
data =  a.status()
print(data)

And this error occurs:

Traceback (most recent call last):
  File "tuya.py", line 89, in <module>
    data =  a.status()
  File "/home/pi/tinytuya/tinytuya/__init__.py", line 405, in status
    result = json.loads(result)
  File "/usr/lib/python3.7/json/__init__.py", line 348, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.7/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.7/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
@k-0 k-0 changed the title Can't get .statuts from switch Can't get .status() from switch Nov 6, 2020
@jasonacox
Copy link
Owner

It is having trouble with the JSON payload coming back from the switch. It could be an encryption problem or just a bad JSON format. Try updating to TinyTuya v1.0.4:

python3 -m pip install --upgrade tinytuya

and then run the network scan function to see if the switch shows up:

python3 -m tinytuya

@k-0
Copy link
Author

k-0 commented Nov 9, 2020

I updated from v1.0.3 to v.1.0.4, but still the same problem.

python3 -m tinytuya
shows the device correctly (with both versions).

FOUND Device [Valid payload]: 192.168.178.46
    ID = bfa0cee9a00567f022jtll, product = bslwhdjerjhsold4, Version = 3.3
    No Stats - Device Key required to poll for status

It's my only device which has 22 chars as ID. Maybe that's the problem?

@jasonacox
Copy link
Owner

There seems to be some strange behavior with some devices that have a 22 character IDs. Try adding device22 to the initialization for dev_type:

a = tinytuya.OutletDevice('here_is_my_key', '192.168.178.46', 'secret_key_here', 'device22')
a.set_version(3.3)
data =  a.status()
print(data)

@k-0
Copy link
Author

k-0 commented Nov 15, 2020

I tried adding device22 and now I get the following error:

root@raspberrypi:/home/pi/tinytuya/tinytuya# cd ../ && python3 tuya.py
Traceback (most recent call last):
  File "tuya.py", line 89, in <module>
    data =  a.status()
  File "/home/pi/tinytuya/tinytuya/__init__.py", line 371, in status
    payload = self.generate_payload(DP_QUERY)
  File "/home/pi/tinytuya/tinytuya/__init__.py", line 324, in generate_payload
    json_data['dps'] = self.dpsUsed
AttributeError: 'OutletDevice' object has no attribute 'dpsUsed'

@jasonacox
Copy link
Owner

Oops! Try sending a DPS requested value:

a = tinytuya.OutletDevice('here_is_my_key', '192.168.178.46', 'secret_key_here', 'device22')
a.set_version(3.3)
a.set_dpsUsed({"1": None})
data =  a.status()
print(data)

Some of the device22 types have different lists of available dps values. I need to add a feature to scan these for us. If the above works, your device is the most common. If not, it will require a bit more work to figure it out.

@k-0
Copy link
Author

k-0 commented Nov 16, 2020

Now it works!
Thank you!

@k-0 k-0 closed this as completed Nov 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants