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?
I just got it working.
My first wall socket plug from WAZA@
But it does not update status when changed locally
Steps:
1) Install efamilycloud version 1.0.7 (found on google search - not the play store one)
2) Setup adding the socket
3) Install the TuyaKey Grab from https://github.com/bobalob/TuyaKeyGrab
4) Get the key and id.
5) Config Hass as bellow:
platform: tuya
host: 192.168.1.172
local_key: xxxxxxxxxxxxxxxxx
device_id: xxxxxxxxxxxxxxxxxxx
switches:
switch1:
friendly_name: Tuya01
id: 1
Today It stopped working…
And I got a message from Google Play Store telling the EFamilyCloud was updated to the last version…
I can not say that was the cause, but now I installed again the 1.0.7, got another key and it is working again. Blocked Play Store updates for that app and lets see what happen!!!
I followed your instruction and instruction on sean6541’s github page
it didn’t work. the trace back is as follows
2018-07-09 00:00:00 ERROR (MainThread) [homeassistant.core] Error executing service <ServiceCall switch.turn_on: entity_id=['switch.hlight']>
Traceback (most recent call last):
File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/core.py", line 1021, in _event_to_service_call
await service_handler.func(service_call)
File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/switch/__init__.py", line 109, in async_handle_switch_service
await switch.async_turn_on()
File "/usr/lib/python3.5/asyncio/futures.py", line 380, in __iter__
yield self # This tells Task to wait for completion.
File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup
future.result()
File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
raise self._exception
File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
result = self.fn(*self.args, **self.kwargs)
File "/home/homeassistant/.homeassistant/custom_components/switch/tuya.py", line 132, in turn_on
self._device.set_status(True, self._switchid)
File "/home/homeassistant/.homeassistant/custom_components/switch/tuya.py", line 96, in set_status
return self._device.set_status(state, switchid)
File "/srv/homeassistant/lib/python3.5/site-packages/pytuya/__init__.py", line 294, in set_status
data = self._send_receive(payload)
File "/srv/homeassistant/lib/python3.5/site-packages/pytuya/__init__.py", line 167, in _send_receive
data = s.recv(1024)
socket.timeout: timed out