powermonitor icon indicating copy to clipboard operation
powermonitor copied to clipboard

unexpected status()

Open ebdavison opened this issue 5 years ago • 14 comments

I have a plug which is joined to my tuya app on my iPhone and the device is being seen in Home Assistant. I wish to monitor power as well.

I grabbed the device ID and IP address and tried to run this script but am getting an error:

Polling Device ebf8372483a88daab4ckmy at 10.211.2.137 with key 0123456789abcde1 and protocol version 3.1
Unexpected status() payload=b'\xf1b\xe6\x13^\xcdc\xc3\x8f\xf4\xab\xfa\tB\xc7\xbb\xefxU\xd9g.,\xd2\xc6\xd8\xfc\xb3@A\x17%'
Dictionary b'\xf1b\xe6\x13^\xcdc\xc3\x8f\xf4\xab\xfa\tB\xc7\xbb\xefxU\xd9g.,\xd2\xc6\xd8\xfc\xb3@A\x17%'
Unexpected status() payload=b'\xf1b\xe6\x13^\xcdc\xc3\x8f\xf4\xab\xfa\tB\xc7\xbb\xefxU\xd9g.,\xd2\xc6\xd8\xfc\xb3@A\x17%'
Dictionary b'\xf1b\xe6\x13^\xcdc\xc3\x8f\xf4\xab\xfa\tB\xc7\xbb\xefxU\xd9g.,\xd2\xc6\xd8\xfc\xb3@A\x17%'

Please advise.

ebdavison avatar May 19 '20 23:05 ebdavison

The payload looks encrypted. I suggest doing a scan to see if this is actually a version 3.3 plug:

python3 -m pip install tuyapower
python3 -m tuyapower

You will get something like this - notice the different versions:

TuyaPower (Tuya compatible smart plug scanner) [0.0.20]

Scanning on UDP ports 6666 and 6667 for devices...

FOUND Device [Valid payload]: 10.0.1.x
    ID = 01234567891234567890, productKey = iXfg9AQVUPhlfyGw, Version = 3.1
    Stats: on=True, W=56.2, mA=478.0, V=120.3 [OK]
FOUND Device [Valid payload]: 10.0.1.y
    ID = 01234567891234567891, productKey = MShdslm9Uw7Q59nN, Version = 3.3
    Device Key required to poll for stats

If it is 3.3, you just need to specify that when you call plugpower.py:

 python plugpower.py 01234567890 10.0.1.99 0123456789abcdef 3.3

jasonacox avatar Jul 22 '20 04:07 jasonacox

Same here.

python3 -m tuyapower TuyaPower (Tuya compatible smart plug scanner) [0.0.20]

Scanning on UDP ports 6666 and 6667 for devices (15 retries)...

FOUND Device [Valid payload]: 192.X.X.X ID = XXXXXX, productKey = XXXXXX, Version = 3.3 Device Key required to poll for stats

and when running: python plugpower.py <ID> <IP> <KEY> 3.3

get an error: Traceback (most recent call last): File "plugpower.py", line 94, in devicepower = deviceInfo(PLUGID,PLUGIP,PLUGKEY,PLUGVERS) File "plugpower.py", line 45, in deviceInfo data = d.status() File "/home/myakove/git/powermonitor/pytuya/init.py", line 311, in status result = json.loads(result) File "/usr/lib64/python3.8/json/init.py", line 357, in loads return _default_decoder.decode(s) File "/usr/lib64/python3.8/json/decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/lib64/python3.8/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)

myakove avatar Aug 12 '20 13:08 myakove

Hi @myakove I may be missing it, but were you specifying the ID, IP and key for plugpower.py?

It will look something like this:

 python3 plugpower.py PLUGID PLUGIP PLUGKEY PLUGVERS

Or you can set those variables in the environment:

#!/bin/bash
export PLUGID=XXXXXX
export PLUGIP=192.X.X.X
export PLUGKEY=XXXXXX
export PLUGVERS=3.3

python3 plugpower.py

jasonacox avatar Aug 13 '20 03:08 jasonacox

Hi,

This is what I sent: python plugpower.py bf4731ed09220ae2aamlof 192.168.X.X KEY 3.3

myakove avatar Aug 13 '20 03:08 myakove

I'm curious if the tuyapower update might work better. Try pulling the tuyapower script instead:

wget https://raw.githubusercontent.com/jasonacox/tuyapower/master/plugpower.py
python3 plugpower.py bf4731ed09220ae2aamlof 192.168.X.X KEY 3.3

jasonacox avatar Aug 13 '20 03:08 jasonacox

Switch On: False Power (W): -99.000000 Current (mA): -99.000000 Voltage (V): -99.000000 Projected usage (kWh): Day: -2.376000 Week: -16.632000 Month: -72.072000

{ "datetime": "2020-08-13T03:56:25Z", "switch": "False", "power": "-99", "current": "-99", "voltage": "-99" }

myakove avatar Aug 13 '20 03:08 myakove

Even when the plug is powered on there is no data. So no error, but nothing is pulled.

myakove avatar Aug 13 '20 04:08 myakove

That's helpful! The tuyapower module has more error handling.

This response means it is unable to decrypt the response payload with that key (the -99 indicates invalid response or unsupported feature of the device -- some plugs do not send power data for instance). This can happen if you have the wrong key but I suspect there may be another 3.3 anomaly here. It could be due to the manufactures implementation or a firmware change. I'll do some research and see what I can find.

Can you provide the plug manufacture and model? Also do you have other plugs that work?

jasonacox avatar Aug 13 '20 04:08 jasonacox

When debugging with pdb I see that err is "'Timeout polling device'"

myakove avatar Aug 13 '20 04:08 myakove

Also in the output "ERROR: Timeout polling device" << Missed this one :)

myakove avatar Aug 13 '20 04:08 myakove

I have only one device. No model on the device and not on the package. Where can I find some useful info about my device model?

myakove avatar Aug 13 '20 04:08 myakove

This is what I have:

US $10.41 57%OFF | Smart WiFi Plug Adaptor 16A Remote Voice Control Power Monitor Socket Outlet Timing Function work with Alexa Google Home Tuya https://a.aliexpress.com/_d6R8jD8

myakove avatar Aug 13 '20 04:08 myakove

Hi @myakove - I'm not able to replicate this with a similar 3.3 device I have. The only way I can get something close is to use a bad PLUGKEY. How did you get the PLUGKEY for your device? I just updated the tuyapower README with steps to do this using the Tuya developer portal - see instructions: https://github.com/jasonacox/tuyapower#get-the-tuya-device-key . I recommend you give that a try if you haven't already.

jasonacox avatar Aug 15 '20 06:08 jasonacox

I tried this one already, no luck.

myakove avatar Aug 16 '20 06:08 myakove