Tuya LOCAL with energy monitoring and without tuya-convert

How to make the easy control?If i need to use cloud at the same time.

I got the energy monitoring working but once or twice a day the plug disconnects. And the only way to connect again is to unplug it. I got this error in my log:`

``
Logger: custom_components.localtuya.common
Source: custom_components/localtuya/pytuya/init.py:240
Integration: LocalTuya integration (documentation, issues)
First occurred: 22 april 2021 18:11:36 (94 occurrences)
Last logged: 11:29:38

[034…1d9] Connect to 192.168.0.217 failed
Traceback (most recent call last):
File “/config/custom_components/localtuya/common.py”, line 149, in _make_connection
status = await self._interface.status()
File “/config/custom_components/localtuya/pytuya/init.py”, line 472, in status
status = await self.exchange(STATUS)
File “/config/custom_components/localtuya/pytuya/init.py”, line 451, in exchange
msg = await self.dispatcher.wait_for(seqno)
File “/config/custom_components/localtuya/pytuya/init.py”, line 240, in wait_for
await asyncio.wait_for(self.listeners[seqno].acquire(), timeout=timeout)
File “/usr/local/lib/python3.8/asyncio/tasks.py”, line 501, in wait_for
raise exceptions.TimeoutError()
asyncio.exceptions.TimeoutError
``

P.S.: The recommended website states that their approach no longer works :frowning:

That seems to be correct for

  • Listing Tuya devices from the Tuya Smart or Smart Life apps

But there is still another approch left:

  • Linking a Tuya device with Smart Link

That’s the way I took a couple of month ago. It’s not as easy as the 1st approach but it did work well.

This worked for me about a week ago:

1 Like

I have an old version of Tuya smart life installed on an android emulator on my PC, I can just use root explorer to grab the local keys that way.

Hello Hugo,

Did you succeed with this? i having the same problem and kind of new to HA.

How do i create a sensor to report the volt, watts, e.t.c.

just set it up via the config flow and enter the DPS settings for your plug. You will then have a switch entity with the information. You can then you sensor template to split them off into seperate sensors.

Quick question: are the local key etc. unique to the device or is it changed everytime you unregsiter and re-register the device? Because when I change from Smart Home to Tuya App, I have to reregister the devices. I don’t want to lose the information.

Would love to see device type vacuum integrated, have it working some what through local tuya.
Just not able to set options for fan speed, voice selection etc/

Hello,
I tried to copy from post 9 and change IP, local_key and device_id, but VSCode shows me “end of stream or a document separator is expected”.
I am really new to all of this, so could someone point me in the right direction? :slight_smile:
Thank you
Alex

What is changing every time you remove/re-add a device from/to Smart Life/Tuya is the local key.

Okay, thank you. Then I will try to not change the app too often :slight_smile:
One question to the implementation.
I installed LocalTuya and set up the switch as switch.plasma_main_gosund_sp112 (I selected the first ID in the dropdown as I think that is the main socket).

I then added this to my configuration.yaml but I don’t see any sensors being created. I think I am doing something wrong (nooby that I am…).

Attempt according to github:

       sensor:
         - platform: template
           sensors:
             tuya-plasma_main_gosund_sp112_voltage:
               value_template: >-
                 {{ states.switch.plasma_main_gosund_sp112.attributes.voltage }}
               unit_of_measurement: 'V'
             tuya-plasma_main_gosund_sp112_current:
               value_template: >-
                 {{ states.switch.plasma_main_gosund_sp112.attributes.current }}
               unit_of_measurement: 'mA'
             tuya-plasma_main_gosund_sp112_current_consumption:
               value_template: >-
                 {{ states.switch.plasma_main_gosund_sp112.attributes.current_consumption }}
               unit_of_measurement: 'W'

Attempt according to HA forum

- platform: template
  sensors:
    tuya_plasma_main_gosund_sp112_voltage:
      friendly_name: "plasma_main_gosund_sp112 voltage"
      unit_of_measurement: 'V'
      value_template: "{{ states.switch.tuya_plasma_main_gosund_sp112.attributes.voltage }}"
      
    tuya_plasma_main_gosund_sp112_current:
      friendly_name: "plasma_main_gosund_sp112 current"
      unit_of_measurement: 'mA'
      value_template: "{{ states.switch.tuya_plasma_main_gosund_sp112.attributes.current }}"
      
    tuya_plasma_main_gosund_sp112_current_consumption:
      friendly_name: "plasma_main_gosund_sp112 current consumption"
      unit_of_measurement: 'W'
      value_template: "{{ states.switch.tuya_plasma_main_gosund_sp112.attributes.current_consumption }}"

What do you read at the Developer Options-Page regarding the entities for the Gosund SP112?

Do they show up as

switch.plasma_main_gosund_sp112.attributes.voltage
etc.?

With exactly this in my configuration.yaml

sensor:
  - platform: template
    sensors:
      tuya-plasma_main_gosund_sp112_voltage:
        value_template: >-
          {{ states.switch.plasma_main_gosund_sp112.attributes.voltage }}
        unit_of_measurement: 'V'
      tuya-plasma_main_gosund_sp112_current:
        value_template: >-
          {{ states.switch.plasma_main_gosund_sp112.attributes.current }}
        unit_of_measurement: 'mA'
      tuya-plasma_main_gosund_sp112_current_consumption:
        value_template: >-
          {{ states.switch.plasma_main_gosund_sp112.attributes.current_consumption }}
        unit_of_measurement: 'W'

I get only

switch.plasma_main_gosund_sp112

So no individual sensors.

Using Gosund Plugs too but reflashed with Tasmota here. So I am not sure but you can try this:

sensor:
  - platform: template
    sensors:
      tuya-plasma_main_gosund_sp112_voltage:
        value_template: >-
          {{ states.switch.plasma_main_gosund_sp112.attributes["voltage"] | replace(" V", "") | float }}
        unit_of_measurement: 'V'
      tuya-plasma_main_gosund_sp112_current:
        value_template: >-
          {{ states.switch.plasma_main_gosund_sp112.attributes["current"] | replace(" mA", "") | float }}
        unit_of_measurement: 'mA'
      tuya-plasma_main_gosund_sp112_current_consumption:
        value_template: >-
          {{ states.switch.plasma_main_gosund_sp112.attributes["current_consumption"] | replace(" W", "") | float }}
        unit_of_measurement: 'W'

I have some devices with LocalTuya but I can not add others. I just get “An unknown error occurred. See log for details.” I have correct keys and everything.

Logger: custom_components.localtuya.config_flow
Source: custom_components/localtuya/pytuya/__init__.py:637
Integration: LocalTuya (documentation, issues)
First occurred: 11:29:28 AM (1 occurrences)
Last logged: 11:29:28 AM

Unexpected exception
Traceback (most recent call last):
  File "/config/custom_components/localtuya/config_flow.py", line 279, in async_step_basic_info
    self.dps_strings = await validate_input(self.hass, user_input)
  File "/config/custom_components/localtuya/config_flow.py", line 185, in validate_input
    interface = await pytuya.connect(
  File "/config/custom_components/localtuya/pytuya/__init__.py", line 637, in connect
    _, protocol = await loop.create_connection(
  File "/usr/local/lib/python3.8/asyncio/base_events.py", line 1025, in create_connection
    raise exceptions[0]
  File "/usr/local/lib/python3.8/asyncio/base_events.py", line 1010, in create_connection
    sock = await self._connect_sock(
  File "/usr/local/lib/python3.8/asyncio/base_events.py", line 924, in _connect_sock
    await self.sock_connect(sock, address)
  File "/usr/local/lib/python3.8/asyncio/selector_events.py", line 496, in sock_connect
    return await fut
  File "/usr/local/lib/python3.8/asyncio/selector_events.py", line 528, in _sock_connect_cb
    raise OSError(err, f'Connect call failed {address}')
OSError: [Errno 113] Connect call failed ('192.168.1.84', 6668)

Hi everyone,

I have the following problem since yesterday.
I do not get any data delivered from the socket.

Do you have an idea why?
Thanks.

Sometimes a restart of HA followed by a re-add of the device helps. Give it a try.