Skip to content

Commit 9db6f4d

Browse files
committed
feat: support templates for disabled
1 parent 10007fc commit 9db6f4d

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ Lovelace Button card for your entities.
144144
| `variables` | object | optional | See [Variables](#Variables) |
145145
| `card_size` | number | 3 | Any number | Configure the card size seen by the auto layout feature of lovelace (lovelace will multiply the value by about 50px) |
146146
| `tooltip` | string | optional | Any string | (Not supported on touchscreens) You can configure the tooltip displayed after hovering the card for 1.5 seconds . Supports templates, see [templates](#javascript-templates) |
147+
| `disabled` | boolean | optional | `false` | Available starting from HA 2025.10. Enables or disables the card. Supports templates. |
147148

148149
### Action
149150

@@ -435,6 +436,7 @@ Those are the configuration fields which support templating:
435436
- The lock being enabled or not (`lock.enabled`)
436437
- all the `card` parameters in a `custom_field`
437438
- all the `variables`
439+
- `disabled`: should return a boolean
438440

439441
Special fields which do support templating but are **only evaluated once**, when the configuration is loaded. Error in those templates will only be visible in the javascript console and the card will not display in that case:
440442

src/button-card.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,14 @@ class ButtonCard extends LitElement {
177177
};
178178
}
179179

180+
public get disabled(): boolean {
181+
if (!this._initialSetupComplete || this._config?.disabled === undefined) {
182+
return false;
183+
} else {
184+
return this._getTemplateOrValue(this._stateObj, this._config!.disabled);
185+
}
186+
}
187+
180188
public set hass(hass: HomeAssistant) {
181189
this._hass = hass;
182190
Object.keys(this._cards).forEach((element) => {

src/types/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export interface ButtonCardConfig {
4848
tooltip?: string;
4949
section_mode?: boolean;
5050
update_timer?: number;
51+
disabled?: string | boolean;
5152
}
5253

5354
export interface GridOptions {

0 commit comments

Comments
 (0)