Auto configure devices
Localtuya can disocver you device entities if cloud is enable because the feature at the moment rely on DP code and Devices Category.
By known the category we use that to get all the possible entities from stored data.
Data stored in /localtuya/core/ha_entities (1)
- Files are named with entities type

DPCodes data
All known Codes are stored in base.py in DPCode Class.
If class doesn't contains your DPCode Add it, DPCode class sorted in alphabetically.
How to get the Codes and DP
You can download your device data in your Home Assistant by Downloading Diagnostics.
- Download
devicediagnosticslocaltuyafrom device page. (1)file -> device_cloud_info - Or download
entrydiagnosticsnote: It contains all devices data(2)file -> cloud_devices
Inside downloaded txt file, in cloud_data object look for your device_id -> dps_data (3)


- TIP: Search for device name instead of
device_id
Now that we know the device category and Codes we can start add the entities.
In /localtuya/core/ha_entities open the file named with entity type you want to add.
All files contains constant dict (1) includes all known categories and possible entities.
- e.g
COVERS or SWITCHES
Look for the category it already exist modify it and add the missing entities.
Using LocalTuyaEntity class we pass entity parameters id and DPs config name as keys and DPCode as values Config names has to be supported by localtuya (1)
- All entities platforms has
idconfig name. but some has more DPs configs names
For example:cover platformshas config names forcurrent_position_dpandset_position_dp
Examples
Add code: switch_4 into SWITCHES in kg category
Add switch into SWITCHES in cl category: with condition
Add cover into COVERS in cl category
"cl": (
LocalTuyaEntity(
id=DPCode.CONTROL,
name="Curtain",
custom_configs=localtuya_cover("open_close_stop", "position"), # localtuya config
current_state=DPCode.SITUATION_SET,
current_position_dp=(DPCode.PERCENT_CONTROL, DPCode.PERCENT_STATE),#(1)!
set_position_dp=DPCode.PERCENT_CONTROL,
),
),
current_position_dpwill search for DP of two possible codes and will take the firstDPfound.