diff --git a/README.md b/README.md index 753d4081..30addab0 100644 --- a/README.md +++ b/README.md @@ -124,7 +124,7 @@ Here is what every option means: ### `stats` object -You can use any attribute of vacuum or even any entity by `entity_id` to display by stats section: +You can use any attribute of vacuum or even any entity by `entity_id` to display by stats section. You can also combine `attribute` with `entity_id` to extract an attribute value of specific entity: | Name | Type | Default | Description | | ---------------- | :------: | -------- | ---------------------------------------------------------------------------------------------------- | diff --git a/src/vacuum-card.ts b/src/vacuum-card.ts index 2838170b..9efe206a 100755 --- a/src/vacuum-card.ts +++ b/src/vacuum-card.ts @@ -267,9 +267,17 @@ export class VacuumCard extends LitElement { return nothing; } - const state = entity_id - ? this.hass.states[entity_id].state - : get(this.entity.attributes, attribute ?? ''); + let state = ''; + + if (entity_id && attribute) { + state = get(this.hass.states[entity_id].attributes, attribute); + } else if (attribute) { + state = get(this.entity.attributes, attribute); + } else if (entity_id) { + state = this.hass.states[entity_id].state; + } else { + return nothing; + } const value = html`