feat: add light effects driven over Zigbee
Add animated effects to the light, controlled from Home Assistant. * Identify Trigger Effect (ZCL 3.5.2.3.3): the light plays Blink, Breathe, Okay and Channel change as overlays on its current state, and returns to exactly what it was showing (src/effect.rs). Home Assistant's flash option uses this. * Scenes: Rainbow, Pulse and Comet run continuously and use the light's own colour and brightness, so on/off, level and colour keep working while one plays (src/scene.rs). The strip is redrawn every 20 ms while anything animates. * A manufacturer-specific effects cluster (0xfd00) selects the scene and tunes its speed and intensity (src/effects_cluster.rs). It uses 0xc0de as a development manufacturer code, which is also what the node descriptor now reports instead of the NXP code it had borrowed. * A ZHA quirk exposes the cluster as a select and two number entities (ha/zha_quirks/smart_light.py). Copy it to a folder set as ZHA's custom_quirks_path. * Ignore Python bytecode. vendor/zigbee-rs is not vendored here: it stays a submodule, now tracking feature/lighting-effects-integration on the fork. That branch adds the manufacturer-specific cluster support and Identify Trigger Effect on top of the RGB colour control work, each of which is also on its own branch for upstream. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
1 parent
cb4b38fc01
commit
115f245484
10 files changed
+665
-13
No files matched your search
@@ -0,0 +1,116 @@
|
||||
"""ZHA quirk for the smart-light effects cluster.
|
||||
|
||||
The light serves a manufacturer-specific cluster (0xFD00, manufacturer code
|
||||
0xC0DE) through which Home Assistant picks an animated scene and tunes it. ZHA
|
||||
cannot talk to a cluster it has no definition for, so this quirk supplies one
|
||||
and turns its attributes into entities:
|
||||
|
||||
* a select for the effect (Off, Rainbow, Pulse, Comet)
|
||||
* a number for the speed, and one for the intensity
|
||||
|
||||
The scene plays in the light's own colour and brightness, so the light's
|
||||
on/off, brightness and colour controls keep working while one runs.
|
||||
|
||||
The identifiers here have to match the firmware: src/effects_cluster.rs.
|
||||
|
||||
Install: copy this file into a folder under the Home Assistant config
|
||||
directory, point ZHA at it in configuration.yaml, and restart Home Assistant:
|
||||
|
||||
zha:
|
||||
custom_quirks_path: /config/custom_zha_quirks/
|
||||
|
||||
The Zigbee device is then listed with the extra entities.
|
||||
|
||||
Untested against a running ZHA: the import fallbacks below are there because
|
||||
the quirk authoring API has moved between releases.
|
||||
"""
|
||||
|
||||
import zigpy.types as t
|
||||
from zigpy.zcl.foundation import BaseAttributeDefs, ZCLAttributeDef
|
||||
|
||||
try:
|
||||
from zhaquirks.clusters import CustomCluster
|
||||
except ImportError: # older zha-quirks
|
||||
from zhaquirks import CustomCluster
|
||||
|
||||
try:
|
||||
from zhaquirks.builder import EntityType, QuirkBuilder
|
||||
except ImportError: # older zha-quirks
|
||||
from zigpy.quirks.v2 import QuirkBuilder
|
||||
from zigpy.quirks.v2.homeassistant import EntityType
|
||||
|
||||
CLUSTER_ID = 0xFD00
|
||||
# a development code: the device has no manufacturer code of its own
|
||||
MANUFACTURER_CODE = 0xC0DE
|
||||
|
||||
|
||||
class SmartLightEffect(t.enum8):
|
||||
"""The scene playing."""
|
||||
|
||||
Off = 0x00
|
||||
Rainbow = 0x01
|
||||
Pulse = 0x02
|
||||
Comet = 0x03
|
||||
|
||||
|
||||
class SmartLightEffectsCluster(CustomCluster):
|
||||
"""The light's effects cluster."""
|
||||
|
||||
cluster_id = CLUSTER_ID
|
||||
ep_attribute = "smart_light_effects"
|
||||
# without this, ZHA would use the device's node descriptor code
|
||||
manufacturer_id_override = MANUFACTURER_CODE
|
||||
|
||||
class AttributeDefs(BaseAttributeDefs):
|
||||
"""Attribute definitions."""
|
||||
|
||||
effect = ZCLAttributeDef(
|
||||
id=0x0000,
|
||||
type=SmartLightEffect,
|
||||
is_manufacturer_specific=True,
|
||||
)
|
||||
speed = ZCLAttributeDef(
|
||||
id=0x0001,
|
||||
type=t.uint8_t,
|
||||
is_manufacturer_specific=True,
|
||||
)
|
||||
intensity = ZCLAttributeDef(
|
||||
id=0x0002,
|
||||
type=t.uint8_t,
|
||||
is_manufacturer_specific=True,
|
||||
)
|
||||
|
||||
|
||||
(
|
||||
QuirkBuilder("smart-light", "smart-light.ws2812")
|
||||
.adds(SmartLightEffectsCluster)
|
||||
.enum(
|
||||
SmartLightEffectsCluster.AttributeDefs.effect.name,
|
||||
SmartLightEffect,
|
||||
SmartLightEffectsCluster.cluster_id,
|
||||
entity_type=EntityType.STANDARD,
|
||||
translation_key="effect",
|
||||
fallback_name="Effect",
|
||||
)
|
||||
.number(
|
||||
SmartLightEffectsCluster.AttributeDefs.speed.name,
|
||||
SmartLightEffectsCluster.cluster_id,
|
||||
min_value=0,
|
||||
max_value=255,
|
||||
step=1,
|
||||
entity_type=EntityType.STANDARD,
|
||||
translation_key="effect_speed",
|
||||
fallback_name="Effect speed",
|
||||
)
|
||||
.number(
|
||||
SmartLightEffectsCluster.AttributeDefs.intensity.name,
|
||||
SmartLightEffectsCluster.cluster_id,
|
||||
min_value=0,
|
||||
max_value=255,
|
||||
step=1,
|
||||
entity_type=EntityType.STANDARD,
|
||||
translation_key="effect_intensity",
|
||||
fallback_name="Effect intensity",
|
||||
)
|
||||
.add_to_registry()
|
||||
)
|
||||
Reference in new issue
Block a user