In order to set this up you need the LocalKey. I followed the instruction to find it with WireShark but got no results (sorry for the vague description). Has anybody set up a Tuya plug and if so, how did you go about doing it? Can Tuya device be used with HA?
There is an Android app that gets teh local_key from Tuya devices after connecting them to an app call eFamily Cloud. See https://github.com/bobalob/TuyaKeyGrab for details.
Thanks! Got the localkey and set up my platform but still no luck. None of my tuya device show up. Does the localkey change if you remove and re-add the device? I used my wifes android phone to configure with eFamily and get the localkey then I removed them and re-discovered them on my iPhone Tuya app. I suspect that the localkey may have changed.
Your local key looks a bit off. There should be no letter larger than ‘f’ because this is a hexadecimal number. Also, I think you need to enclose your data in single quotes. For example…
I’m pretty sure keyError refers to “id”. Important: id is not the “id of the switch” (three switches: 1,2,3), but rather the number of switches per device. Ergo if you have three devices that are all a device with a single plug, they all get “id: 1”. That should resolve the keyErrors for all I know. Note: There are other threads around that pretty accurately describe the process of getting the key.
Yes, the local key changes every time the device is set up again.
Also, apparently the switches I have can only connect to one TCP client at a time and will refuse all other connection requests. That means that when intending to control them with HA, you cannot control them with the app anymore (I uninstalled the app, now it works almost flawlessly).
now, via GUI trying to turn on a switch, I got the following error:
File “/home/homeassistant/.homeassistant/custom_components/switch/tuya.py”, line 83, in update
raise ConnectionError(“Failed to update status.”)
ConnectionError: Failed to update status.
I’ve been able to get HA to update when the light turns on or off both with and without the Tuya app controlling the switch but I cannot get HA to actually control the switch. I get an error in the Tuya.py
Here’s the error:
File “/home/homeassistant/.homeassistant/custom_components/switch/tuya.py”, line 77, in update
status = self._device.status()
File “/srv/homeassistant/lib/python3.5/site-packages/pytuya/init.py”, line 256, in status
data = self._send_receive(payload)
File “/srv/homeassistant/lib/python3.5/site-packages/pytuya/init.py”, line 165, in _send_receive
s.send(payload)
ConnectionResetError: [Errno 104] Connection reset by peer
@sebringsc I just recently got Tuya switches working in HA. If you have the Device ID (“devid” in Tuya protocol) and Key (“localkey” in Tuya protocol) then I’d suggest testing control with the pytuya python module (which is underlying this HA Device Add-On).
From memory, pip install pytuya then open a python shell and paste in this code. If successful your outlet should toggle on/off …
@fryguy04
Thanks for the pointers. I was unable to install pytuya via the pip3 command (I get a permissions error). I already have a pytuya.py file in my switch folder in homeassitant but I copy/pasted and created it myself. Coincidentally I seem to be stuck with Python 2.7. I have tried to update it but I get the same permissions error. I also have the most recent release of HA but my Python is still 2.7
As for the import pytuya, i am unable to figure out how to do that. When I SSH to my raspberry pi, I cannot run import pytuya as it gives me an error. I don’t know enough about python to know what I am doing wrong. I also do not know how to open a python shell via SSH. Any pointers on what to do?