A powerful custom Home Assistant Lovelace card designed to create dynamic forms and handle form-based actions with ease.
Form Card enables you to integrate highly customizable forms into your dashboards, using Home Assistant-provided selectors. Pair it with form-entity-row
to embed form fields inside entity rows for seamless user experiences.
Having issues with the UI editor when using card-mod with form-card? A PR which fixes this issue has been submitted, and will hopefully be merged soon.
- Dynamic Form Field Support: Build forms with various input types using Home Assistant selectors.
- Action Triggers: Perform actions when forms are submitted or values are changed.
- Data Management: Spread values directly into action payloads or nest them under a key for structured data.
- Templating: Utilize Jinja2 templates in field names, values, or action data for configurable dynamic behavior.
- Entity Row Integration: Add form fields directly to entity rows with
form-entity-row
.
form-card is available in HACS (Home Assistant Community Store).
Use this link to directly go to the repository in HACS
or
- Install HACS if you don't have it already
- Open HACS in Home Assistant
- Search for "Mushroom"
- Click the download button. β¬οΈ
- Download
form-card.js
file from the latest release. - Put
form-card.js
file into yourconfig/www
folder. - Add reference to
form-card.js
in Dashboard. There's two way to do that:
- Using UI: Settings β Dashboards β More Options icon β Resources β Add Resource β Set Url as
/local/form-card.js
β Set Resource type asJavaScript Module
. Note: If you do not see the Resources menu, you will need to enable Advanced Mode in your User Profile - Using YAML: Add following code to
lovelace
section.resources: - url: /local/form-card.js type: module
YAML:
type: custom:form-card
title: My Custom Form
fields:
- name: text_field
label: Text Field
entity: input_text.my_text
selector:
text: { }
- name: number_field
label: Number Field
selector:
number:
min: 0
max: 100
step: 1
default: "50"
save_action:
action: call-service
service: input_text.set_value
target:
entity_id: input_text.my_text
data:
value: "{{ value['number_field'] }}"
Parameter | Type | Default | Required? | Description |
---|---|---|---|---|
type |
string |
N/A | β | Must be set to custom:form-card . |
title |
string |
N/A | β | Title of the form card. |
fields |
array |
N/A | β | Array defining form fields (see field options below). |
reset_on_submit |
boolean |
false |
β | If true , resets the form on submit. |
spread_values_to_data |
boolean |
false |
β | If true , spreads form values into action payload directly. |
save_action |
action |
N/A | β | Defines what action occurs when the form is submitted. |
save_label |
string |
N/A | β | Label for the save button. |
hide_undo_button |
boolean |
false |
β | If true , hides the undo button. |
Parameter | Type | Default | Required? | Description |
---|---|---|---|---|
type |
string |
N/A | β | Must be set to custom:form-entity-row . |
selector |
selector |
N/A | β | Selector configuration. |
entity |
string |
N/A | β | Entity ID for the field. |
label |
string |
N/A | β | Display name for the field. |
default |
any |
entity state |
β | Default value for the field. Will be set to entity (if specified) state if not provided. |
icon |
string |
N/A | β | Icon for the field. |
spread_values_to_data |
boolean |
false |
β | If true , spreads form values into action payload directly (under the key value ). |
change_action |
action |
N/A | β | Defines what action occurs when the field is changed. |
If entity
is provided, it will be used as the default value for target
in your change_action
.
Each element in the fields
array supports the following options:
Parameter | Type | Default | Required? | Description |
---|---|---|---|---|
name |
string |
N/A | β | Unique identifier for the field. |
label |
string |
N/A | β | Display name for the field. |
entity |
string |
N/A | β | Entity ID for the field. |
selector |
selector |
N/A | β | Selector configuration. |
default |
any |
entity state |
β | Default value for the field. Will be set to entity (if specified) state if not provided. |
description |
string |
N/A | β | Description for the field. |
placeholder |
string |
N/A | β | Placeholder text for the field. |
required |
boolean |
false |
β | Marks the field as required. |
disabled |
boolean |
false |
β | Whether the field is disabled. |
All options accept jinja2 templates.
The templates have access to a few special variables. Those are:
config
- an object containing the card configurationuser
- the username of the currently logged in user
For entity rows and fields with entity
specified, the following variables are also available:
entity
- the entity ID of the field
YAML:
type: custom:form-card
title: Dynamic Input
fields:
- name: temperature
label: Desired Temperature
entity: climate.living_room
selector:
number:
min: 10
max: 30
step: 1
default: "{{ state_attr(entity, 'temperature') }}"
save_action:
action: call-service
service: climate.set_temperature
target:
entity_id: climate.living_room
data:
temperature: "{{ value['temperature'] }}"
YAML:
type: entities
entities:
- type: custom:form-entity-row
entity: input_text.my_text
label: Custom Input
default: "Default Value"
change_action:
action: call-service
service: input_text.set_value
data:
value: "{{ value }}"
# or (equivalent):
spread_values_to_data: true
change_action:
action: call-service
service: input_text.set_value