Skip to content

Commit 1071549

Browse files
committed
Document suggestions for dashboards
1 parent a4da0ee commit 1071549

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

docs/frontend/custom-ui/custom-strategy.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,59 @@ window.customStrategies.push({
5454
});
5555
```
5656

57+
### Suggest values in the create dialog
58+
59+
Dashboard strategies can also suggest initial values for the dashboard details form that opens after a user picks the strategy.
60+
61+
To do this, add a static `getCreateSuggestions(hass)` method to your dashboard strategy element. Return an object with any of these optional keys:
62+
63+
| Key | Description |
64+
| ------- | ------------------------------------------ |
65+
| `title` | Suggested dashboard title. |
66+
| `icon` | Suggested dashboard icon, like `mdi:home`. |
67+
68+
Example:
69+
70+
```js
71+
class MyDemoDashboardStrategy extends HTMLElement {
72+
static getCreateSuggestions(hass) {
73+
return {
74+
title: hass.config.location_name || "My demo dashboard",
75+
icon: "mdi:view-dashboard",
76+
};
77+
}
78+
79+
static async generate(config, hass) {
80+
const title = config.title || "My demo dashboard";
81+
const locationName = hass.config.location_name || "Home Assistant";
82+
83+
return {
84+
title,
85+
views: [
86+
{
87+
title: "Home",
88+
path: "home",
89+
cards: [
90+
{
91+
type: "markdown",
92+
content:
93+
`# ${locationName}\n\n` +
94+
"This dashboard was generated by a community dashboard strategy.",
95+
},
96+
{
97+
type: "entities",
98+
entities: ["sun.sun"],
99+
},
100+
],
101+
},
102+
],
103+
};
104+
}
105+
}
106+
```
107+
108+
These values are only defaults for the dialog. Users can still change them before creating the dashboard.
109+
57110
### Examples
58111

59112
A good example to start from is the [home overview](https://github.com/home-assistant/frontend/tree/dev/src/panels/lovelace/strategies/home) dashboard or the [energy dashboard](https://github.com/home-assistant/frontend/tree/dev/src/panels/lovelace/strategies/energy).

0 commit comments

Comments
 (0)