::after
```
--------------------------------
### Button to Set Light to White (Color Temperature)
Source: https://github.com/nerwyn/custom-card-features/blob/main/README.md
This button action calls the light.turn_on service to set the light to a specific color temperature. It features conditional styling for white elements.
```yaml
- tap_action:
action: call-service
service: light.turn_on
data:
color_temp: 500
target:
entity_id: light.chandelier
option: 255,137,14
label: White
icon: mdi:alpha-w
entity_id: light.chandelier
type: button
value_attribute: state
styles: |-
:host {
flex-basis: 200%;
--label-color: white;
--color: white;
{% if (state_attr(config.entity, "rgb_color") or []).join(',') == '255,137,14' %}
--label-filter: invert(1);
--icon-filter: invert(1);
{% endif %}
}
```
--------------------------------
### Light Tile Configuration with Multiple Features
Source: https://github.com/nerwyn/custom-card-features/blob/main/README.md
This configuration defines a light tile with various interactive features. It includes a toggle for the main light, individual buttons for bulbs, a color selector, and brightness/temperature sliders. Use this for detailed control over a light entity.
```yaml
type: tile
layout_options:
grid_columns: 4
grid_rows: 5
entity: light.chandelier
vertical: false
icon_tap_action:
action: perform-action
perform_action: light.toggle
target:
entity_id: light.chandelier
confirmation: true
features:
- type: custom:service-call
entries:
- type: toggle
tap_action:
action: perform-action
confirmation:
text: >-
Are you sure you want to turn the light {{ 'on' if checked else
'off' }}?
exemptions: []
target:
entity_id:
- light.chandelier
perform_action: light.turn_{{ 'on' if checked else 'off' }}
data: |
{% if checked %}
kelvin: 2000
{% endif %}
icon: ''
label: >-
{{ value if checked else states(config.entity) }}{{ unit if checked
else "" }}
value_attribute: brightness
unit_of_measurement: '%'
autofill_entity_id: true
entity_id: light.chandelier
styles: |-
:host {
flex-basis: 400%;
}
haptics: true
unchecked_icon: mdi:ceiling-light-outline
checked_icon: mdi:ceiling-light
- tap_action:
action: call-service
service: light.toggle
target:
entity_id: light.chandelier_bulb_1
icon: mdi:lightbulb
label: Bulb 1
entity_id: light.chandelier
type: button
value_attribute: state
styles: |-
:host {
--icon-color: orange;
}
- tap_action:
action: call-service
service: light.toggle
target:
entity_id: light.chandelier_bulb_2
icon: mdi:lightbulb
label: Bulb 2
entity_id: light.chandelier
type: button
value_attribute: state
styles: |-
:host {
--icon-color: yellow;
}
- tap_action:
action: call-service
service: light.toggle
target:
entity_id: light.chandelier_bulb_3
icon: mdi:lightbulb
label: Bulb 3
entity_id: light.chandelier
type: button
value_attribute: state
styles: |-
:host {
--icon-color: green;
}
- tap_action:
action: call-service
service: light.toggle
target:
entity_id: light.chandelier_bulb_4
icon: mdi:lightbulb
label: Bulb 4
entity_id: light.chandelier
type: button
value_attribute: state
styles: |-
:host {
--icon-color: blue;
}
- tap_action:
action: call-service
service: light.toggle
target:
entity_id: light.chandelier_bulb_5
icon: mdi:lightbulb
label: Bulb 5
entity_id: light.chandelier
type: button
value_attribute: state
styles: |-
:host {
--icon-color: purple;
}
styles: ''
- type: custom:service-call
entries:
- type: selector
entity_id: light.chandelier
value_attribute: rgb_color
options:
- tap_action:
action: call-service
service: light.turn_on
data:
color_name: red
target:
entity_id: light.chandelier
confirmation: true
option: 255,0,0
label: Red
icon: mdi:alpha-r
entity_id: light.chandelier
type: button
value_attribute: state
styles: |
:host {
--label-color: red;
--color: red;
{% if (state_attr(config.entity, "rgb_color") or []).join(',') == '255,0,0' %}
--label-filter: invert(1);
{% endif %}
}
- tap_action:
action: call-service
service: light.turn_on
data:
color_name: green
target:
entity_id: light.chandelier
option: 0,255,0
label: Green
icon: mdi:alpha-g
entity_id: light.chandelier
type: button
value_attribute: state
styles: |-
:host {
--label-color: green;
--color: green;
{% if (state_attr(config.entity, "rgb_color") or []).join(',') == '0,255,0' %}
--label-filter: invert(1);
{% endif %}
```
--------------------------------
### CSS Variables for Theming
Source: https://github.com/nerwyn/custom-card-features/blob/main/_autodocs/utilities.md
Demonstrates using CSS variables for theming, allowing customization of colors and opacity.
```css
:host {
--color: var(--feature-color);
--opacity: 0.2;
}
```
--------------------------------
### Number Input Range Validation Configuration
Source: https://github.com/nerwyn/custom-card-features/blob/main/_autodocs/errors.md
Example configuration for number input validation, highlighting error states when the input is outside the specified range.
```yaml
type: input
thumb: number
range: [0, 100]
styles: |
.background {
border-color: var(--error-color);
}
```
--------------------------------
### Get Action Configuration
Source: https://github.com/nerwyn/custom-card-features/blob/main/_autodocs/api-reference-base-custom-feature.md
Retrieves the appropriate action configuration for a given action type. Use this to check for and access specific action settings before execution.
```typescript
const tapAction = this.getAction('tap_action');
if (tapAction) {
await this.sendAction('tap_action');
}
```
--------------------------------
### Action Confirmation Configuration
Source: https://github.com/nerwyn/custom-card-features/blob/main/_autodocs/errors.md
YAML configuration for tap actions, demonstrating basic confirmation and custom confirmation messages with exemptions.
```yaml
tap_action:
action: perform-action
confirmation: true
# With custom message
tap_action:
action: perform-action
confirmation:
text: Really turn off the light?
exemptions:
- user: admin_user_id
```
--------------------------------
### Basic Service Call Feature
Source: https://github.com/nerwyn/custom-card-features/blob/main/_autodocs/overview.md
Example of a custom service call feature for a tile card. Includes a button to turn on a light and a slider to control brightness.
```yaml
type: tile
entity: light.living_room
features:
- type: custom:service-call
entries:
- type: button
icon: mdi:lightbulb-on
label: On
tap_action:
action: perform-action
perform_action: light.turn_on
target:
entity_id: light.living_room
- type: slider
range: [0, 100]
step: 1
tap_action:
action: perform-action
perform_action: light.turn_on
target:
entity_id: light.living_room
data:
brightness_pct: '{{ value | int }}'
```
--------------------------------
### Importing Deep Object Utilities
Source: https://github.com/nerwyn/custom-card-features/blob/main/_autodocs/utilities.md
Demonstrates how to import deep object manipulation functions like deepGet and deepSet.
```typescript
// Individual imports
import { deepGet, deepSet } from '../utils';
import { atLeastHaVersion } from '../utils';
// Or from index
import { deepGet, atLeastHaVersion } from '../utils';
```
--------------------------------
### navigate
Source: https://github.com/nerwyn/custom-card-features/blob/main/_autodocs/api-reference-base-custom-feature.md
Navigates within Home Assistant by manipulating the browser's history using `window.history.pushState()` or `replaceState()`.
```APIDOC
## navigate(action)
### Description
Navigates within Home Assistant using `window.history.pushState()` or `replaceState()`.
### Method
`navigate(action: IAction): void`
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
```typescript
const action = {
action: 'navigate',
navigation_path: '/lovelace/0'
};
this.navigate(action);
```
### Response
#### Success Response
None
#### Response Example
None provided.
```
--------------------------------
### handleConfirmation(element, action)
Source: https://github.com/nerwyn/custom-card-features/blob/main/_autodocs/utilities.md
Shows a Home Assistant confirmation dialog if configured in the action. Returns a promise that resolves to a boolean indicating whether the action should proceed.
```APIDOC
## handleConfirmation(element, action)
### Description
Shows Home Assistant confirmation dialog if configured in action. Returns whether action should proceed.
### Parameters
#### Path Parameters
- **element** (BaseCustomFeature) - Required - The custom feature element.
- **action** (IAction) - Required - The action configuration.
### Returns
(Promise
) - A promise that resolves to true if the action should proceed, false otherwise.
### Example
```typescript
async sendAction(actionType: ActionType) {
const action = this.getAction(actionType);
if (!action || !(await handleConfirmation(this, action))) {
return;
}
// Proceed with action execution
}
```
```
--------------------------------
### Action Execution Pipeline
Source: https://github.com/nerwyn/custom-card-features/blob/main/_autodocs/overview.md
Illustrates the sequence of operations when an action is triggered, from sending the action to its final dispatch based on type. Includes navigation, service calls, toggling, and event firing.
```mermaid
graph TD
sendAction(sendAction(actionType))
↓
getAction(getAction(actionType)) → retrieves from config
↓
deepRenderTemplate() → renders all templates in action
↓
handleConfirmation() → shows dialog if configured
↓
Dispatch by action type:
├─ navigate → window.history.pushState
├─ url → window.open
├─ perform-action → hass.callService(domain, service, data, target)
├─ toggle → toggleSingle for each entity
├─ more-info → dispatch hass-more-info event
├─ assist → dispatch hass-action event
├─ fire-dom-event → window.dispatchEvent
├─ eval → new Function(this.eval)()
├─ repeat → nothing (hold-mode only)
└─ none → nothing
```
--------------------------------
### Template Label with Missing Entity State Handling
Source: https://github.com/nerwyn/custom-card-features/blob/main/_autodocs/errors.md
YAML example showing how to handle missing entity states within a template label, providing a default value when the entity state is undefined.
```yaml
# Check in template
label: '{{ value if value else "N/A" }}'
```
--------------------------------
### moreInfo
Source: https://github.com/nerwyn/custom-card-features/blob/main/_autodocs/api-reference-base-custom-feature.md
Opens the Home Assistant more-info dialog for a specified entity. If no target entity is provided, it defaults to the entity associated with the feature.
```APIDOC
## moreInfo(action)
### Description
Opens the Home Assistant more-info dialog for an entity.
### Method
`moreInfo(action: IAction): void`
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
```typescript
const action = {
action: 'more-info',
target: { entity_id: 'light.living_room' }
};
this.moreInfo(action);
```
### Response
#### Success Response
None
#### Response Example
None provided.
```
--------------------------------
### atLeastHaVersion(version, major, minor)
Source: https://github.com/nerwyn/custom-card-features/blob/main/_autodocs/utilities.md
Checks if the provided Home Assistant version string is at least the specified major and minor version numbers.
```APIDOC
## atLeastHaVersion(version, major, minor)
### Description
Checks if Home Assistant version is at least specified version.
### Parameters
#### Path Parameters
- **version** (string) - Required - The version string to check (e.g., '2024.8.0').
- **major** (number) - Required - The major version number to compare against.
- **minor** (number) - Required - The minor version number to compare against.
### Returns
(boolean) - True if the version is greater than or equal to the specified major.minor, false otherwise.
### Example
```typescript
const version = this.hass.config.version;
if (atLeastHaVersion(version, 2024, 8)) {
// Use 2024.8.0+ features
this.classList.add('no-padding');
}
```
```
--------------------------------
### assist(action)
Source: https://github.com/nerwyn/custom-card-features/blob/main/_autodocs/api-reference-base-custom-feature.md
Opens the Home Assistant Assist dialog. This method delegates the action to the `hassAction()` function.
```APIDOC
## assist(action)
### Description
Opens Home Assistant Assist dialog. Delegates to `hassAction()`.
### Parameters
- `action` (IAction) - Required - Action object to be passed to `hassAction()`.
```
--------------------------------
### Importing External Libraries
Source: https://github.com/nerwyn/custom-card-features/blob/main/_autodocs/utilities.md
Shows how to import functions from external libraries like ha-nunjucks, js-yaml, and lit.
```typescript
// External libraries
import { hasTemplate, renderTemplate } from 'ha-nunjucks';
import { load as loadYAML } from 'js-yaml';
import { css, html } from 'lit';
```
--------------------------------
### buildStyles(css)
Source: https://github.com/nerwyn/custom-card-features/blob/main/_autodocs/utilities.md
Wraps CSS rules in a Lit HTML `"
}
```
```
--------------------------------
### url
Source: https://github.com/nerwyn/custom-card-features/blob/main/_autodocs/api-reference-base-custom-feature.md
Opens an external URL using `window.open()`. If a protocol (like `http://` or `https://`) is not specified, it will be automatically prepended.
```APIDOC
## url(action)
### Description
Opens an external URL using `window.open()`. Automatically adds `https://` if protocol not specified.
### Method
`url(action: IAction): void`
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
```typescript
const action = {
action: 'url',
url_path: 'example.com'
};
this.url(action);
```
### Response
#### Success Response
None
#### Response Example
None provided.
```
--------------------------------
### Render Home Assistant Templates
Source: https://github.com/nerwyn/custom-card-features/blob/main/_autodocs/utilities.md
Use `renderTemplate` to process nunjucks templates with Home Assistant state and custom context. Set `strict` to true to throw errors on undefined variables.
```typescript
const hass = this.hass;
// Simple value
renderTemplate(hass, '{{ value }}', { value: 50 }) // '50'
// Conditional
renderTemplate(hass, '{{ iif(checked, "On", "Off") }}', { checked: true }) // 'On'
// Entity state
renderTemplate(hass, '{{ states("light.living_room") }}', hass) // 'on'
// With filters
renderTemplate(hass, '{{ value | int }}', { value: 50.5 }) // '50'
```
--------------------------------
### Value Update Delay Configuration
Source: https://github.com/nerwyn/custom-card-features/blob/main/_autodocs/errors.md
YAML configuration showing how to set the delay for value synchronization from Home Assistant to the custom feature.
```yaml
type: slider
value_from_hass_delay: 1000
# For faster sync
value_from_hass_delay: 500
# For slower sync
value_from_hass_delay: 2000
```
--------------------------------
### renderTemplate(str, context)
Source: https://github.com/nerwyn/custom-card-features/blob/main/_autodocs/api-reference-base-custom-feature.md
Renders a Nunjucks template using the Home Assistant template engine. This is useful for dynamically generating values within the configuration.
```APIDOC
## renderTemplate(str, context)
### Description
Renders a nunjucks template using Home Assistant template engine. Used for dynamic values in config.
### Parameters
- `str` (string | number | boolean) - Required - The template string or a regular value.
- `context` (object) - Optional - An optional template context object.
### Returns
- Rendered value or the original value if no template is detected.
### Request Example
```typescript
const color = this.renderTemplate('{{ iif(checked, "red", "blue") }}');
const icon = this.renderTemplate('mdi:light-{{ iif(checked, "on", "off") }}');
```
```
--------------------------------
### Light Control Button with Tap Actions
Source: https://github.com/nerwyn/custom-card-features/blob/main/README.md
Configures a button to control a light, with different actions for tap, double-tap, and hold. The button's color dynamically reflects the light's state.
```yaml
features:
- type: custom:service-call
entries:
- type: button
haptics: true
tap_action:
action: perform-action
perform_action: light.turn_on
data:
entity_id: light.sunroom_ceiling
color_name: red
double_tap_action:
action: perform-action
perform_action: light.turn_on
xdouble_tap_window: 1000
data:
entity_id: light.sunroom_ceiling
color_name: green
hold_action:
action: perform-action
perform_action: light.turn_on
xhold_time: 2000
data:
entity_id: light.sunroom_ceiling
color_name: blue
icon: mdi:power
label: '{{ states(config.entity) }}'
entity_id: light.sunroom_ceiling
value_attribute: state
styles: |-
:host {
{% if is_state(config.entity, "on") %}
--color: rgb({{ state_attr(config.entity, "rgb_color") }});
{% endif %};
}
```
--------------------------------
### XKCD Button with Dynamic URL and Momentary Actions
Source: https://github.com/nerwyn/custom-card-features/blob/main/README.md
Implements an XKCD button that opens a comic based on hold duration, using momentary button mode. It also includes a button to display the state float and log momentary action timings. This demonstrates advanced button interactions and dynamic URL generation.
```yaml
type: custom:service-call
entries:
- type: button
entity_id: climate.downstairs_thermostat
label: XKCD
value_from_hass_delay: 5000
momentary_end_action:
action: url
url_path: https://xkcd.com/{{ (1000 * hold_secs) | int }}
value_attribute: state
- type: button
entity_id: sensor.cold_flu_index_today
label: |-
State Float
{{ value }}
value_attribute: state
styles: ''
icon: ''
autofill_entity_id: false
momentary_end_action:
action: eval
eval: >-
const actionType = 'momentary_end_action'
const message = `${actionType} - ${Math.floor(this.momentaryEnd -
this.momentaryStart)}ms`
console.log(message)
const event = new Event('hass-notification', { bubbles: true,
composed: true })
event.detail = { message }
this.dispatchEvent(event)
momentary_start_action:
action: eval
eval: >-
const actionType = 'momentary_start_action'
```