diff --git a/src/data/device_automation.ts b/src/data/device_automation.ts index e64300a5aa..9bc011a591 100644 --- a/src/data/device_automation.ts +++ b/src/data/device_automation.ts @@ -167,10 +167,18 @@ const compareEntityIdWithEntityRegId = ( return false; } if (entityIdA.includes(".")) { - entityIdA = entityRegistryByEntityId(entityRegistry)[entityIdA].id; + const entityA = entityRegistryByEntityId(entityRegistry)[entityIdA]; + if (!entityA) { + return false; + } + entityIdA = entityA.id; } if (entityIdB.includes(".")) { - entityIdB = entityRegistryByEntityId(entityRegistry)[entityIdB].id; + const entityB = entityRegistryByEntityId(entityRegistry)[entityIdB]; + if (!entityB) { + return false; + } + entityIdB = entityB.id; } return entityIdA === entityIdB; };