Skip to content

Commit e9173f9

Browse files
committed
Document suggestions for dashboards
1 parent e696bd9 commit e9173f9

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
@@ -48,6 +48,59 @@ window.customStrategies.push({
4848
});
4949
```
5050

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

53106
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)