diff --git a/src/panels/lovelace/elements/hui-state-label-element.ts b/src/panels/lovelace/elements/hui-state-label-element.ts index bd8ad45616..93aa196d33 100644 --- a/src/panels/lovelace/elements/hui-state-label-element.ts +++ b/src/panels/lovelace/elements/hui-state-label-element.ts @@ -58,6 +58,23 @@ class HuiStateLabelElement extends LitElement implements LovelaceElement { `; } + if ( + this._config.attribute && + !stateObj.attributes[this._config.attribute] + ) { + return html` + + `; + } + return html`
- ${this._config.prefix}${stateObj + ${this._config.prefix}${!this._config.attribute ? computeStateDisplay( this.hass.localize, stateObj, this.hass.language ) - : "-"}${this._config.suffix} + : stateObj.attributes[this._config.attribute]}${this._config.suffix}
`; } diff --git a/src/panels/lovelace/elements/types.ts b/src/panels/lovelace/elements/types.ts index e42f689e31..08ca175fa7 100644 --- a/src/panels/lovelace/elements/types.ts +++ b/src/panels/lovelace/elements/types.ts @@ -64,6 +64,7 @@ export interface StateIconElementConfig extends LovelaceElementConfig { export interface StateLabelElementConfig extends LovelaceElementConfig { entity: string; + attribute?: string; prefix?: string; suffix?: string; tap_action?: ActionConfig; diff --git a/src/translations/en.json b/src/translations/en.json index c2824ff6b5..f845e511a0 100755 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -2128,6 +2128,7 @@ } }, "warning": { + "attribute_not_found": "Attribute {attribute} not available in: {entity}", "entity_not_found": "Entity not available: {entity}", "entity_non_numeric": "Entity is non-numeric: {entity}" },