Localtuya can disocver you device entities if cloud is enable because the feature at the moment rely on DP code
and Devices Category{target="_blank"}.
By known the category
we use that to get all the possible entities from stored data.
Data stored in /localtuya/core/ha_entities
(1)
{.annotate}
??? info "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
.
!!! tip annotate "How to get the Codes and DP
"
You can download your device data in your Home Assistant
by Downloading Diagnostics
.
1. Download `device` diagnostics `localtuya` from device page. (1) `file -> device_cloud_info`
2. Or download `entry` diagnostics `note: 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)
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 entites.
{.annotate}
- 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)
{.annotate}
- All entities platforms has
id
config name. but some has more DPs configs names
For example:cover platforms
has config names forcurrent_position_dp
andset_position_dp
??? example "Add code: switch_4
into SWITCHES
in kg
category"
python "kg": ( LocalTuyaEntity( id=DPCode.SWITCH_4, # REQUIRED: id config name = look DP with code `switch_4` name="Switch 4", # Name the entity: `Switch 4` icon="mdi:icon_name", # icon for the entity entity_category=EntityCategory.CONFIG, # Show entity in this category ), ),
??? example "Add switch
into SWITCHES
in cl
category: with condition"
python "cl": ( LocalTuyaEntity( id=DPCode.CONTROL_BACK, name="Reverse", icon="mdi:swap-horizontal", entity_category=EntityCategory.CONFIG, condition_contains_any=["true", "false"], ), ),
??? example "Add cover
into COVERS
in cl
category"
python "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, ), ),
1. `current_position_dp` will search for DP of two possible codes and will take the first `DP` found.