mirror of
https://github.com/bahmcloud/HA-KNX-Bridge.git
synced 2026-04-06 22:41:14 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 69267f7c0f | |||
| 91f51cb414 | |||
| 1eb283112c |
4
.idea/PROJECT_STATE.md
generated
4
.idea/PROJECT_STATE.md
generated
@@ -47,7 +47,9 @@ Completed:
|
|||||||
- Relative color temperature steps (DPT 3.007) added for lights.
|
- Relative color temperature steps (DPT 3.007) added for lights.
|
||||||
- Relative color temperature control wired into light schema, UI order adjusted, and KNX color temperature types aligned.
|
- Relative color temperature control wired into light schema, UI order adjusted, and KNX color temperature types aligned.
|
||||||
- Color temperature service calls now use mireds for better compatibility.
|
- Color temperature service calls now use mireds for better compatibility.
|
||||||
- Project version set to 0.0.29 and `CHANGELOG.md` maintained.
|
- Relative dimming/color temperature decoding improved for control/stepcode payloads.
|
||||||
|
- Relative dimming/CT now treat step_code 0 as a start/stop toggle and rely on raw payload parsing.
|
||||||
|
- Project version set to 0.0.32 and `CHANGELOG.md` maintained.
|
||||||
|
|
||||||
Files created:
|
Files created:
|
||||||
- `custom_components/ha_knx_bridge/__init__.py`
|
- `custom_components/ha_knx_bridge/__init__.py`
|
||||||
|
|||||||
@@ -1,5 +1,14 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 0.0.32 - 2026-02-15
|
||||||
|
- Treat DPT 3.007 step_code 0 as a start/stop toggle for relative dimming/CT and rely on raw payload parsing.
|
||||||
|
|
||||||
|
## 0.0.31 - 2026-02-15
|
||||||
|
- Treat DPT 3.007 step_code 0 as a single-step for relative dimming/CT and register control_dimming event types.
|
||||||
|
|
||||||
|
## 0.0.30 - 2026-02-15
|
||||||
|
- Improve relative dimming/color temperature decoding for control/stepcode payloads.
|
||||||
|
|
||||||
## 0.0.29 - 2026-02-15
|
## 0.0.29 - 2026-02-15
|
||||||
- Use mired-based HA color temperature service calls for better device compatibility.
|
- Use mired-based HA color temperature service calls for better device compatibility.
|
||||||
|
|
||||||
|
|||||||
@@ -74,9 +74,10 @@ Only state addresses expose an `invert outgoing` toggle to flip KNX payloads.
|
|||||||
|
|
||||||
Notes:
|
Notes:
|
||||||
- For XY color, the bridge sends the brightness as the Y (luminance) component.
|
- For XY color, the bridge sends the brightness as the Y (luminance) component.
|
||||||
- Relative dimming (DPT 3.007) maps KNX step values to small `brightness_step_pct` changes in Home Assistant.
|
- Relative dimming (DPT 3.007) maps KNX step values (control/stepcode) to small `brightness_step_pct` changes in Home Assistant.
|
||||||
- For relative dimming, the bridge repeats steps until a KNX stop telegram (0 or 8) is received.
|
- For relative dimming, the bridge repeats steps until a KNX stop telegram (0 or 8) is received.
|
||||||
- Relative color temperature (DPT 3.007) adjusts Kelvin in the same start/stop pattern.
|
- Relative color temperature (DPT 3.007) adjusts Kelvin in the same start/stop pattern.
|
||||||
|
- Some KNX keypads send `step_code 0` for a start/stop toggle; the bridge treats `step_code 0` as start when idle and stop when already dimming.
|
||||||
- Color temperature mode must match the KNX telegram DPT: `relative` for 5.001, `absolute` for 7.600 (2-byte unsigned), `absolute_float` for DPT 9 (2-byte float). The bridge sends HA color temperature using `color_temp` (mireds) for maximum compatibility.
|
- Color temperature mode must match the KNX telegram DPT: `relative` for 5.001, `absolute` for 7.600 (2-byte unsigned), `absolute_float` for DPT 9 (2-byte float). The bridge sends HA color temperature using `color_temp` (mireds) for maximum compatibility.
|
||||||
|
|
||||||
## Notes
|
## Notes
|
||||||
@@ -112,5 +113,5 @@ Notes:
|
|||||||
- Advanced DPT mapping options and inversion settings.
|
- Advanced DPT mapping options and inversion settings.
|
||||||
|
|
||||||
## Versioning and Releases
|
## Versioning and Releases
|
||||||
- Current version: 0.0.29
|
- Current version: 0.0.32
|
||||||
- `CHANGELOG.md` lists versions with the newest entries at the top.
|
- `CHANGELOG.md` lists versions with the newest entries at the top.
|
||||||
|
|||||||
@@ -1172,7 +1172,19 @@ class BridgeManager:
|
|||||||
return
|
return
|
||||||
|
|
||||||
if action == "relative_dimming":
|
if action == "relative_dimming":
|
||||||
value = _extract_event_value(event)
|
dim_info = _extract_dimming_info(event)
|
||||||
|
if dim_info is not None:
|
||||||
|
control, step_code = dim_info
|
||||||
|
if step_code == 0:
|
||||||
|
direction = "up" if control else "down"
|
||||||
|
if port.entity_id in self._light_dimming_tasks:
|
||||||
|
self._stop_light_dimming(port.entity_id)
|
||||||
|
return
|
||||||
|
self._start_light_dimming(
|
||||||
|
port.entity_id, direction, 1
|
||||||
|
)
|
||||||
|
return
|
||||||
|
value = _extract_dimming_value(event)
|
||||||
if value is None:
|
if value is None:
|
||||||
return
|
return
|
||||||
if value in (0, 8):
|
if value in (0, 8):
|
||||||
@@ -1188,7 +1200,19 @@ class BridgeManager:
|
|||||||
return
|
return
|
||||||
|
|
||||||
if action == "relative_color_temperature":
|
if action == "relative_color_temperature":
|
||||||
value = _extract_event_value(event)
|
dim_info = _extract_dimming_info(event)
|
||||||
|
if dim_info is not None:
|
||||||
|
control, step_code = dim_info
|
||||||
|
if step_code == 0:
|
||||||
|
direction = "up" if control else "down"
|
||||||
|
if port.entity_id in self._light_ct_tasks:
|
||||||
|
self._stop_light_ct_adjust(port.entity_id)
|
||||||
|
return
|
||||||
|
self._start_light_ct_adjust(
|
||||||
|
port, direction, 1
|
||||||
|
)
|
||||||
|
return
|
||||||
|
value = _extract_dimming_value(event)
|
||||||
if value is None:
|
if value is None:
|
||||||
return
|
return
|
||||||
if value in (0, 8):
|
if value in (0, 8):
|
||||||
@@ -1448,6 +1472,21 @@ class BridgeManager:
|
|||||||
_runner()
|
_runner()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def _apply_light_dimming_step(
|
||||||
|
self, entity_id: str, direction: str, step_code: int
|
||||||
|
) -> None:
|
||||||
|
percent = _relative_dimming_percent(step_code)
|
||||||
|
if percent is None or percent <= 0:
|
||||||
|
return
|
||||||
|
|
||||||
|
async def _runner() -> None:
|
||||||
|
step = percent if direction == "up" else -percent
|
||||||
|
await self._call_light_service(
|
||||||
|
entity_id, "turn_on", {"brightness_step_pct": step}
|
||||||
|
)
|
||||||
|
|
||||||
|
self.hass.async_create_task(_runner())
|
||||||
|
|
||||||
def _stop_light_dimming(self, entity_id: str) -> None:
|
def _stop_light_dimming(self, entity_id: str) -> None:
|
||||||
task = self._light_dimming_tasks.pop(entity_id, None)
|
task = self._light_dimming_tasks.pop(entity_id, None)
|
||||||
if task is not None:
|
if task is not None:
|
||||||
@@ -1485,6 +1524,36 @@ class BridgeManager:
|
|||||||
_runner()
|
_runner()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def _apply_light_ct_step_once(
|
||||||
|
self, port: LightPort, direction: str, step_code: int
|
||||||
|
) -> None:
|
||||||
|
percent = _relative_dimming_percent(step_code)
|
||||||
|
if percent is None or percent <= 0:
|
||||||
|
return
|
||||||
|
|
||||||
|
async def _runner() -> None:
|
||||||
|
current_kelvin = _current_color_temp_kelvin(self.hass, port)
|
||||||
|
if current_kelvin is None:
|
||||||
|
current_kelvin = _light_min_kelvin(port)
|
||||||
|
delta = (_light_max_kelvin(port) - _light_min_kelvin(port)) * (
|
||||||
|
percent / 100
|
||||||
|
)
|
||||||
|
if direction == "up":
|
||||||
|
next_kelvin = current_kelvin + delta
|
||||||
|
else:
|
||||||
|
next_kelvin = current_kelvin - delta
|
||||||
|
next_kelvin = min(
|
||||||
|
max(next_kelvin, _light_min_kelvin(port)),
|
||||||
|
_light_max_kelvin(port),
|
||||||
|
)
|
||||||
|
await self._call_light_service(
|
||||||
|
port.entity_id,
|
||||||
|
"turn_on",
|
||||||
|
{"color_temp": _kelvin_to_mireds(next_kelvin)},
|
||||||
|
)
|
||||||
|
|
||||||
|
self.hass.async_create_task(_runner())
|
||||||
|
|
||||||
def _stop_light_ct_adjust(self, entity_id: str) -> None:
|
def _stop_light_ct_adjust(self, entity_id: str) -> None:
|
||||||
task = self._light_ct_tasks.pop(entity_id, None)
|
task = self._light_ct_tasks.pop(entity_id, None)
|
||||||
if task is not None:
|
if task is not None:
|
||||||
@@ -1511,6 +1580,42 @@ def _extract_event_value(event: Event) -> int | None:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def _extract_dimming_value(event: Event) -> int | None:
|
||||||
|
info = _extract_dimming_info(event)
|
||||||
|
if info is not None:
|
||||||
|
control, step_code = info
|
||||||
|
return ((1 if control else 0) << 3) | (step_code & 0x07)
|
||||||
|
return _extract_event_value(event)
|
||||||
|
|
||||||
|
|
||||||
|
def _extract_dimming_info(event: Event) -> tuple[bool, int] | None:
|
||||||
|
if "value" in event.data:
|
||||||
|
value = event.data["value"]
|
||||||
|
if isinstance(value, dict):
|
||||||
|
control = value.get("control")
|
||||||
|
step = value.get("stepcode", value.get("step_code"))
|
||||||
|
if control is not None and step is not None:
|
||||||
|
try:
|
||||||
|
return bool(int(control)), int(step) & 0x07
|
||||||
|
except (TypeError, ValueError):
|
||||||
|
return None
|
||||||
|
if isinstance(value, (int, float)):
|
||||||
|
raw = int(value)
|
||||||
|
return bool(raw & 0x08), raw & 0x07
|
||||||
|
if isinstance(value, (list, tuple)) and len(value) >= 2:
|
||||||
|
try:
|
||||||
|
return bool(int(value[0])), int(value[1]) & 0x07
|
||||||
|
except (TypeError, ValueError):
|
||||||
|
return None
|
||||||
|
data = event.data.get("data")
|
||||||
|
if isinstance(data, (list, tuple)) and len(data) >= 2:
|
||||||
|
try:
|
||||||
|
return bool(int(data[0])), int(data[1]) & 0x07
|
||||||
|
except (TypeError, ValueError):
|
||||||
|
return None
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def _clean_address(address: Any) -> str | None:
|
def _clean_address(address: Any) -> str | None:
|
||||||
if not address:
|
if not address:
|
||||||
return None
|
return None
|
||||||
@@ -1803,6 +1908,24 @@ def _relative_dimming_step(value: int) -> tuple[str, int] | None:
|
|||||||
return direction, percent
|
return direction, percent
|
||||||
|
|
||||||
|
|
||||||
|
def _relative_dimming_percent(step_code: int) -> int | None:
|
||||||
|
percent_map = {
|
||||||
|
1: 10,
|
||||||
|
2: 8,
|
||||||
|
3: 6,
|
||||||
|
4: 4,
|
||||||
|
5: 3,
|
||||||
|
6: 2,
|
||||||
|
7: 1,
|
||||||
|
}
|
||||||
|
step = int(step_code)
|
||||||
|
if step <= 0:
|
||||||
|
step = 1
|
||||||
|
if step > 7:
|
||||||
|
step = 7
|
||||||
|
return percent_map.get(step)
|
||||||
|
|
||||||
|
|
||||||
def _map_scalar_value(value: Any) -> int | None:
|
def _map_scalar_value(value: Any) -> int | None:
|
||||||
if isinstance(value, bool):
|
if isinstance(value, bool):
|
||||||
return 1 if value else 0
|
return 1 if value else 0
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"domain": "ha_knx_bridge",
|
"domain": "ha_knx_bridge",
|
||||||
"name": "HA KNX Bridge",
|
"name": "HA KNX Bridge",
|
||||||
"version": "0.0.29",
|
"version": "0.0.32",
|
||||||
"config_flow": true,
|
"config_flow": true,
|
||||||
"documentation": "https://github.com/bahmcloud/HA-KNX-Bridge",
|
"documentation": "https://github.com/bahmcloud/HA-KNX-Bridge",
|
||||||
"issue_tracker": "https://github.com/bahmcloud/HA-KNX-Bridge/issues",
|
"issue_tracker": "https://github.com/bahmcloud/HA-KNX-Bridge/issues",
|
||||||
|
|||||||
Reference in New Issue
Block a user