Tuya LOCAL with energy monitoring and without tuya-convert

Good! :slight_smile: Then it was my fault, I thought it only applied to switch devices
 I fixed it in the 2.0.3 release I just published, now the correct handling of device20/device22 dev_types works for all devices (cover/switch/light). I have published it, maybe it could fix @OfWonder’s problems too

If you make some improvements to the cover class please share it with me so we might improve the repo.
Bye!

1 Like

Implementing the most current version now prevents my instance of home assistant from starting at all. I am running in a virtual machine. I am not sure if that would effect this in any way. Also, I am not sure what dps means, but are there any edits that need to be made to the light.py file on a case by case basis?

It actually starts eventually. It just takes around 10 to 15 minutes. Please see below for a sample of my logs:

Updating localtuya light took longer than the scheduled update interval 0:00:30

2:51:25 AM – Light (WARNING) - message first occurred at 2:49:25 AM and shows up 5 times

Failed to get status after 3 tries

2:50:05 AM – localtuya (WARNING)

Update of light.test is taking over 10 seconds

2:49:05 AM – /usr/local/lib/python3.8/asyncio/events.py (WARNING)

Setup failed for default_config: Could not set up all dependencies.

2:48:25 AM – setup.py (ERROR)

Unable to set up dependencies of default_config. Setup failed for dependencies: logbook, zone

2:48:25 AM – setup.py (ERROR)

Setup of logbook is taking longer than 300 seconds. Startup will proceed without waiting any longer

2:48:25 AM – setup.py (ERROR) - message first occurred at 2:48:25 AM and shows up 2 times

Waiting on integrations to complete setup: zone, zeroconf, mqtt, tuya, mobile_app

2:48:25 AM – bootstrap.py (WARNING)

Timeout fetching Home Assistant update data

2:48:25 AM – Updater (ERROR)

Setup of zone is taking over 10 seconds.

2:48:24 AM – /usr/local/lib/python3.8/asyncio/events.py (WARNING) - message first occurred at 2:48:24 AM and shows up 2 times

Setup of light platform localtuya is taking over 10 seconds.

2:48:24 AM – Light (WARNING)

Updating state for light.test (<class ‘custom_components.localtuya.light.TuyaDevice’>) took 210.132 seconds. Please report it to the custom component author.

2:48:24 AM – helpers/entity.py (WARNING)

Failed to get color temp after 3 tries

2:48:24 AM – localtuya (WARNING) - message first occurred at 2:43:09 AM and shows up 4 times

You are using a custom integration for localtuya which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant.

2:41:24 AM – loader.py (WARNING)

I also get this notification:

Invalid config

The following integrations and platforms could not be set up:

Please check your config.

@OfWonder regarding the startup time: I experienced the same last week (not related to localtuya), startup took 10 minutes and it turned out to be the DB which got corrupted or too big: I deleted it and restarted and now it takes approx. 1 minute. Also please check your config since you are getting an “Invalid config” error.
You should not be editing light.py unless we discover that there is some bug in there.
What you should try to understand is:

  1. if your devices are switch or light (how does the tuya integration detects them)?
  2. at this point you should have found the deviceId and localKey of the devices. The length of the deviceId tells you whether it is a device20 or device22: in the latter case, dps values need to be specified in the requests in order to communicate with the device. Localtuya does it since v1.0.1, but you have to specify the correct dps in the configuration
  3. the dps involved can be extracted when you sniff the communication with the device, the same way you should have found the localKey and deviceId: you should detect which dps represent the status of each subswitch, and configure the .yaml files accordingly

Once again, if you want to give me SSH access to your system I can try something myself, otherwise you can ship me the device as you proposed.
Bye
rospogrigio

1 Like

Hi @rospogrigio, I submitted a pull request. This is the first pull request i’ve ever submitted, so I hope I did it right. I made two changes:

(1) General reorganization of the README to make things easier to follow
(2) Added support for alternate open/close/stop commands. The defaults open and close commands are “on” and “off”. Those commands don’t work for my device, as my cover device uses “open” and “close” instead. I left “on” and “off” as the defaults, but you can now edit the commands via configuration.yaml.

Nice job, I’ll test it and release it when I have some spare time.
Thank you!

1 Like

Just published the new release 1.1.0, integrating the huge work by @loaxley and fan support by @fancygaphtrn (could not test it so I trust it is working).
Enjoy!
rospogrigio

1 Like

I have suffered some hours to obtain my keys.
If this helps someone:

On a Linux VM:

sudo apt get install npm
npm i @tuyapi/cli -g`
tuya-cli list-app

Followed this tutorial (it’s in italian, translated with google translate).

You need Smart Life app version 3.12.6 for this to work.

I have an interesting case.

Micaela Centro and Retroiluminacion mueble are on the same switch, when i start Home assistant, both work. A few seconds later, Micaela Centro (the first switch within the 2-gang switch) disconnects.

Before disconnection:

After disconnection:

I have 3 2-gang switches and all have the same behavior.

Here is config YAML:

platform: localtuya
    host: 192.168.1.147
    local_key: xxx
    device_id: xxx
    name: MicaPrincipal
    friendly_name: Dormitorio Micaela Principal
    protocol_version: 3.3
    switches:
      sw01:
        name: MicaCentro
        friendly_name: Micaela Centro
        id: 1
      sw02:
        name: RetroMuebl
        friendly_name: Retroiluminacion Mueble
        id: 2

The ID of the second switch does not seem to affect. Initially it was 7, and it worked exactly the same. When i change the ID of the first switch however, Home Assistant takes longer to initiate.

I have this configured for debug:

logger:
  default: info
  logs:
    custom_components.localtuya: debug

But no debug logs appear on my Configuration/logs.

Any ideas?

Hi everyboy
I bought recently: https://www.aliexpress.com/item/32963064005.html?cv=47843&af=240682&utm_campaign=240682&aff_platform=api-new-hotproduct-download&mall_affr=pr3&utm_medium=cpa&aff_trace_key=846020afb0e6447baafa18dc64f52180-1599320317881-07358&dp=c1b62826282e64fe595285cedd0ea079&terminal_id= aa2e180765bd4eb080bcdbfce3ca1207 & tmLog = new_Detail & utm_source = admitad & utm_content = 47843

I would like to integrate it locally, with “localtuya”. I have already integrated interrupeteur but for the cover commetn to do ??

Thank you.

(Sorry for my bad English)

I have alarm panel with dps:
{
1 disarmed
2 20
3 1
4 false
9 true
10 false
15 true
16 100
17 true


}

as I understand dps1 its mode of alarm: armed, disarmed, stay, home. Can I change this dps with localtuya?

I don’t believe that localtuya currently supports alarm devices, but you can certainly get and set the dps for any device type with tuya-cli https://github.com/TuyaAPI/cli.

I dont understand haw integrate tuya cli in HA.

I see that two “Retroiluminacion Mueble” appear: maybe you have some conflicts going on: go to Configuration-Entities and remove invalid entities. Then, in order to enable further debugging you can add:

  logs:
    custom_components.localtuya: debug
    custom_components.localtuya.pytuya: debug

and check what you see in home-assistant.log

1 Like

Hi guys can you also add support for local control of thermostats? I mean climate class.

I had already tried similar addon from this link but it doesnt work for me.

@Alloc186 , please wait because with the help of some skilled developers we are improving the repository introducing major features and improving robustness and integration with Home Assistant. Once we have done with this major job we can concentrate on adding other devices such as thermostats
 thank you for your waiting.

1 Like

Okey, thanks for info! You are doing great job .-) I will be waiting.

If you are using this component (and the switch or light platforms in particular for now), I need some help. I’m working on config flow support so you can add devices from the UI (YAML support is still there, but is converted into a config entry) and I basically need testers for it.

Links to PRs are here:


Worth noting regarding YAML if you decide to stay with that
 Changes are updated if change something in YAML but if you remove a device from YAML, you still have to manually go to Configuration -> Integrations and remove it there as well.

1 Like

I created a PR for cover platform as well:

1 Like

Hi, tuyalocal used to turn devices on or off locally ?? or still use the cloud?? please answer me soon