Tuya LOCAL with energy monitoring and without tuya-convert

Hi

There is a bug fix (pending integration) for an issue where some connection drops and fail to recover. I am running the branch with the fix and it is going really well. I suggest you try running that branch (or wait for it to be in the master) before further reporting?

My understanding is that tuya devices can only handle one local connection at a time and that running the smart life app you are making things work

Good Morning. I am new to HA and therefore new to LocalTuya. I spent 8 hours yesterday and finally had some success, I managed to turn a Tuya Light on using the LocalTuya integration BUT I cannot turn it off
 here is my configuration.yaml:

localtuya:

  • host: 192.168.86.101
    device_id: xxx
    local_key: xxx
    friendly_name: Test Light
    protocol_version: “3.1”
    entities:
    • platform: light
      friendly_name: Device Light
      id: 1
      brightness: 22

It works through the Tuya App, it works through the Tuya Integration and if I turn off the internet to the IP I can turn it on with LocalTuya but the toggle in the device flicks back to OFF almost as soon as I turn it on
 I have an in-wall dimmer I want to use and I doubt I can Tasmotize it so I thought I’d try this methodology.

TIA

Are you sure it’s a version 3.1 device?

If I use 3.3 it fails to authenticate

the wizard function (which I couldn’t actually get to work BTW) sets it to 3.1 as well

also on restart of HA, the device toggle in LocalTuya becomes unresponsive
 I just noticed that if I turn the light off from the Tuya App the toggle responds again


This usually means that the local key is not correct. It has been the case in 9/10 times I would say. Quadruple check that fit gave the correct key.

if the Key was wrong I shouldn’t be able to even turn it on though? and that was my first thought
 I’ve checked it multiple times


Ah, yes, that’s right. My bad! Do you see anything at all in the log?

see now I don’t know where the log is
 I’m sorry I hate being a noob
 I’ve got 20+ years of broad IT experience behind me, but I feel like an idiot right now
 I can’t be THIS hard


You can start by clicking Configuration in the side-panel and scroll down to Log. Likely you will find some entries regarding localtuya there.

1 Like

OK
 so I have success at turning the light on and off
 In the log it is requesting color_mode
 I tried 2 and 21, neither of which work
 it is a normal a19 non-color globe
 the brand is Feit if that matters

Me again. So I have a Feit In-wall dimmer -switch to work. I don’t know jhow to configure the dimmer functions
 do I assume that I copy the light functions?

I would expect that you emulate that via light and use brightness for dimmer functionality.

Has ony one got this to work

Ive got the ID and localkey Local Tuya finds the devices (Nedis Power Plug with Powerconsuption) Ive added them to IOT Tuya like discrebed (som where)

Tried it with Tuya installed and with out and same result

I whant to extract the power cosnuption

Any tips

localtuya:

  • host: 192.168.86.102
    device_id: xxx
    local_key: xxx
    friendly_name: Tuya_Outside_Light_2
    protocol_version: “3.1”
    entities:

    • platform: light
      friendly_name: Outside_Light_2
      id: 1
      brightness: 1
      brightness_lower: 25
      brightness_upper: 255
  • host: 192.168.86.201
    device_id: xxxx
    local_key: xxxx
    friendly_name: Tuya_Dimmer_Switch
    protocol_version: “3.3”
    entities:

    • platform: light
      friendly_name: Dimmer_Switch
      id: 1
      brightness: 1
      #brightness_lower: 25
      #brightness_upper: 255

These get me me the ability to turn on the Light and switch. They both show that there is a dimming option in the entity. But neither actually dim function in the entity effect the device. I get on/off which is definitely better then where I was the other day but not all the way there :(
 I have tried a plethora of numbers against the brightness DPS value.

As a foot note
 I have 2 versions of Home assistant running, one is Hass.Io in a Vm and one is a containerized Hass install. In neither of these can I get the integration wizard method to work, I’ve had to edit the configuration.yaml file so I have not really had an opportunity to look at the expected values for the entities. Where can I find them in the localtuya folder? I am really enjoying playing with this integration and I would love to help at a lower level. I am going to be buying a bunch of stuff frpom Menards today (Motion sensor, door sensor, security camera) and maybe some stuff from Walmart (Merkury Brand) and see if they work differently. I hope my problems are not brand specific! I just remembered something actually in the tuya app when i click on the light I get an error “the current version does not support the device. Please update the app” Of course my Tuya App is completely up to date


I also just figured out, not sure if anyone else knew this or not
 the encryption key changes if you re-add a device back into your Tuya App


Third thing I noticed, my Feit Dimmer Switch, from inside the Tuya app, actually brings up a Feit screen to manipulate the Dimmer function
 is that relevant? I cannot now connect to my dimmer anymore after pairing it again to the Tuya app
 I have changed my configuration.yaml to reflect the new encryption key. I also have an error now in the TinyTuya program:

Traceback (most recent call last):
File “/usr/lib/python3.7/runpy.py”, line 193, in _run_module_as_main
“main”, mod_spec)
File “/usr/lib/python3.7/runpy.py”, line 85, in _run_code
exec(code, run_globals)
File “/home/shane/.local/lib/python3.7/site-packages/tinytuya/main.py”, line 44, in
tinytuya.scan(color=color)
File “/home/shane/.local/lib/python3.7/site-packages/tinytuya/init.py”, line 1087, in scan
d = deviceScan(True, maxretry, color)
File “/home/shane/.local/lib/python3.7/site-packages/tinytuya/init.py”, line 1139, in deviceScan
client.bind(("", UDPPORT))
OSError: [Errno 98] Address already in use

I read that I need to make sure I am logged out of the Tuya app I did that and I shut down my Tuya IoT page so I don’t know where i am going wrong
 It did pull the DeviceID’s and Encryption Key’s

HA is also giving me this error:
Logger: homeassistant
Source: runner.py:99
First occurred: 3:05:05 PM (1 occurrences)
Last logged: 3:05:05 PM

Error doing job: Unclosed connection

I have a problem with 1 WiFi plugg it looks like this in HA


I can controll it via Tyua Code in yamal
- host: 192.168.167.36
local_key:
device_id:
friendly_name: MysRummet
protocol_version: “3.3”
entities:
- platform: switch
friendly_name: MysRummet
id: 1
current: 18
current_consumption: 19
voltage: 20
- platform: sensor
friendly_name: MysRummet Current
id: 18
unit_of_measurement: ‘mA’
- platform: sensor
friendly_name: MysRummet Current Consumption
id: 19
scaling: 0.1
unit_of_measurement: ‘W’
- platform: sensor
friendly_name: MysRummet Voltage
id: 20
scaling: 0.1
unit_of_measurement: ‘V’

I also have 2 more WiFi pluggs (same brand) and they are working
Code in yamal

  • host: 192.168.167.33
    local_key:
    device_id:
    friendly_name: TV
    protocol_version: “3.3”
    entities:
    - platform: switch
    friendly_name: TV
    id: 1
    current: 18
    current_consumption: 19
    voltage: 20
    - platform: sensor
    friendly_name: TV Current
    id: 18
    unit_of_measurement: ‘mA’
    - platform: sensor
    friendly_name: TV AnvÀndning
    id: 19
    scaling: 0.1
    unit_of_measurement: ‘W’
    - platform: sensor
    friendly_name: TV Voltage
    id: 20
    scaling: 0.1
    unit_of_measurement: ‘V’

They are the same except ofc ID and key and IP Adress

What im i missing?

Thought I’d put this into the thread before adding it as a stand alone addon:

I’ve created a HASSOS addon which, with an api id/key, device id and region will query the Tuya API and provide a locally accessible file with all of your device Names, Ids and Keys

I just got sick of having to login to my ubuntu server to run the command.

This is very much a work in progress and currently it will query the API every 5 minutes when the Addon is running.

The addon is on my repo https://github.com/wlatic/hassio.addons

There are going to be issues, but hopefully with feed back, I can iron them out. Also someone may be able to take this and run with it!

4 Likes

I’d love to give this add-on a try. I added the repository, but the Tuyagrab add-on doesn’t show up to install.
Seeing this error in the logs:
Can’t read json from /data/addons/git/367cd613/addon-tuyagrab/tuyagrab/config.json: Expecting value: line 30 column 10 (char 566)