Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/_docs/03-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ The following types of items can be used as subjects within a rule.

The special case `entity: '*'` represents all HA entities. It can be used in rules that need to run whenever the state of any HA entity changes.

Wildcards (*) can also be used to match subsets of entities, for example `light.*`, `sensor.*_temperature`.

### Action Triggers

Floorplan supports the same action triggers used in [Lovelace](https://www.home-assistant.io/lovelace/actions) (`tap_action`, `hold_action`, `double_tap_action`). In addition to these, Floorplan adds two of its own action triggers.
Expand Down
24 changes: 23 additions & 1 deletion src/components/floorplan/floorplan-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1207,7 +1207,25 @@ export class FloorplanElement extends LitElement {
// Do not add target entity "*"
if (entityId && entityId === "*") continue;

this.addTargetEntity(entityId, elementIds, targetEntities);
// support wildcard entityId
if (entityId.includes('*')) {
const regex = wildcardsToRegex(entityId);
let foundAny = false;
for (const hassEntityId of Object.keys(this.hass.states)) {
if (regex.test(hassEntityId)) {
this.addTargetEntity(hassEntityId, [hassEntityId], targetEntities);
foundAny = true;
}
}
if (!foundAny) {
this.logWarning(
'CONFIG',
`Cannot find entities matching '${entityId}' in Home Assistant`
);
}
} else {
this.addTargetEntity(entityId, elementIds, targetEntities);
}
}

// Entities as a list of objects
Expand All @@ -1223,6 +1241,10 @@ export class FloorplanElement extends LitElement {
}

return targetEntities;

function wildcardsToRegex(entityId: string) {
return new RegExp('^' + entityId.replace(/[.+^${}()|[\]\\]/g, '\\$&').replace(/\*/g, '.*') + '$');
}
}

addTargetEntity(
Expand Down