@@ -11406,24 +11406,56 @@ class FastSearchCard extends HTMLElement {
1140611406
1140711407 }
1140811408
11409- // 🎯 FIND RELATED SCENES
11409+ // 🎯 FIND RELATED SCENES - Erweiterte Metadaten-Analyse
1141011410 findRelatedScenes(deviceId, deviceArea) {
1141111411 if (!this._hass || !this.allItems) return [];
1141211412
11413+ // Device-ID und Area-ID des Ziel-Devices ermitteln
11414+ const targetDeviceId = this.getDeviceId(deviceId);
11415+ const targetAreaId = this.getAreaId(deviceId, deviceArea);
11416+
11417+ console.log(`🔍 Target Device ID: ${targetDeviceId}, Area ID: ${targetAreaId}`);
11418+
1141311419 return this.allItems.filter(item => {
1141411420 if (item.domain !== 'scene') return false;
1141511421
11416- // METHODE 1: Direkte Entity-Analyse
1141711422 const state = this._hass.states[item.id];
11418- if (state && state.attributes.entity_id) {
11423+ if (!state) return false;
11424+
11425+ // METHODE 1: Direkte Entity-Analyse (bestehend)
11426+ if (state.attributes.entity_id) {
1141911427 const targetEntities = state.attributes.entity_id;
1142011428 if (targetEntities.includes(deviceId)) {
1142111429 console.log(`✅ Scene ${item.name} targets device directly`);
11422- return true; // Szene betrifft dieses Gerät direkt
11430+ return true;
11431+ }
11432+ }
11433+
11434+ // 🆕 METHODE 2: Device-ID Matching
11435+ if (targetDeviceId && state.attributes.entity_id) {
11436+ const sceneEntityIds = state.attributes.entity_id;
11437+ for (const entityId of sceneEntityIds) {
11438+ const entityDeviceId = this.getDeviceId(entityId);
11439+ if (entityDeviceId === targetDeviceId) {
11440+ console.log(`✅ Scene ${item.name} targets same device via different entity`);
11441+ return true;
11442+ }
11443+ }
11444+ }
11445+
11446+ // 🆕 METHODE 3: Area-ID Matching via alle Entities in der Area
11447+ if (targetAreaId && state.attributes.entity_id) {
11448+ const sceneEntityIds = state.attributes.entity_id;
11449+ for (const entityId of sceneEntityIds) {
11450+ const entityAreaId = this.getAreaId(entityId);
11451+ if (entityAreaId === targetAreaId) {
11452+ console.log(`✅ Scene ${item.name} affects same area: ${targetAreaId}`);
11453+ return true;
11454+ }
1142311455 }
1142411456 }
1142511457
11426- // METHODE 2 : Gleiche Area
11458+ // METHODE 4 : Gleiche Area (bestehend)
1142711459 if (item.area === deviceArea && deviceArea !== 'Ohne Raum') {
1142811460 console.log(`✅ Scene ${item.name} in same area: ${deviceArea}`);
1142911461 return true;
@@ -11432,6 +11464,34 @@ class FastSearchCard extends HTMLElement {
1143211464 return false;
1143311465 });
1143411466 }
11467+
11468+ // 🔧 Helper: Get Device ID for Entity
11469+ getDeviceId(entityId) {
11470+ if (!this._hass.entities || !this._hass.entities[entityId]) return null;
11471+ return this._hass.entities[entityId].device_id || null;
11472+ }
11473+
11474+ // 🔧 Helper: Get Area ID for Entity
11475+ getAreaId(entityId, fallbackAreaName = null) {
11476+ // Direkt von Entity
11477+ const entityRegistry = this._hass.entities?.[entityId];
11478+ if (entityRegistry?.area_id) return entityRegistry.area_id;
11479+
11480+ // Via Device
11481+ const deviceId = this.getDeviceId(entityId);
11482+ if (deviceId && this._hass.devices?.[deviceId]?.area_id) {
11483+ return this._hass.devices[deviceId].area_id;
11484+ }
11485+
11486+ // Fallback: Area-Name zu Area-ID konvertieren
11487+ if (fallbackAreaName && this._hass.areas) {
11488+ const area = Object.values(this._hass.areas).find(a => a.name === fallbackAreaName);
11489+ return area?.area_id || null;
11490+ }
11491+
11492+ return null;
11493+ }
11494+
1143511495
1143611496 // 🎯 FIND RELATED SCRIPTS
1143711497 findRelatedScripts(deviceId, deviceArea) {
0 commit comments