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
device
diagnosticslocaltuya
from device page. (1)file -> device_cloud_info
- Or download
entry
diagnosticsnote: 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 entites.
- 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
id
config name. but some has more DPs configs names
For example:cover platforms
has config names forcurrent_position_dp
andset_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_dp
will search for DP of two possible codes and will take the firstDP
found.