diff --git a/src/components/entity/ha-entity-attribute-picker.ts b/src/components/entity/ha-entity-attribute-picker.ts index d47fda3ffd..c79386d355 100644 --- a/src/components/entity/ha-entity-attribute-picker.ts +++ b/src/components/entity/ha-entity-attribute-picker.ts @@ -15,6 +15,14 @@ class HaEntityAttributePicker extends LitElement { @property() public entityId?: string; + /** + * List of attributes to be excluded. + * @type {Array} + * @attr exclude-attributes + */ + @property({ type: Array, attribute: "exclude-attributes" }) + public excludeAttributes?: string[]; + @property({ type: Boolean }) public autofocus = false; @property({ type: Boolean }) public disabled = false; @@ -42,10 +50,12 @@ class HaEntityAttributePicker extends LitElement { if (changedProps.has("_opened") && this._opened) { const state = this.entityId ? this.hass.states[this.entityId] : undefined; (this._comboBox as any).items = state - ? Object.keys(state.attributes).map((key) => ({ - value: key, - label: formatAttributeName(key), - })) + ? Object.keys(state.attributes) + .filter((key) => !this.excludeAttributes?.includes(key)) + .map((key) => ({ + value: key, + label: formatAttributeName(key), + })) : []; } } diff --git a/src/components/ha-selector/ha-selector-attribute.ts b/src/components/ha-selector/ha-selector-attribute.ts index 4d00fa8f9c..af66b97515 100644 --- a/src/components/ha-selector/ha-selector-attribute.ts +++ b/src/components/ha-selector/ha-selector-attribute.ts @@ -8,9 +8,9 @@ import "../entity/ha-entity-attribute-picker"; @customElement("ha-selector-attribute") export class HaSelectorAttribute extends SubscribeMixin(LitElement) { - @property() public hass!: HomeAssistant; + @property({ attribute: false }) public hass!: HomeAssistant; - @property() public selector!: AttributeSelector; + @property({ attribute: false }) public selector!: AttributeSelector; @property() public value?: any; @@ -22,7 +22,7 @@ export class HaSelectorAttribute extends SubscribeMixin(LitElement) { @property({ type: Boolean }) public required = true; - @property() public context?: { + @property({ attribute: false }) public context?: { filter_entity?: string; }; @@ -32,6 +32,7 @@ export class HaSelectorAttribute extends SubscribeMixin(LitElement) { .hass=${this.hass} .entityId=${this.selector.attribute.entity_id || this.context?.filter_entity} + .excludeAttributes=${this.selector.attribute.exclude_attributes} .value=${this.value} .label=${this.label} .helper=${this.helper} diff --git a/src/data/selector.ts b/src/data/selector.ts index 7514c0fd1b..affeeb4bd9 100644 --- a/src/data/selector.ts +++ b/src/data/selector.ts @@ -65,6 +65,7 @@ export interface AreaSelector { export interface AttributeSelector { attribute: { entity_id?: string; + exclude_attributes?: readonly string[]; }; } diff --git a/src/panels/config/automation/condition/types/ha-automation-condition-numeric_state.ts b/src/panels/config/automation/condition/types/ha-automation-condition-numeric_state.ts index 47b1c9919b..73974c5a15 100644 --- a/src/panels/config/automation/condition/types/ha-automation-condition-numeric_state.ts +++ b/src/panels/config/automation/condition/types/ha-automation-condition-numeric_state.ts @@ -1,11 +1,11 @@ -import "../../../../../components/ha-form/ha-form"; import { html, LitElement } from "lit"; import { customElement, property } from "lit/decorators"; import memoizeOne from "memoize-one"; import { fireEvent } from "../../../../../common/dom/fire_event"; +import "../../../../../components/ha-form/ha-form"; +import type { SchemaUnion } from "../../../../../components/ha-form/types"; import { NumericStateCondition } from "../../../../../data/automation"; import type { HomeAssistant } from "../../../../../types"; -import type { SchemaUnion } from "../../../../../components/ha-form/types"; @customElement("ha-automation-condition-numeric_state") export default class HaNumericStateCondition extends LitElement { @@ -25,7 +25,75 @@ export default class HaNumericStateCondition extends LitElement { { name: "entity_id", required: true, selector: { entity: {} } }, { name: "attribute", - selector: { attribute: { entity_id: entityId } }, + selector: { + attribute: { + entity_id: entityId, + exclude_attributes: [ + "access_token", + "auto_update", + "available_modes", + "away_mode", + "changed_by", + "code_format", + "color_modes", + "current_activity", + "device_class", + "editable", + "effect_list", + "effect", + "entity_picture", + "fan_mode", + "fan_modes", + "fan_speed_list", + "forecast", + "friendly_name", + "frontend_stream_type", + "has_date", + "has_time", + "hs_color", + "hvac_mode", + "hvac_modes", + "icon", + "media_album_name", + "media_artist", + "media_content_type", + "media_position_updated_at", + "media_title", + "next_dawn", + "next_dusk", + "next_midnight", + "next_noon", + "next_rising", + "next_setting", + "operation_list", + "operation_mode", + "options", + "preset_mode", + "preset_modes", + "release_notes", + "release_summary", + "release_url", + "restored", + "rgb_color", + "rgbw_color", + "shuffle", + "sound_mode_list", + "sound_mode", + "source_list", + "source_type", + "source", + "state_class", + "supported_features", + "swing_mode", + "swing_mode", + "swing_modes", + "title", + "token", + "unit_of_measurement", + "xy_color", + ], + }, + }, }, { name: "above", selector: { text: {} } }, { name: "below", selector: { text: {} } }, diff --git a/src/panels/config/automation/condition/types/ha-automation-condition-state.ts b/src/panels/config/automation/condition/types/ha-automation-condition-state.ts index 0a72d74a86..fd4998893a 100644 --- a/src/panels/config/automation/condition/types/ha-automation-condition-state.ts +++ b/src/panels/config/automation/condition/types/ha-automation-condition-state.ts @@ -4,12 +4,12 @@ import memoizeOne from "memoize-one"; import { assert, literal, object, optional, string, union } from "superstruct"; import { createDurationData } from "../../../../../common/datetime/create_duration_data"; import { fireEvent } from "../../../../../common/dom/fire_event"; +import "../../../../../components/ha-form/ha-form"; +import type { SchemaUnion } from "../../../../../components/ha-form/types"; import type { StateCondition } from "../../../../../data/automation"; import type { HomeAssistant } from "../../../../../types"; import { forDictStruct } from "../../structs"; import type { ConditionElement } from "../ha-automation-condition-row"; -import "../../../../../components/ha-form/ha-form"; -import type { SchemaUnion } from "../../../../../components/ha-form/types"; const stateConditionStruct = object({ condition: literal("state"), @@ -35,7 +35,33 @@ export class HaStateCondition extends LitElement implements ConditionElement { { name: "entity_id", required: true, selector: { entity: {} } }, { name: "attribute", - selector: { attribute: { entity_id: entityId } }, + selector: { + attribute: { + entity_id: entityId, + exclude_attributes: [ + "access_token", + "available_modes", + "color_modes", + "editable", + "effect_list", + "entity_picture", + "fan_modes", + "fan_speed_list", + "forecast", + "friendly_name", + "hvac_modes", + "icon", + "operation_list", + "options", + "preset_modes", + "sound_mode_list", + "source_list", + "state_class", + "swing_modes", + "token", + ], + }, + }, }, { name: "state", diff --git a/src/panels/config/automation/trigger/types/ha-automation-trigger-numeric_state.ts b/src/panels/config/automation/trigger/types/ha-automation-trigger-numeric_state.ts index 88be9564a5..763fca4bc3 100644 --- a/src/panels/config/automation/trigger/types/ha-automation-trigger-numeric_state.ts +++ b/src/panels/config/automation/trigger/types/ha-automation-trigger-numeric_state.ts @@ -1,13 +1,13 @@ -import "../../../../../components/ha-form/ha-form"; import { html, LitElement, PropertyValues } from "lit"; import { customElement, property } from "lit/decorators"; import memoizeOne from "memoize-one"; import { createDurationData } from "../../../../../common/datetime/create_duration_data"; import { fireEvent } from "../../../../../common/dom/fire_event"; import { hasTemplate } from "../../../../../common/string/has-template"; +import "../../../../../components/ha-form/ha-form"; +import type { SchemaUnion } from "../../../../../components/ha-form/types"; import type { NumericStateTrigger } from "../../../../../data/automation"; import type { HomeAssistant } from "../../../../../types"; -import type { SchemaUnion } from "../../../../../components/ha-form/types"; @customElement("ha-automation-trigger-numeric_state") export class HaNumericStateTrigger extends LitElement { @@ -21,7 +21,75 @@ export class HaNumericStateTrigger extends LitElement { { name: "entity_id", required: true, selector: { entity: {} } }, { name: "attribute", - selector: { attribute: { entity_id: entityId } }, + selector: { + attribute: { + entity_id: entityId, + exclude_attributes: [ + "access_token", + "auto_update", + "available_modes", + "away_mode", + "changed_by", + "code_format", + "color_modes", + "current_activity", + "device_class", + "editable", + "effect_list", + "effect", + "entity_picture", + "fan_mode", + "fan_modes", + "fan_speed_list", + "forecast", + "friendly_name", + "frontend_stream_type", + "has_date", + "has_time", + "hs_color", + "hvac_mode", + "hvac_modes", + "icon", + "media_album_name", + "media_artist", + "media_content_type", + "media_position_updated_at", + "media_title", + "next_dawn", + "next_dusk", + "next_midnight", + "next_noon", + "next_rising", + "next_setting", + "operation_list", + "operation_mode", + "options", + "preset_mode", + "preset_modes", + "release_notes", + "release_summary", + "release_url", + "restored", + "rgb_color", + "rgbw_color", + "shuffle", + "sound_mode_list", + "sound_mode", + "source_list", + "source_type", + "source", + "state_class", + "supported_features", + "swing_mode", + "swing_mode", + "swing_modes", + "title", + "token", + "unit_of_measurement", + "xy_color", + ], + }, + }, }, { name: "above", selector: { text: {} } }, { name: "below", selector: { text: {} } }, diff --git a/src/panels/config/automation/trigger/types/ha-automation-trigger-state.ts b/src/panels/config/automation/trigger/types/ha-automation-trigger-state.ts index 9405a76f75..dcd0daafc3 100644 --- a/src/panels/config/automation/trigger/types/ha-automation-trigger-state.ts +++ b/src/panels/config/automation/trigger/types/ha-automation-trigger-state.ts @@ -55,7 +55,35 @@ export class HaStateTrigger extends LitElement implements TriggerElement { { name: "attribute", selector: { - attribute: { entity_id: entityId ? entityId[0] : undefined }, + attribute: { + entity_id: entityId ? entityId[0] : undefined, + exclude_attributes: [ + "access_token", + "available_modes", + "color_modes", + "device_class", + "editable", + "effect_list", + "entity_picture", + "fan_modes", + "fan_speed_list", + "friendly_name", + "has_date", + "has_time", + "hvac_modes", + "icon", + "operation_list", + "options", + "preset_modes", + "sound_mode_list", + "source_list", + "state_class", + "supported_features", + "swing_modes", + "token", + "unit_of_measurement", + ], + }, }, }, {