Add card to dashboard section
dashboards_add_card_to_sectionInsert a Lovelace card into a specific section of a sections-type dashboard view, leaving other views intact. Optionally guard against stale reads with a config hash.
Instructions
Insert a card into one section of a type: sections view, leaving every other view intact.
Resolves the view via _load_view, requires it to be a sections
view, inserts card_config into that section's cards list at
position (or the end), and saves the whole dashboard back. This is
the only way to make a card visible on a sections view —
dashboards_add_card_to_view writes to view.cards, which such a
view renders only in edit mode. When expected_config_hash is given,
it is checked against the dashboard's hash right after the read and
before any change, so a stale caller never overwrites the wrong
section.
Use when: adding a card to a specific section of a sections view.
Pass expected_config_hash whenever section_index/position came
from an earlier read that might now be stale.
Not for: a masonry/panel view — use
dashboards_add_card_to_view.
Returns: {status: "added", url_path, view_index, view_title, section_index, card_index, cards_in_section, config_hash} —
config_hash is re-read from HA after the save (not the locally built
dict), ready to chain into the next call's expected_config_hash.
Errors: raises ValueError when card_config has no type key, the
view can't be resolved, isn't a sections view, or section_index is
out of range. Returns {"error": "config_changed", "expected_config_hash", "current_config_hash", "action"} without saving when
expected_config_hash doesn't match.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| position | No | Zero-based index within the section to insert at. Omit to append at the end. | |
| url_path | Yes | Dashboard url_path, or a view path in the default dashboard (e.g. 'living-room'). | |
| view_index | No | Zero-based view index; needed only when url_path names a dashboard rather than a view path. | |
| card_config | Yes | Lovelace card config with a 'type' key, e.g. {'type': 'tile', 'entity': 'sensor.power'}. | |
| section_index | Yes | Zero-based target section index, from dashboards_get_view_sections. | |
| expected_config_hash | No | Optional guard: the config_hash from a recent dashboards_get_view_sections or section-tool response. If the dashboard's current hash differs, this call returns 'config_changed' and saves nothing, since section_index/position are positions, not stable ids, and a change since your read may target the wrong section. Omit to skip the check (today's behaviour). |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||