You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: Support for sections using section_mode: true (#959)
You can use this card in [sections
views](https://www.home-assistant.io/dashboards/sections/) (the default
in home assistant since early 2024).
To enabled compatibility with sections (meaning the card adjusts its
size automatically and aligns with the other cards), you need to add
`section_mode: true` to the configuration of your card. This will set
the CSS card height to 100% and allow modification of its size using the
default `grid_options` available with all cards used in sections.
For users with heavily modified cards using `styles`, you might need to
adjust your configuration once enabling `section_mode`.
⚠️ While `section_mode` is enabled: using `aspect_ratio` or setting the
card's `height` or `width` using CSS will probably the layout and is
considered incompatible. There might be other incompatible options, if
you find any, please update this documentation by submitting a PR.
<img width="468" height="384" alt="section_mode"
src="https://github.com/user-attachments/assets/c8bc53d2-a40c-4e44-93e7-34ded22dd575"
/>
```yaml
views:
- title: Grid
type: sections
sections:
- type: grid
cards:
- type: custom:button-card
entity: switch.skylight
name: Button 1
section_mode: true
grid_options:
rows: 4
columns: 6
- type: custom:button-card
entity: switch.skylight
name: Button 2
section_mode: true
grid_options:
rows: 2
columns: 6
- type: custom:button-card
entity: switch.skylight
name: Button 3
section_mode: true
grid_options:
rows: 2
columns: 6
- type: custom:button-card
entity: switch.skylight
name: Button 4
section_mode: true
grid_options:
rows: 2
columns: 12
```
Closes#854
---------
Co-authored-by: dcapslock <[email protected]>
|`section_mode`| boolean | optional |`true`\|`false`| Set it to `true` when the card is used in a sections view. See [Sections views](#sections-views)|
102
105
|`triggers_update`| string or array | optional |`switch.ac`| entity_id list that would trigger a card update, see [triggers_update](#triggers_update)|
103
106
|`group_expand`| boolean | false |`true`\|`false`| When `true`, if any of the entities triggering a card update is a group, it will auto-expand the group and the card will update on any child entity state change. This works with nested groups too. See [triggers_update](#triggers_update)|
104
107
|`icon`| string | optional |`mdi:air-conditioner`| Icon to display. Will be overridden by the icon defined in a state (if present). Defaults to the entity icon. Hide with `show_icon: false`. Supports templates, see [templates](#javascript-templates)|
@@ -121,7 +124,7 @@ Lovelace Button card for your entities.
121
124
|`show_last_changed`| boolean |`false`|`true`\|`false`| Replace the label altogether and display the the `last_changed` attribute in a nice way (eg: `12 minutes ago`) |
122
125
|`show_entity_picture`| boolean |`false`|`true`\|`false`| Replace the icon by the entity picture (if any) or the custom picture (if any). Falls back to using the icon if both are undefined |
123
126
|`show_live_stream`| boolean |`false`|`true`\|`false`| Display the camera stream (if the entity is a camera). Requires the `stream:` component to be enabled in home-assistant's config |
124
-
|`live_stream_aspect_ratio`| string | optional |`16x9`, `50%`, `1.78` ... | See home-assistant Picture Entity card [aspect_ratio](https://www.home-assistant.io/dashboards/picture-entity/#aspect_ratio) for valid options |
127
+
|`live_stream_aspect_ratio`| string | optional |`16x9`, `50%`, `1.78` ... | See home-assistant Picture Entity card [aspect_ratio](https://www.home-assistant.io/dashboards/picture-entity/#aspect_ratio) for valid options |
125
128
|`live_stream_fit_mode`| string | optional |`cover`, `contain`, `fill`| See home-assistant Picture Entity card [fit_mod](https://www.home-assistant.io/dashboards/picture-entity/#fit_mode) for information on how each option works |
126
129
|`entity_picture`| string | optional | Can be any of `/local/*` file or a URL | Will override the icon/the default entity_picture with your own image. Best is to use a square image. You can also define one per state. Supports templates, see [templates](#javascript-templates)|
127
130
|`units`| string | optional |`Kb/s`, `lux`, ... | Override or define the units to display after the state of the entity. If omitted, it's using the entity's units |
@@ -274,6 +277,55 @@ The order of your elements in the `state` object matters. The first one which is
274
277
| `template` | | See [templates](#javascript-templates) for examples. `value` needs to be a javascript expression which returns a boolean. If the boolean is true, it will match this state |
275
278
| `default` | N/A | If nothing matches, this is used |
276
279
280
+
### Sections views
281
+
282
+
You can use this card in [sections views](https://www.home-assistant.io/dashboards/sections/) (the default in home assistant since early 2024).
283
+
284
+
To enable compatibility with sections (meaning the card adjusts its size automatically and aligns with the other cards), you need to add `section_mode: true` to the configuration of your card. This will set the CSS card height to 100% and allow modification of its size using the default `grid_options` available with all cards used in sections.
285
+
286
+
For users with heavily modified cards using `styles`, you might need to adjust your configuration once enabling `section_mode`.
287
+
288
+
⚠️ While `section_mode` is enabled: using `aspect_ratio` or setting the card's `height` or `width` using CSS will probably the layout and is considered incompatible. There might be other incompatible options, if you find any, please update this documentation by submitting a PR.
289
+
290
+

291
+
292
+
```yaml
293
+
views:
294
+
- title: Grid
295
+
type: sections
296
+
sections:
297
+
- type: grid
298
+
cards:
299
+
- type: custom:button-card
300
+
entity: switch.skylight
301
+
name: Button 1
302
+
section_mode: true
303
+
grid_options:
304
+
rows: 4
305
+
columns: 6
306
+
- type: custom:button-card
307
+
entity: switch.skylight
308
+
name: Button 2
309
+
section_mode: true
310
+
grid_options:
311
+
rows: 2
312
+
columns: 6
313
+
- type: custom:button-card
314
+
entity: switch.skylight
315
+
name: Button 3
316
+
section_mode: true
317
+
grid_options:
318
+
rows: 2
319
+
columns: 6
320
+
- type: custom:button-card
321
+
entity: switch.skylight
322
+
name: Button 4
323
+
section_mode: true
324
+
grid_options:
325
+
rows: 2
326
+
columns: 12
327
+
```
328
+
277
329
### Layout
278
330
279
331
This option enables you to modify the layout of the card.
3. Add `/local/button_card.js` as a [dashboard JavaScript module resource](https://developers.home-assistant.io/docs/frontend/custom-ui/registering-resources/).
1143
+
3. Add `/local/button_card.js` as a [dashboard JavaScript module resource](https://developers.home-assistant.io/docs/frontend/custom-ui/registering-resources/).
1092
1144
1093
1145
> Note: Your browser may block the download link as the file is a javascript file. If the link seems to do nothing, copy the link address and use directly in your browser's address bar where you will most likely get prompt on whether to allow the download or not.
1094
1146
@@ -1501,7 +1553,7 @@ Example with `template`:
1501
1553
1502
1554
#### Nested `custom:button-card`
1503
1555
1504
-
A simple nested example. This could be completed with a non-nested card, but the simplicity of this example is to show using templates in nested button cards.
1556
+
A simple nested example. This could be completed with a non-nested card, but the simplicity of this example is to show using templates in nested button cards.
0 commit comments