Tuya LOCAL with energy monitoring and without tuya-convert

I’ve installed 3.1.0 release and it is working very well (I was at 3.0.1).
Thank you @rospogrigio and @postlund
You guys are awesome!

1 Like

You are mixing old and new configuration syntax. Have a look at README.md in the git repo for an example (or set up via config flow).

1 Like

I figured it out with the following, indeed following the github examples. Just too many posts on this while the best I could do was following the Github examples. I just missed the information where to put it all. I also struggled with the fact that it wouldn’t show up anymore in the normal integration section, after adding it on HACS. Seemed that it works just fine if you put it in the YAML, you just can’t use the Flow option anymore. After you add it in the configuration YAML it shows up in the normal integration, but you will lose the option to add stuff by UI. Not sure how to fix this. This:

Has some good comments on it. But I never got to the point of trying to fix it any longer, since I already got it running.

#Add to configuration.yaml

#Localtuya

localtuya:  

- host: 192.168.178.xxx

  device_id: xxx

  local_key: xxx

  friendly_name: wifi plug

  protocol_version: "3.3"

  entities:

      - platform: switch

        friendly_name: wifi plug

        id: 1

        current: 18 # Optional

        current_consumption: 19 # Optional

        voltage: 20 # Optional

      - platform: sensor

        friendly_name: Plug Voltage

        id: 20

        scaling: 0.1 # Optional

        device_class: voltage # Optional

        unit_of_measurement: "V" # Optional

        

      - platform: sensor

        friendly_name: Plug Current

        id: 18

        scaling: 1 # Optional

        unit_of_measurement: "mA" # Optional

        

      - platform: sensor

        friendly_name: Plug Current Consumption

        id: 19

        scaling: 0.1 # Optional

        unit_of_measurement: "W" # Optional

Hi
yesterday I tried to add the localtuya from HACS. Until yesterday everything was working fine.
after the update I restarted HA and my 5 covers were unavailable (grey out) on the contrary my 2 dimmers were available.

s1

if i manually move the slider (picture below) they start to work and are available afterwards.

s2

Today after a restart they are unavailable again, and I get the following in the logs

Logger: homeassistant.util.logging
Source: util/logging.py:108
First occurred: 12:51:26 PM (5 occurrences)
Last logged: 12:51:27 PM

Exception in _update_handler when dispatching 'localtuya_50758014840d8e91eaa2': ({'1': '1'},) Traceback (most recent call last): File "/config/custom_components/localtuya/common.py", line 245, in _update_handler self.status_updated() File "/config/custom_components/localtuya/cover.py", line 185, in status_updated time_diff = time.time() - self._timer_start TypeError: unsupported operand type(s) for -: 'float' and 'NoneType'
Exception in _update_handler when dispatching 'localtuya_50758014840d8e918614': ({'1': '3'},) Traceback (most recent call last): File "/config/custom_components/localtuya/common.py", line 245, in _update_handler self.status_updated() File "/config/custom_components/localtuya/cover.py", line 185, in status_updated time_diff = time.time() - self._timer_start TypeError: unsupported operand type(s) for -: 'float' and 'NoneType'
Exception in _update_handler when dispatching 'localtuya_50758014840d8e918632': ({'1': '1'},) Traceback (most recent call last): File "/config/custom_components/localtuya/common.py", line 245, in _update_handler self.status_updated() File "/config/custom_components/localtuya/cover.py", line 185, in status_updated time_diff = time.time() - self._timer_start TypeError: unsupported operand type(s) for -: 'float' and 'NoneType'
Exception in _update_handler when dispatching 'localtuya_50758014840d8e91f036': ({'1': '1'},) Traceback (most recent call last): File "/config/custom_components/localtuya/common.py", line 245, in _update_handler self.status_updated() File "/config/custom_components/localtuya/cover.py", line 185, in status_updated time_diff = time.time() - self._timer_start TypeError: unsupported operand type(s) for -: 'float' and 'NoneType'
Exception in _update_handler when dispatching 'localtuya_50758014840d8e91f4fd': ({'1': '3'},) Traceback (most recent call last): File "/config/custom_components/localtuya/common.py", line 245, in _update_handler self.status_updated() File "/config/custom_components/localtuya/cover.py", line 185, in status_updated time_diff = time.time() - self._timer_start TypeError: unsupported operand type(s) for -: 'float' and 'NoneType'

What’s wrong? what should I do please?

Hi
please any help regarding the above? Is there something I can do? I am thinking to completely remove the integration and re- added it but I am not sure if it will solve the problem.

It’s reported here:

1 Like

ok, that’s good. At least I didn’t deleted the integration yet since it would not solve the problem.
As I can understand hopefully the team will fix it.
Can you confirm, that when it will be fixed we will see the update in HACS. right?

Yeah, @rospogrigio can make a release once it’s fixed.

Dear @Makis, I pushed a candidate fix in the following PR: https://github.com/rospogrigio/localtuya/pull/189 , can you please test it and report there if it fixes your problem?
Thank you

Hi, of course I will try it. But please can you tell me what I have to do?

Replace the cover.py file in your localtuya folder with the one you find here:
https://raw.githubusercontent.com/rospogrigio/localtuya/cover_fix_time_nonetype/custom_components/localtuya/cover.py
And let us know…

yes, it is working
thank you!

Hi, @rospogrigio.

With the last master branch 3.1.0, also a lot of entries appeared in the logs.

Entries in the logs
Logger: custom_components.localtuya.light
Source: custom_components/localtuya/pytuya/__init__.py:132
Integration: LocalTuya integration (documentation, issues)
First occurred: 10:25:53 (518 occurrences)
Last logged: 10:33:25

[121...281] Entity light.in_wall_dimmer_2 is requesting unset index for option color_mode
[121...281] Entity light.in_wall_dimmer_2 is requesting unknown DPS index None
[830...dcb] Entity light.on_wall_dimmer is requesting unset index for option color_mode
[830...dcb] Entity light.on_wall_dimmer is requesting unknown DPS index None
[046...60d] Entity light.in_wall_dimmer_1 is requesting unset index for option color_mode
[046...60d] Entity light.in_wall_dimmer_1 is requesting unknown DPS index None

But there is no color_temp or color_mode DP in dimmers. Brightness DP only.

OnWall dimmer has:

OnWall Dimmer

onwall dimmer

InWall dimmer has:

InWall Dimmer

inwall dimmer

In InWall Dimmers - DP 101 is a separate setting for the minimum brightness level.

Or is it okay?

Thanks.

I have been spending hours with no luck with different android emulators, different versions of tuya apps and attempts with local sniffers on my samsung phone, but no luck of getting the IDs of my motion sensors or switches.

Does anyone please have a method that always work for you? From a windows computer or non-rooted android phone?
Thanks :slight_smile:

Hi. I use this method:

For those who use the Tuya Smart app on Android, and have a PC with Windows OS.

For getting the Tuya Smart LocalKey (or device ID, or etc.). There a method a “easier” way.

The Tuya Smart app stores the LocalKey in a XML-File on your phone/tablet. Usually you can’t access it until the phone is rooted. But don’t worry, no need to root your phone, there is a easier way.

We will install a Android emulator, root it, install the Tuya Smart app and extract the keys. To do so, go to:

Bstweaker

and download the latest BlueStacks Tweaker (Link is on top of the page) and Bluestacks installation (down below) according to your OS (32/64Bit).
Also go town to “utils” and download SuperSu 2.82-SR5.apk and Root Checker Pro 1.6.2.apk.

Then install Bluestacks, and after installation, follow the first instructional video on the page to root Bluestacks.

With rooted Bluestacks, go to Play Store and Download “Tuya Smart” app.

N.B. Version Tuya Smart App should be no higher v.3.6.1

Make sure to run it once, login and access your device’s once!

This is essential because only when doing so, it will get the configuration to our Bluestacks rooted phone!

Next, install “ES File Explorer” from Google Play store.
Set ES File Explorer to “Root Mode” (Scroll down left to find “Root Explorer”)

Set ES File Explorer

a warning will popup if root sholud be granted, grant it.

root sholud be granted

get_id_4

Now on the right, navigate to:

/data/data/com.tuya.smartlife/shared_prefs

shared_prefs

shared pref

You end up in a folder with some XML-files, this is where we want to go.

XML-files

shared pref1

Find the file called:

preferences_global_key_<some chars and numbers>.xml 

and click it. ES File Explorer will open it (or better copy file and open in Notepad++). You will find the ID of your device’s!

In my case, it:

I use this method to get local ID for devices of various manufacturers, for example Tuya Smart, Xiaomi, Midea Air.

3 Likes

Hi
apparently there is still something wrong.
Today some of my covers where grayed out and I could not use them at all, even with the slider
The logs are

og Details (ERROR)
Logger: homeassistant
Source: components/tuya/__init__.py:146
First occurred: 7:44:52 AM (17 occurrences)
Last logged: 9:50:01 AM

Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/tuya/__init__.py", line 153, in async_poll_devices_update
    device_list = await hass.async_add_executor_job(_get_updated_devices)
  File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/tuya/__init__.py", line 146, in _get_updated_devices
    tuya.poll_devices_update()
  File "/usr/local/lib/python3.8/site-packages/tuyaha/tuyaapi.py", line 166, in poll_devices_update
    return self.discover_devices()
  File "/usr/local/lib/python3.8/site-packages/tuyaha/tuyaapi.py", line 207, in discover_devices
    devices = self.discovery()
  File "/usr/local/lib/python3.8/site-packages/tuyaha/tuyaapi.py", line 188, in discovery
    response = self._request("Discovery", "discovery")
  File "/usr/local/lib/python3.8/site-packages/tuyaha/tuyaapi.py", line 267, in _request
    self._raise_frequently_invoke(
  File "/usr/local/lib/python3.8/site-packages/tuyaha/tuyaapi.py", line 292, in _raise_frequently_invoke
    raise TuyaFrequentlyInvokeException(message)
tuyaha.tuyaapi.TuyaFrequentlyInvokeException: Method [Discovery] fails 1 time(s) using poll interval 60.0 - error: you can discovery once in 600 seconds

and

Log Details (ERROR)
Logger: homeassistant.util.logging
Source: util/logging.py:108
First occurred: 7:39:52 AM (1 occurrences)
Last logged: 7:39:52 AM

Exception in _update_handler when dispatching 'localtuya_50758014840d8e91f036': ({},) Traceback (most recent call last): File "/config/custom_components/localtuya/common.py", line 245, in _update_handler self.status_updated() File "/config/custom_components/localtuya/cover.py", line 168, in status_updated if self._state.isupper(): AttributeError: 'NoneType' object has no attribute 'isupper'

Screenshot 2020-11-26 094846

Mmm I believe this is something for @postlund, or maybe you just had some connection issues…

not sure for the connections issues because everything else was working ok or at least I think so

The first exception is from the regular tuya integration, so not a problem for us. The other indicates that a status update has been received, but for some reason we don’t have a state yet (I.e. value for the ID DP). This is a case I guess shouldn’t happen, but maybe we should guard against it since it can happen sometimes when there’s an issue with the initial DP detection.

Hi

In Log for Dimmer. Dimmer work ON, OFF and adjust Brightness.
Dimmer ON:

WARNING
Logger: custom_components.localtuya.light
Source: custom_components/localtuya/pytuya/__init__.py:132
Integration: LocalTuya integration (documentation, issues)
First occurred: 11:16:22 (1080 occurrences)
Last logged: 11:20:09

[830...dcb] Entity light.on_wall_dimmer is requesting unset index for option color_mode
[830...dcb] Entity light.on_wall_dimmer is requesting unknown DPS index None
[830...dcb] Entity light.on_wall_dimmer is requesting unknown DPS index 1
[830...dcb] Entity light.on_wall_dimmer is requesting unknown DPS index 2
(1080 occurrences)

Dimmer OFF

Logger: custom_components.localtuya.light
Source: custom_components/localtuya/pytuya/__init__.py:132
Integration: LocalTuya integration (documentation, issues)
First occurred: 11:16:22 (1424 occurrences)
Last logged: 11:28:23

[830...dcb] Entity light.on_wall_dimmer is requesting unset index for option color_mode
[830...dcb] Entity light.on_wall_dimmer is requesting unknown DPS index None
[830...dcb] Entity light.on_wall_dimmer is requesting unknown DPS index 1
[830...dcb] Entity light.on_wall_dimmer is requesting unknown DPS index 2
(1424 occurrences)

After reboot server:

Logger: custom_components.localtuya.light
Source: custom_components/localtuya/pytuya/__init__.py:132
Integration: LocalTuya integration (documentation, issues)
First occurred: 11:33:29 (12 occurrences)
Last logged: 11:33:29

[830...dcb] Entity light.on_wall_dimmer is requesting unknown DPS index None
[121...4c6] Entity light.in_wall_dimmer_1 is requesting unset index for option color_mode
[121...4c6] Entity light.in_wall_dimmer_1 is requesting unknown DPS index None
[121...281] Entity light.in_wall_dimmer_2 is requesting unset index for option color_mode
[121...281] Entity light.in_wall_dimmer_2 is requesting unknown DPS index None

How to fix this?