-
Notifications
You must be signed in to change notification settings - Fork 355
Converters
Alex X edited this page Apr 5, 2024
·
10 revisions
All devices are described by a specification with a list of converters in this file. It has a description of how converters work.
You can write you own external converter without change integration code. Just create xiaomi_gateway3.py
file in Hass config folder.
- Devices are checked by model name: string for Zigbee device and number for BLE and Mesh devices
- one specification can describe several models of devices as long as they do not have differences
- the new device is added to the top of the list, so it will have a higher priority when checking for a model match and you can override the built-in converters
from custom_components.xiaomi_gateway3.core.devices import *
DEVICES = [{
"lumi.switch.n0agl1": ["Aqara", "Relay T1", "SSM-U01"],
"spec": [
BaseConv("switch", "switch", mi="2.p.1"), # bool
MathConv("energy", "sensor", mi="3.p.1", multiply=0.001, round=2),
MathConv("power", "sensor", mi="3.p.2", round=2),
BoolConv("led", "switch", mi="4.p.1"), # uint8
MapConv("power_on_state", "select", mi="5.p.1", map={0: "off", 1: "previous"}),
],
}] + DEVICES
Some tips:
-
ZOnOffConv
- this is simple converter for on/off devices (relays and light)- first argument - it's entity name in Hass, example:
switch
,plug
,outlet
,channel_1
, etc. - second argument - entity type in Hass, example:
switch
orlight
- first argument - it's entity name in Hass, example:
- For multichannel devices you need add endpoint parameter, example:
ep=2
- Some single-channel devices don't work on the 1st endpoint, you must also add enpoint parameter
-
ZigbeeStats
,ZTuyaPowerOn
- this are converters with already specified the attribute name and entity type
from custom_components.xiaomi_gateway3.core.devices import *
DEVICES = [{
"01MINIZB": ["Sonoff", "Mini", "ZBMINI"],
"spec": [ZOnOffConv("switch", "switch")]
}] + DEVICES
from custom_components.xiaomi_gateway3.core.devices import *
DEVICES = [{
"FNB56-ZSC01LX1.2": ["Unknown", "Dimmer", "LXZ8-02A"],
"spec": [
ZOnOffConv("light", "light"),
ZBrightnessConv("brightness", parent="light"),
]
}] + DEVICES
from custom_components.xiaomi_gateway3.core.devices import *
DEVICES = [{
"TS0121": ["BlitzWolf", "Plug", "BW-SHP13"],
"support": 5,
"spec": [
ZOnOffConv("plug", "switch"),
ZVoltageConv("voltage", "sensor", entity={"poll": True}),
ZCurrentConv("current", "sensor", multiply=0.001),
ZPowerConv("power", "sensor"),
ZEnergyConv("energy", "sensor", multiply=0.01),
ZTuyaPowerOnConv("power_on_state", "select"),
],
}] + DEVICES
Tuya multichannel relay with optional power_on_state
.
from custom_components.xiaomi_gateway3.core.devices import *
DEVICES = [{
"TS0115": ["UseeLink", "Power Strip", "SM-SO306E"],
"spec": [
ZOnOffConv("channel_1", "switch", ep=1),
ZOnOffConv("channel_2", "switch", ep=2),
ZOnOffConv("channel_3", "switch", ep=3),
ZOnOffConv("channel_4", "switch", ep=4),
ZOnOffConv("usb", "switch", ep=7),
ZTuyaPowerOnConv("power_on_state", "select"),
]
}] + DEVICES