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
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.file -> device_cloud_info
- Or download
entry
diagnosticsnote: It contains all devices data
file -> cloud_devices
Inside downloaded txt file
, in cloud_data object
look for your device_id -> dps_data
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
includes all known categories
and possible entities.
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
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),
set_position_dp=DPCode.PERCENT_CONTROL,
),
),