mirror of
https://github.com/bahmcloud/HA-KNX-Bridge.git
synced 2026-04-06 16:51:14 +00:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 221454d5e8 | |||
| 69267f7c0f | |||
| 91f51cb414 | |||
| 1eb283112c | |||
| 60b436f79f |
10
.idea/PROJECT_STATE.md
generated
10
.idea/PROJECT_STATE.md
generated
@@ -10,7 +10,7 @@ The integration should:
|
||||
- Auto-select appropriate KNX DPTs and request only the group addresses needed.
|
||||
- Ignore missing/empty group addresses without errors.
|
||||
|
||||
Target compatibility: Home Assistant 2025.12 with forward compatibility to 2026.2.
|
||||
Target compatibility: Home Assistant 2025.12 with forward compatibility to 2026.03.
|
||||
|
||||
Project rules:
|
||||
- Keep `README.md` updated for user-relevant changes after each new version.
|
||||
@@ -18,7 +18,7 @@ Project rules:
|
||||
- Releases are created only when explicitly requested.
|
||||
- Version number must match everywhere it is referenced (manifest, changelog, README, HACS if used).
|
||||
|
||||
## Current State (as of 2026-02-15)
|
||||
## Current State (as of 2026-03-09)
|
||||
Completed:
|
||||
- Repo initialized with `main` branch and pushed to GitHub.
|
||||
- HACS metadata (`hacs.json`) and base integration scaffold created.
|
||||
@@ -46,7 +46,11 @@ Completed:
|
||||
- Relative dimming now repeats steps until a stop telegram is received.
|
||||
- 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.
|
||||
- Project version set to 0.0.28 and `CHANGELOG.md` maintained.
|
||||
- Color temperature service calls now use mireds for better compatibility.
|
||||
- Relative dimming/color temperature decoding improved for control/stepcode payloads.
|
||||
- Relative dimming/CT now parse control strings from DPT 3.007 payloads and treat raw step values as percent steps (0/8 stop).
|
||||
- Home Assistant 2026.03 compatibility fix: graceful fallback for removed `ATTR_COLOR_TEMP` import and color temperature service calls now use Kelvin.
|
||||
- Project version set to 0.0.34 and `CHANGELOG.md` maintained.
|
||||
|
||||
Files created:
|
||||
- `custom_components/ha_knx_bridge/__init__.py`
|
||||
|
||||
19
CHANGELOG.md
19
CHANGELOG.md
@@ -1,5 +1,24 @@
|
||||
# Changelog
|
||||
|
||||
## 0.0.34 - 2026-03-09
|
||||
- Fix startup on Home Assistant 2026.03 by handling removed `ATTR_COLOR_TEMP` imports.
|
||||
- Switch light color temperature service calls to `color_temp_kelvin`.
|
||||
|
||||
## 0.0.33 - 2026-02-15
|
||||
- Parse control strings from DPT 3.007 payloads and use raw step values as percent steps (0/8 stop).
|
||||
|
||||
## 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
|
||||
- Use mired-based HA color temperature service calls for better device compatibility.
|
||||
|
||||
## 0.0.28 - 2026-02-15
|
||||
- Add relative color temperature control (DPT 3.007), reorder relative dimming field in UI, and align color temperature KNX types.
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ Current minimal scope:
|
||||
- Light port (KNX -> HA commands, HA state -> KNX)
|
||||
|
||||
## Requirements
|
||||
- Home Assistant 2025.12 or newer (tested for compatibility with 2026.2).
|
||||
- Home Assistant 2025.12 or newer (tested for compatibility with 2026.03).
|
||||
- The built-in KNX integration must be set up and running.
|
||||
|
||||
## Install (HACS)
|
||||
@@ -74,10 +74,11 @@ Only state addresses expose an `invert outgoing` toggle to flip KNX payloads.
|
||||
|
||||
Notes:
|
||||
- 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.
|
||||
- Relative color temperature (DPT 3.007) adjusts Kelvin in the same start/stop pattern.
|
||||
- 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).
|
||||
- Step values `1..7` dim down, `9..15` dim up, and `0/8` stop; the bridge uses the raw step value as the percent step size.
|
||||
- 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_kelvin`.
|
||||
|
||||
## Notes
|
||||
- For DPT 1.008 (Up/Down), the bridge treats `0 = Up/Open` and `1 = Down/Close`.
|
||||
@@ -112,5 +113,5 @@ Notes:
|
||||
- Advanced DPT mapping options and inversion settings.
|
||||
|
||||
## Versioning and Releases
|
||||
- Current version: 0.0.28
|
||||
- Current version: 0.0.34
|
||||
- `CHANGELOG.md` lists versions with the newest entries at the top.
|
||||
|
||||
@@ -8,7 +8,6 @@ from typing import Any
|
||||
from homeassistant.components.light import (
|
||||
ATTR_BRIGHTNESS,
|
||||
ATTR_COLOR_MODE,
|
||||
ATTR_COLOR_TEMP,
|
||||
ATTR_HS_COLOR,
|
||||
ATTR_RGB_COLOR,
|
||||
ATTR_RGBW_COLOR,
|
||||
@@ -79,6 +78,11 @@ _LOGGER = logging.getLogger(__name__)
|
||||
|
||||
KNX_DOMAIN = "knx"
|
||||
|
||||
try:
|
||||
from homeassistant.components.light import ATTR_COLOR_TEMP
|
||||
except ImportError: # pragma: no cover - fallback for newer HA
|
||||
ATTR_COLOR_TEMP = "color_temp"
|
||||
|
||||
try:
|
||||
from homeassistant.components.light import ATTR_COLOR_TEMP_KELVIN
|
||||
except ImportError: # pragma: no cover - fallback for older HA
|
||||
@@ -678,13 +682,13 @@ class BridgeManager:
|
||||
)
|
||||
self._register_knx_light_command(
|
||||
port.relative_color_temperature_address,
|
||||
None,
|
||||
"control_dimming",
|
||||
port,
|
||||
"relative_color_temperature",
|
||||
)
|
||||
self._register_knx_light_command(
|
||||
port.relative_dimming_address,
|
||||
None,
|
||||
"control_dimming",
|
||||
port,
|
||||
"relative_dimming",
|
||||
)
|
||||
@@ -1172,7 +1176,13 @@ class BridgeManager:
|
||||
return
|
||||
|
||||
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:
|
||||
self._stop_light_dimming(port.entity_id)
|
||||
return
|
||||
value = _extract_dimming_value(event)
|
||||
if value is None:
|
||||
return
|
||||
if value in (0, 8):
|
||||
@@ -1188,7 +1198,13 @@ class BridgeManager:
|
||||
return
|
||||
|
||||
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:
|
||||
self._stop_light_ct_adjust(port.entity_id)
|
||||
return
|
||||
value = _extract_dimming_value(event)
|
||||
if value is None:
|
||||
return
|
||||
if value in (0, 8):
|
||||
@@ -1448,6 +1464,21 @@ class BridgeManager:
|
||||
_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:
|
||||
task = self._light_dimming_tasks.pop(entity_id, None)
|
||||
if task is not None:
|
||||
@@ -1485,6 +1516,36 @@ class BridgeManager:
|
||||
_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",
|
||||
{ATTR_COLOR_TEMP_KELVIN: int(round(next_kelvin))},
|
||||
)
|
||||
|
||||
self.hass.async_create_task(_runner())
|
||||
|
||||
def _stop_light_ct_adjust(self, entity_id: str) -> None:
|
||||
task = self._light_ct_tasks.pop(entity_id, None)
|
||||
if task is not None:
|
||||
@@ -1511,6 +1572,59 @@ def _extract_event_value(event: Event) -> int | 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:
|
||||
control_bit = _parse_control_value(control)
|
||||
if control_bit is None:
|
||||
return None
|
||||
try:
|
||||
return control_bit, 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 _parse_control_value(value: Any) -> bool | None:
|
||||
if isinstance(value, bool):
|
||||
return value
|
||||
if isinstance(value, (int, float)):
|
||||
return bool(int(value))
|
||||
if isinstance(value, str):
|
||||
text = value.strip().lower()
|
||||
if text in ("increase", "up", "raise", "1", "true", "on"):
|
||||
return True
|
||||
if text in ("decrease", "down", "lower", "0", "false", "off"):
|
||||
return False
|
||||
return None
|
||||
|
||||
|
||||
def _clean_address(address: Any) -> str | None:
|
||||
if not address:
|
||||
return None
|
||||
@@ -1587,12 +1701,6 @@ def _percent_to_brightness(percent: int) -> int:
|
||||
return int(round(percent / 100 * 255))
|
||||
|
||||
|
||||
def _kelvin_to_mireds(kelvin: float) -> int:
|
||||
if kelvin <= 0:
|
||||
return 0
|
||||
return int(round(1000000 / kelvin))
|
||||
|
||||
|
||||
def _mireds_to_kelvin(mireds: float) -> float:
|
||||
if mireds <= 0:
|
||||
return 0
|
||||
@@ -1784,10 +1892,16 @@ def _relative_dimming_step(value: int) -> tuple[str, int] | None:
|
||||
return None
|
||||
if value <= 7:
|
||||
direction = "down"
|
||||
step = value
|
||||
percent = value
|
||||
else:
|
||||
direction = "up"
|
||||
step = value - 8
|
||||
percent = value
|
||||
if percent <= 0:
|
||||
return None
|
||||
return direction, percent
|
||||
|
||||
|
||||
def _relative_dimming_percent(step_code: int) -> int | None:
|
||||
percent_map = {
|
||||
1: 10,
|
||||
2: 8,
|
||||
@@ -1797,10 +1911,12 @@ def _relative_dimming_step(value: int) -> tuple[str, int] | None:
|
||||
6: 2,
|
||||
7: 1,
|
||||
}
|
||||
percent = percent_map.get(step)
|
||||
if percent is None:
|
||||
return None
|
||||
return direction, percent
|
||||
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:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"domain": "ha_knx_bridge",
|
||||
"name": "HA KNX Bridge",
|
||||
"version": "0.0.28",
|
||||
"version": "0.0.34",
|
||||
"config_flow": true,
|
||||
"documentation": "https://github.com/bahmcloud/HA-KNX-Bridge",
|
||||
"issue_tracker": "https://github.com/bahmcloud/HA-KNX-Bridge/issues",
|
||||
|
||||
Reference in New Issue
Block a user