Local tuya light bulb protocol version 3.3

Hi, another user kinda new to HA so seeking a little guidance.

I have some Brilliant Downlights which are using API 3.3. I’m also controlling them via the cloud with voice assistants, not ready to flash them just yet but would still like to make use of localtuya in HA as well.

I’ve managed to get them working (I’m using this fork) by changing the index IDs to:

DPS_INDEX_ON         = '20'
DPS_INDEX_MODE       = '21'
DPS_INDEX_BRIGHTNESS = '22'
DPS_INDEX_COLOURTEMP = '23'
DPS_INDEX_COLOUR     = '26'

which these lights are using instead of 1-6.

The last problem I’m having is they seem use a brightness scale of 10 - 1000 instead of 25 - 255 and colour temp is set from 0 to 1000.

When I use the sliders of the component, I can only set a maximum brightness of 255 and a colour temp up to 255.

I’ve changed everything I could find relating to it in the scripts, so I’m guessing I’m left with HA storing these values in a scale of 0-255 and I will have to add some extra conversion in the scripts to scale them up to the 1000 range?

Am I on the right track?
Thanks

(Edit: Found this one which is already modified for the 1000 range)

@bamzero Hello.

What it looks like in your configuration.yaml

I have a dimmer, but it works just like a switch. Thanks.

Nothing special, just like the example

light:
  - platform: localtuya
    host: 10.0.0.1
    local_key: 1234567891234567
    device_id: 12345678912345671234
    name: tuya01

Sounds like you may have it as a switch: ?
If so try light: (if you are using a different component and it doesn’t work try either of the two I linked.)

I have several 1-, 2-, 3-channel switches, relays, and smart plugs (with a measurement of power consumption). I also have several dimmers, such as:

I also use this custom component. But in it, my dimmers only work as switches: ON and OFF. Without adjusting the brightness level.

And the author of this component wrote to me:

As a dimmer, this component does not know how to work - only as a switch.

Does this component work as a dimmer for you?

Hello.

I am try light:

light:
  - platform: localtuya
    host: 192.168.1.91
    local_key: 33054eabd5292214
    device_id: 83054170840d8e91adcb
    name: dimmer_01
    protocol_version: 3.1

use this custom component.

The dimmer appeared in the HA interface,

but it does not work. In logs:

Update for light.dimmer_01 fails
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 281, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 461, in async_device_update
    await self.hass.async_add_executor_job(self.update)
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/localtuya/light.py", line 223, in update
    brightness = int(self._device.brightness())
  File "/config/custom_components/localtuya/light.py", line 140, in brightness
    return self._device.brightness()
  File "/config/custom_components/localtuya/pytuya/__init__.py", line 560, in brightness
    return self.status()[self.DPS][self.DPS_INDEX_BRIGHTNESS]
KeyError: '3'

What does this Error mean and what am I doing wrong? Thanks.

P.S. The dimmer has only state and brightness:

dpName: {}, dps: {1: true, 2: 255}

2 - is the brightness.

Normally 1 is on/off state, 2 is colourmode and 3 is brightness.

You will have to edit your init.py in pytuya for your DPS_INDEX values.

Try changing value for DPS_INDEX_BRIGHTNESS = ‘3’ to ‘2’
and DPS_INDEX_MODE = ‘2’ to ‘3’

(You may need to change the DPS_2_STATE values below it to match also)

Has anyone had anyone had luck getting RGB lights to work?
This repository link seems to attempt it but it is not working and it seems that the previous contributors are not maintaining it anymore.
I got the closest with the code from @Alfiegerner but have not be able to get it going. I’m not a coder so it might just be syntax or something.
I’m trying to avoid flashing my devices at this stage as I need to keep them in a working state until I get more devices.

what is the different between regular tuya and this one? Should I run both or just choose one?

localtuya means your HA is talking direct to the device (bulb etc).

WIth the normal integration:
Tuya HA --> talks to Tuya Cloud Server --> TuyaServers talk to Bulb

Local Tuya :
HA --> Bulb

so your automations are not dependant on cloud anymore