Tuya WiFi Smart Plug: Difference between revisions

From Leo's Notes
This page was last edited on 5 December 2018, at 05:43.
No edit summary
No edit summary
Line 10: Line 10:
* mq.gw.tuyaus.com via MQTT
* mq.gw.tuyaus.com via MQTT
* a1.tuyaus.com via HTTP
* a1.tuyaus.com via HTTP
You will probably still need to allow it to connect to the cloud once. If you don't let it completely connect, some features like voltage/wattage are disabled from the output (?).


The localKey seems to change every time the device is reconnected to the cloud.
The localKey seems to change every time the device is reconnected to the cloud.
Line 18: Line 16:
The status output from the AWP04L smart plug looks like this. The plug has monitoring features and should return the voltage and amperage (hence the calculated wattage).
The status output from the AWP04L smart plug looks like this. The plug has monitoring features and should return the voltage and amperage (hence the calculated wattage).


{{highlight|lang=text|code=
{{highlight|lang=text|code=<nowiki>
{u'devId': u'02200194dc4f22137d7f', u'dps': {
{u'devId': u'02200194dc4f22137d7f', u'dps': {
u'1': True,        outlet status
u'1': True,        outlet status
Line 25: Line 23:
u'4': 73,          amps (0.073 amps)
u'4': 73,          amps (0.073 amps)
u'6': 1198        volts
u'6': 1198        volts
}}</nowiki>
}}
}}


<s>You will probably still need to allow it to connect to the cloud once. If you don't let it completely connect, some features like voltage/wattage are disabled from the output (?).</s> MQTT must be working, or else these features are disabled:


{{highlight|lang=text|code=<nowiki>
{u'devId': u'02200194dc4f22135606', u'dps': {u'1': True, u'2': 0}}
>>> x.status()
{u'devId': u'02200194dc4f22135606', u'dps': {u'1': True, u'2': 0}}
>>> x.status()
{u'devId': u'02200194dc4f22135606', u'dps': {u'1': True, u'2': 0}}
>>> x.status()
{u'devId': u'02200194dc4f22135606', u'dps': {u'1': True, u'2': 0, u'5': 0, u'4': 0, u'6': 1184}}
>>> x.status()
{u'devId': u'02200194dc4f22135606', u'dps': {u'1': True, u'2': 0, u'5': 0, u'4': 0, u'6': 1184}}
>>> x.status()
{u'devId': u'02200194dc4f22135606', u'dps': {u'1': True, u'2': 0, u'5': 0, u'4': 0, u'6': 1184}}</nowiki>
}}
}}


== See Also ==
== See Also ==
* https://github.com/clach04/python-tuya
* https://github.com/clach04/python-tuya
* https://github.com/clach04/python-tuya/wiki
* https://github.com/clach04/python-tuya/wiki

Revision as of 05:43, 5 December 2018

To talk to the device, you need 3 things:

  1. The device IP address
  2. UUID / Device ID
  3. localKey

You can get this by sniffing the traffic the Android app makes with a SSL Capture app. When adding a new plug, some of the requests should contain something about a 'localKey'. One of the requests should also return all devices as well as their corresponding localKey from their server.

Self Hosted

It looks like the plug currently talks with

  • mq.gw.tuyaus.com via MQTT
  • a1.tuyaus.com via HTTP

The localKey seems to change every time the device is reconnected to the cloud.

tuya python

The status output from the AWP04L smart plug looks like this. The plug has monitoring features and should return the voltage and amperage (hence the calculated wattage).

{u'devId': u'02200194dc4f22137d7f', u'dps': {
u'1': True,        outlet status
u'2': 0,           ??
u'5': 56,          watts (5.6)
u'4': 73,          amps (0.073 amps)
u'6': 1198         volts
}}

You will probably still need to allow it to connect to the cloud once. If you don't let it completely connect, some features like voltage/wattage are disabled from the output (?). MQTT must be working, or else these features are disabled:


{u'devId': u'02200194dc4f22135606', u'dps': {u'1': True, u'2': 0}}
&gt;&gt;&gt; x.status()
{u'devId': u'02200194dc4f22135606', u'dps': {u'1': True, u'2': 0}}
&gt;&gt;&gt; x.status()
{u'devId': u'02200194dc4f22135606', u'dps': {u'1': True, u'2': 0}}
&gt;&gt;&gt; x.status()
{u'devId': u'02200194dc4f22135606', u'dps': {u'1': True, u'2': 0, u'5': 0, u'4': 0, u'6': 1184}}
&gt;&gt;&gt; x.status()
{u'devId': u'02200194dc4f22135606', u'dps': {u'1': True, u'2': 0, u'5': 0, u'4': 0, u'6': 1184}}
&gt;&gt;&gt; x.status()
{u'devId': u'02200194dc4f22135606', u'dps': {u'1': True, u'2': 0, u'5': 0, u'4': 0, u'6': 1184}}


See Also