2019-05-09 22:13:06 +08:00
# Button Card <!-- omit in toc -->
2019-02-24 04:57:23 +08:00
2019-02-24 04:55:19 +08:00
[![GitHub Release][releases-shield]][releases]
[![License][license-shield]](LICENSE.md)
2019-02-24 04:55:41 +08:00
![Project Maintenance][maintenance-shield]
2019-02-24 04:55:19 +08:00
[![GitHub Activity][commits-shield]][commits]
[![Discord][discord-shield]][discord]
[![Community Forum][forum-shield]][forum]
2019-02-23 08:21:18 +08:00
2018-10-06 18:10:54 +08:00
Lovelace Button card for your entities.
2018-08-26 23:52:54 +08:00
2018-09-04 01:38:48 +08:00
![all ](examples/all.gif )
2018-08-28 08:06:51 +08:00
2019-05-09 22:13:06 +08:00
## TOC <!-- omit in toc -->
- [Features ](#features )
- [Configuration ](#configuration )
- [Main Options ](#main-options )
- [Action ](#action )
- [State ](#state )
- [Available operators ](#available-operators )
- [Layout ](#layout )
- [Templates ](#templates )
- [Styles ](#styles )
- [Easy styling options ](#easy-styling-options )
2019-05-10 20:49:44 +08:00
- [Light entity color variable ](#light-entity-color-variable )
2019-05-09 22:13:06 +08:00
- [ADVANCED styling options ](#advanced-styling-options )
2019-05-16 08:43:39 +08:00
- [Configuration Templates ](#configuration-templates )
2019-05-24 18:54:42 +08:00
- [General ](#general )
- [Merging state by id ](#merging-state-by-id )
2019-05-09 22:13:06 +08:00
- [Installation ](#installation )
- [Manual Installation ](#manual-installation )
2019-05-24 18:54:42 +08:00
- [Installation and tracking with `custom_updater` ](#installation-and-tracking-with-customupdater )
2019-05-09 22:13:06 +08:00
- [Examples ](#examples )
- [Configuration with states ](#configuration-with-states )
- [Default behavior ](#default-behavior )
- [With Operator on state ](#with-operator-on-state )
2019-05-24 18:54:42 +08:00
- [`tap_action` Navigate ](#tapaction-navigate )
2019-05-09 22:13:06 +08:00
- [blink ](#blink )
- [Play with width, height and icon size ](#play-with-width-height-and-icon-size )
- [Templates Support ](#templates-support )
- [Playing with label templates ](#playing-with-label-templates )
- [State Templates ](#state-templates )
- [Styling ](#styling )
- [Lock ](#lock )
2019-05-24 18:54:42 +08:00
- [Aspect Ratio ](#aspect-ratio )
2019-05-09 22:13:06 +08:00
- [Credits ](#credits )
2018-08-28 08:06:51 +08:00
## Features
2019-04-18 08:30:57 +08:00
- works with any toggleable entity
2019-05-10 20:49:44 +08:00
- 6 available actions on **tap** and/or **hold** and/or **double click** : `none` , `toggle` , `more-info` , `navigate` , `url` and `call-service`
2019-04-18 08:30:57 +08:00
- state display (optional)
2019-05-09 22:13:06 +08:00
- custom color (optional), or based on light rgb value/temperature
2019-04-18 08:30:57 +08:00
- custom state definition with customizable color, icon and style (optional)
2019-04-29 16:50:13 +08:00
- [custom size of the icon, width and height ](#Play-with-width-height-and-icon-size ) (optional)
2019-05-24 18:54:42 +08:00
- [aspect ratio support ](#aspect-ratio ) (optional)
2019-04-30 00:44:04 +08:00
- Support for [templates ](#templates ) in some fields
2019-04-18 08:30:57 +08:00
- custom icon (optional)
- custom css style (optional)
2019-05-09 22:13:06 +08:00
- multiple [layout ](#Layout ) support and [custom layout ](#advanced-styling-options ) support
- units for sensors can be redefined or hidden
2019-04-18 08:30:57 +08:00
- 2 color types
- `icon` : apply color settings to the icon only
- `card` : apply color settings to the card only
- automatic font color if color_type is set to `card`
- blank card and label card (for organization)
- [blink ](#blink ) animation support
2019-04-20 00:33:07 +08:00
- rotating animation support
2019-05-09 22:13:06 +08:00
- confirmation popup for sensitive items (optional) or [locking mecanism ](#lock )
2019-04-25 16:15:57 +08:00
- haptic support for the [Beta IOS App ](http://home-assistant.io/ios/beta )
2019-04-18 08:30:57 +08:00
- support for [custom_updater ](https://github.com/custom-components/custom_updater )
2018-08-26 23:52:54 +08:00
2019-04-18 07:03:57 +08:00
## Configuration
2019-04-18 08:30:57 +08:00
2019-04-18 07:03:57 +08:00
### Main Options
2019-04-20 02:16:47 +08:00
| Name | Type | Default | Supported options | Description |
| -------------- | ----------- | ------------ | ------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `type` | string | **Required** | `custom:button-card` | Type of the card |
2019-05-16 08:43:39 +08:00
| `template` | string | optional | any valid template from `button_card_templates` | See [configuration template ](#Configuration-Templates ) |
2019-04-25 15:45:04 +08:00
| `entity` | string | optional | `switch.ac` | entity_id |
2019-04-20 02:16:47 +08:00
| `icon` | string | optional | `mdi:air-conditioner` | Icon to display. Will be overriden by the icon defined in a state (if present). Defaults to the entity icon. Hide with `show_icon: false` |
| `color_type` | string | `icon` | `icon` \| `card` \| `blank-card` \| `label-card` | Color either the background of the card or the icon inside the card. Setting this to `card` enable automatic `font` and `icon` color. This allows the text/icon to be readable even if the background color is bright/dark. Additional color-type options `blank-card` and `label-card` can be used for organisation (see examples). |
2019-05-24 18:54:42 +08:00
| `color` | string | optional | `auto` \| `auto-no-temperature` \| `rgb(28, 128, 199)` | Color of the icon/card. `auto` sets the color based on the color of a light including the temperature of the light. Setting this to `auto-no-temperature` will behave like home-assistant's default ignoring the temperature of the light. By default, if the entity state is `off` , the color will be `var(--paper-item-icon-active-color)` , for `on` it will be `var(--paper-item-icon-color)` and for any other state it will be `var(--primary-text-color)` . You can redefine each colors using `state` |
| `size` | string | `40%` | `20px` | Size of the icon. Can be percentage or pixel |
| `aspect_ratio` | string | optional | `1/1` , `2/1` , `1/1.5` , ... | See [here ](#aspect-ratio ) for an example. Aspect ratio of the card. `1/1` being a square. This will auto adapt to your screen size |
2019-04-22 02:50:44 +08:00
| `tap_action` | object | optional | See [Action ](#Action ) | Define the type of action on click, if undefined, toggle will be used. |
2019-04-25 15:45:04 +08:00
| `hold_action` | object | optional | See [Action ](#Action ) | Define the type of action on hold, if undefined, nothing happens. |
2019-05-10 20:49:44 +08:00
| `dbltap_action` | object | optional | See [Action ](#Action ) | Define the type of action on double click, if undefined, nothing happens. |
2019-04-20 02:16:47 +08:00
| `name` | string | optional | `Air conditioner` | Define an optional text to show below the icon |
2019-04-30 00:44:04 +08:00
| `label` | string | optional | Any string that you want | Display a label below the card. See [Layouts ](#layout ) for more information. |
2019-05-01 19:40:20 +08:00
| `label_template` | string | optional | | See [templates ](#templates ). Any javascript code which returns a string. Overrides `label` |
2019-04-20 12:44:35 +08:00
| `show_name` | boolean | `true` | `true` \| `false` | Wether to show the name or not. Will pick entity_id's name by default, unless redefined in the `name` property or in any state `name` property |
2019-05-24 18:54:42 +08:00
| `name_template` | string | optional | | See [templates ](#templates ). Any javascript code which returns a string. Overrides `name` |
2019-04-20 02:16:47 +08:00
| `show_state` | boolean | `false` | `true` \| `false` | Show the state on the card. defaults to false if not set |
| `show_icon` | boolean | `true` | `true` \| `false` | Wether to show the icon or not. Unless redefined in `icon` , uses the default entity icon from hass |
2019-04-23 15:13:54 +08:00
| `show_units` | boolean | `true` | `true` \| `false` | Display or hide the units of a sensor, if any. |
2019-05-04 19:20:33 +08:00
| `show_label` | boolean | `false` | `true` \| `false` | Display or hide the `label` /`label_template` |
| `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` ) |
2019-04-26 07:00:50 +08:00
| `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 |
| `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 |
2019-05-24 18:54:42 +08:00
| `entity_picture_template` | string | optional | | See [templates ](#templates ). Any javascript code which returns a path to a file or a url as a string. Overrides `entity_picture` |
2019-04-23 15:13:54 +08:00
| `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 |
2019-05-01 19:40:20 +08:00
| `styles` | object list | optional | | See [styles ](#styles ) |
2019-04-20 02:16:47 +08:00
| `state` | object list | optional | See [State ](#State ) | State to use for the color, icon and style of the button. Multiple states can be defined |
2019-04-22 14:04:11 +08:00
| `confirmation` | string | optional | Free-form text | Show a confirmation popup on tap with defined text |
2019-05-04 19:20:33 +08:00
| `lock` | boolean | `false` | `true` \| `false` | See [lock ](#lock ). This will display a normal button with a lock symbol in the corner. Clicking the button will make the lock go away and enable the button to be manoeuvred for five seconds |
2019-06-05 04:49:46 +08:00
| `unlock_users` | string list | optional | A list of users | List of users allowed to unlock the button when `lock: true` . If not defined, everyone is allowed to unlock the button |
2019-04-23 15:13:54 +08:00
| `layout` | string | optional | See [Layout ](#Layout ) | The layout of the button can be modified using this option |
2019-04-18 07:03:57 +08:00
### Action
2019-04-20 02:21:15 +08:00
| Name | Type | Default | Supported options | Description |
| ----------------- | ------ | -------- | ---------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- |
| `action` | string | `toggle` | `more-info` , `toggle` , `call-service` , `none` , `navigate` , `url` | Action to perform |
2019-05-24 18:54:42 +08:00
| `entity` | string | none | Any entity id | **Only valid for `action: more-info`** to override the entity on which you want to call `more-info` |
2019-04-20 02:21:15 +08:00
| `navigation_path` | string | none | Eg: `/lovelace/0/` | Path to navigate to (e.g. `/lovelace/0/` ) when action defined as navigate |
| `url` | string | none | Eg: `https://www.google.fr` | URL to open on click when action is `url` . The URL will open in a new tab |
| `service` | string | none | Any service | Service to call (e.g. `media_player.media_play_pause` ) when `action` defined as `call-service` |
2019-05-16 08:43:39 +08:00
| `service_data` | object | none | Any service data | Service data to include (e.g. `entity_id: media_player.bedroom` ) when `action` defined as `call-service` . If your `service_data` requires an `entity_id` , you can use the keywork `entity` , this will actually call the service on the entity defined in the main configuration of this card. Useful for [configuration templates ](#configuration-templates ) |
2019-04-25 16:15:57 +08:00
| `haptic` | string | none | `success` , `warning` , `failure` , `light` , `medium` , `heavy` , `selection` | Haptic feedback for the [Beta IOS App ](http://home-assistant.io/ios/beta ) |
2019-05-10 21:23:00 +08:00
| `repeat` | number | none | eg: `500` | For a hold_action, you can optionally configure the action to repeat while the button is being held down (for example, to repeatedly increase the volume of a media player). Define the number of milliseconds between repeat actions here. |
2019-04-18 07:03:57 +08:00
### State
2019-04-20 02:16:47 +08:00
| Name | Type | Default | Supported options | Description |
| ---------- | ------------- | ------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- |
| `operator` | string | `==` | See [Available Operators ](#Available-operators ) | The operator used to compare the current state against the `value` |
| `value` | string/number | **required** (unless operator is `default` ) | If your entity is a sensor with numbers, use a number directly, else use a string | The value which will be compared against the current state of the entity |
2019-04-20 12:44:35 +08:00
| `name` | string | optional | Any string, `'Alert'` , `'My little switch is on'` , ... | if `show_name` is `true` , the name to display for this state. If undefined, uses the general config `name` , and if undefined uses the entity name |
2019-05-24 18:54:42 +08:00
| `name_template` | string | optional | | See [templates ](#templates ). Any javascript code which returns a string. Overrides `name` |
2019-04-20 02:16:47 +08:00
| `icon` | string | optional | `mdi:battery` | The icon to display for this state. Defaults to the entity icon. Hide with `show_icon: false` |
| `color` | string | `var(--primary-text-color)` | Any color, eg: `rgb(28, 128, 199)` or `blue` | The color of the icon (if `color_type: icon` ) or the background (if `color_type: card` ) |
2019-05-01 19:40:20 +08:00
| `styles` | string | optional | | See [styles ](#styles ) |
2019-04-20 02:16:47 +08:00
| `spin` | boolean | `false` | `true` \| `false` | Should the icon spin for this state? |
2019-04-26 07:00:50 +08:00
| `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 for this state. Best is to use a square image |
2019-05-24 18:54:42 +08:00
| `entity_picture_template` | string | optional | | See [templates ](#templates ). Any javascript code which returns a path to a file or a url as a string. Overrides `entity_picture` |
2019-04-30 00:44:04 +08:00
| `label` | string | optional | Any string that you want | Display a label below the card. See [Layouts ](#layout ) for more information. |
2019-05-01 19:40:20 +08:00
| `label_template` | string | optional | | See [templates ](#templates ). Any javascript code which returns a string. Overrides `label` |
2019-04-18 07:03:57 +08:00
### Available operators
2019-04-30 00:44:04 +08:00
The order of your elements in the `state` object matters. The first one which is `true` will match.
2019-04-18 07:03:57 +08:00
| Operator | `value` example | Description |
| :-------: | --------------- | -------------------------------------------------------------------------------------------------------- |
| `<` | `5` | Current state is inferior to `value` |
| `<=` | `4` | Current state is inferior or equal to `value` |
| `==` | `42` or `'on'` | **This is the default if no operator is specified.** Current state is equal (`==` javascript) to `value` |
| `>=` | `32` | Current state is superior or equal to `value` |
| `>` | `12` | Current state is superior to `value` |
| `!=` | `'normal'` | Current state is not equal (`!=` javascript) to `value` |
| `regex` | `'^norm.*$'` | `value` regex applied to current state does match |
2019-05-01 19:40:20 +08:00
| `template` | | See [templates ](#templates ) for examples. `value` needs to be a javascript expression which returns a boolean. If the boolean is true, it will match this state |
2019-04-18 07:03:57 +08:00
| `default` | N/A | If nothing matches, this is used |
2019-04-23 15:13:54 +08:00
### Layout
This option enables you to modify the layout of the card.
It is fully compatible with every `show_*` option. Make sure you set `show_state: true` if you want to show the state
Multiple values are possible, see the image below for examples:
* `vertical` (default value if nothing is provided): Everything is centered vertically on top of each other
2019-04-30 00:44:04 +08:00
* `icon_name_state` : Everything is aligned horizontally, name and state are concatenated, label is centered below
* `name_state` : Icon sits on top of name and state concatenated on one line, label below
* `icon_name` : Icon and name are horizontally aligned, state and label are centered below
* `icon_state` : Icon and state are horizontally aligned, name and label are centered below
* `icon_label` : Icon and label are horizontally aligned, name and state are centered below
* `icon_name_state2nd` : Icon, name and state are horizontally aligned, name is above state, label below name and state
* `icon_state_name2nd` : Icon, name and state are horizontally aligned, state is above name, label below name and state
2019-04-23 15:13:54 +08:00
![layout_image ](examples/layout.png )
2019-04-30 00:44:04 +08:00
### Templates
2019-05-24 18:54:42 +08:00
`label_template` , `name_template` , `entity_picture_template` supports templating as well as `value` for `state` when `operator: template`
2019-05-04 19:20:33 +08:00
* `label_template` : It will be interpreted as javascript code and the code should return a string.
`label_template` supports inline HTML, so you can do stuff like:
```yaml
label_template: >
return 'Connection: '
+ (states['switch.connection'].state === 'on'
? '< span style = "color: #00FF00 ;" > enabled</ span > '
: '< span style = "color: #FF0000 ;" > disabled</ span > ')
+ ' / '
+ (states['binary_sensor.status'].state === 'on' ? 'connected' : 'disconnected')
```
![label-template-example ](examples/label_template.png )
2019-05-24 18:54:42 +08:00
* `name_template` : It will be interpreted as javascript code and the code should return a string.
* `entity_picture_template` : It will be interpreted as javascript code and the code should return a path to a file or a url as a string.
2019-05-01 19:40:20 +08:00
* `value` for `state` when `operator: template` : It will be interpreted as javascript code and the code should return a boolean (`true` or `false` )
2019-04-30 00:44:04 +08:00
Inside the javascript code, you'll have access to those variables:
* `entity` : The current entity object, if the entity is defined in the card
* `states` : An object with all the states of all the entities (equivalent to `hass.states` )
* `user` : The user object (equivalent to `hass.user` )
* `hass` : The complete `hass` object
2019-05-01 19:40:20 +08:00
The value shouldn't be enclosed in quotes:
```yaml
label_template: >
return states['light.mylight'].attributes.brightness
```
or
```yaml
state:
- operator: template
value: >
return states['input_select.light_mode'].state === 'night_mode'
```
See [here ](#templates-support ) for some examples.
### Styles
2019-05-09 22:13:06 +08:00
#### Easy styling options
2019-05-01 19:40:20 +08:00
For each element in the card, styles can be defined in 2 places:
* in the main part of the config
* in each state
Styles defined in each state are **additive** with the ones defined in the main part of the config. In the `state` part, just define the ones specific to your current state and keep the common ones in the main part of the config.
The `style` object members are:
* `card` : styles for the card itself. Styles that are defined here will be applied to the whole card and it's content, unless redefined in elements below.
* `icon` : styles for the icon
* `entity_picture` : styles for the picture (if any)
* `name` : styles for the name
* `state` : styles for the state
* `label` : styles for the label
2019-05-10 20:49:44 +08:00
* `lock` : styles for the lock icon (see [here ](https://github.com/custom-cards/button-card/blob/master/src/styles.ts#L36-L49 ) for the default style)
2019-05-01 19:40:20 +08:00
```yaml
- type: custom:button-card
[...]
styles:
card:
- xxxx: value
icon:
- xxxx: value
entity_picture:
- xxxx: value
name:
- xxxx: value
state:
- xxxx: value
label:
- xxxx: value
state:
- value: 'on'
styles:
card:
- yyyy: value
icon:
- yyyy: value
entity_picture:
- yyyy: value
name:
- yyyy: value
state:
- yyyy: value
label:
- yyyy: value
```
This will render:
* The `card` with the styles `xxxx: value` **and** `yyyy: value` applied
* Same for all the others.
See [styling ](#styling ) for a complete example.
2019-04-30 00:44:04 +08:00
2019-05-10 20:49:44 +08:00
#### Light entity color variable
2019-05-29 22:09:53 +08:00
If a light entity is assigned to the button, then:
* the CSS variable `--button-card-light-color` will contain the current light color
* the CSS variable `--button-card-light-color-no-temperature` will contain the current light without the temperature
You can use them both in other parts of the button. When off, it will be set to `var(--paper-item-icon-color)`
2019-05-10 20:49:44 +08:00
![css-var ](examples/color-variable.gif )
```yaml
styles:
name:
2019-05-29 22:09:53 +08:00
- color: var(--button-card-light-color)
2019-05-10 20:49:44 +08:00
card:
- -webkit-box-shadow: 0px 0px 9px 3px var(--button-card-light-color)
- box-shadow: 0px 0px 9px 3px var(--button-card-light-color)
```
2019-05-09 22:13:06 +08:00
#### ADVANCED styling options
For advanced styling, there are 2 other options in the `styles` config object:
* `grid` : mainly layout for the grid
* `img_cell` : mainly how you position your icon in it's cell
This is how the button is constructed (HTML elements):
![elements in the button ](examples/button-card-elements.png )
The `grid` element uses CSS grids to design the layout of the card:
* `img_cell` element is going to the `grid-area: i` by default
* `name` element is going to the `grid-area: n` by default
* `state` element is going to the `grid-area: s` by default
* `label` element is going to the `grid-area: l` by default
You can see how the default layouts are constructed [here ](./src/styles.ts#L152 ) and inspire yourself with it. We'll not support advanced layout questions here, please use [home-assitant's community forum][forum] for that.
To learn more, please use Google and this [excellent guide about CSS Grids ](https://css-tricks.com/snippets/css/complete-guide-grid/ ) :)
Some examples:
* label on top:
```yaml
styles:
grid:
- grid-template-areas: '"l" "i" "n" "s"'
- grid-template-rows: min-content 1fr min-content min-content
- grid-template-columns: 1fr
```
* icon on the right side (by overloading an existing layout):
```yaml
- type: "custom:button-card"
entity: sensor.sensor1
layout: icon_state_name2nd
show_state: true
show_name: true
show_label: true
label: label
styles:
grid:
- grid-template-areas: '"n i" "s i" "l i"'
- grid-template-columns: 1fr 40%
```
* Apple Homekit-like buttons:
2019-05-10 20:49:44 +08:00
2019-05-09 22:13:06 +08:00
![apple-like-buttons ](examples/apple_style.gif )
```yaml
- type: custom:button-card
entity: switch.skylight
name: < 3 Apple
icon: mdi:fire
show_state: true
styles:
card:
- width: 100px
- height: 100px
grid:
- grid-template-areas: '"i" "n" "s"'
- grid-template-columns: 1fr
- grid-template-rows: 1fr min-content min-content
img_cell:
- align-self: start
- text-align: start
name:
- justify-self: start
- padding-left: 10px
- font-weight: bold
- text-transform: lowercase
state:
- justify-self: start
- padding-left: 10px
state:
- value: 'off'
styles:
card:
- filter: opacity(50%)
icon:
- filter: grayscale(100%)
```
2019-05-16 08:43:39 +08:00
### Configuration Templates
2019-05-24 18:54:42 +08:00
#### General
2019-05-16 08:43:39 +08:00
* Define your config template in the main lovelace configuration and then use it in your button-card. This will avoid a lot of repetitions! It's basically YAML anchors, but without using YAML anchors and is very useful if you split your config in multiple files 😄
2019-05-24 18:54:42 +08:00
* You can overload any parameter with a new one
* You can merge states together **by `id`** when using templates. The states you want to merge have to have the same `id` . This `id` parameter is new and can be anything (string, number, ...). States without `id` will be appended to the state array. Styles embedded in a state are merged together as usual. See [here ](#merging-state-by-id ) for an example.
2019-05-16 08:43:39 +08:00
* You can also inherit another template from within a template.
In `ui-lovelace.yaml` (or in another file using `!import` )
```yaml
button_card_templates:
header:
styles:
card:
- padding: 5px 15px
- background-color: var(--paper-item-icon-active-color)
name:
- text-transform: uppercase
- color: var(--primary-background-color)
- justify-self: start
- font-weight: bold
label:
- text-transform: uppercase
- color: var(--primary-background-color)
- justify-self: start
- font-weight: bold
2019-05-16 08:48:06 +08:00
header_red:
template: header
styles:
card:
- background-color: '#FF0000'
2019-05-16 08:43:39 +08:00
2019-05-16 08:48:06 +08:00
my_little_template:
[...]
2019-05-16 08:43:39 +08:00
```
And then where you use button-card, you can apply this template, and/or overload it:
```yaml
- type: custom:button-card
template: header_red
name: My Test Header
```
2019-05-24 18:54:42 +08:00
#### Merging state by id
Example to merge state by `id` :
```yaml
button_card_templates:
sensor:
styles:
card:
- font-size: 16px
- width: 75px
tap_action:
action: more-info
state:
- color: orange
value: 75
id: my_id
sensor_humidity:
template: sensor
icon: 'mdi:weather-rainy'
state:
- color: 'rgb(255,0,0)'
operator: '>'
value: 50
- color: 'rgb(0,0,255)'
operator: '< '
value: 25
sensor_test:
template: sensor_humidity
state:
- color: pink
id: my_id
operator: '>'
value: 75
styles:
name:
- color: '#ff0000'
############### Used like this ##############
- type: custom:button-card
template: sensor_test
entity: input_number.test
show_entity_picture: true
```
Will result in this state object for your button (styles, operator and color are overridden for the `id: my_id` as you can see):
```yaml
state:
- color: pink
operator: '>'
value: 75
styles:
name:
- color: '#ff0000'
- color: 'rgb(255,0,0)'
operator: '>'
value: 50
- color: 'rgb(0,0,255)'
operator: '< '
value: 25
```
2019-04-18 07:03:57 +08:00
## Installation
2019-04-18 08:30:57 +08:00
2019-02-23 08:06:43 +08:00
### Manual Installation
2019-04-26 00:38:41 +08:00
1. Download the [button-card ](https://raw.githubusercontent.com/custom-cards/button-card/master/dist/button-card.js )
2018-08-28 08:06:51 +08:00
2. Place the file in your `config/www` folder
3. Include the card code in your `ui-lovelace-card.yaml`
2019-02-23 08:06:43 +08:00
2018-08-26 23:52:54 +08:00
```yaml
title: Home
resources:
- url: /local/button-card.js
type: module
```
2019-02-23 08:06:43 +08:00
2018-08-28 08:06:51 +08:00
4. Write configuration for the card in your `ui-lovelace.yaml`
2019-02-23 08:06:43 +08:00
### Installation and tracking with `custom_updater`
2018-09-04 01:38:48 +08:00
2019-02-23 08:06:43 +08:00
1. Make sure the [custom_updater ](https://github.com/custom-components/custom_updater ) component is installed and working.
2. Configure Lovelace to load the card.
2018-09-04 01:38:48 +08:00
2019-02-23 08:06:43 +08:00
```yaml
resources:
- url: /customcards/github/custom-cards/button-card.js?track=true
type: module
2018-09-04 01:38:48 +08:00
```
2019-02-23 08:06:43 +08:00
3. Run the service `custom_updater.check_all` or click the "CHECK" button if you use the [`tracker-card` ](https://github.com/custom-cards/tracker-card ).
4. Refresh the website.
2018-09-04 01:38:48 +08:00
2018-08-28 08:06:51 +08:00
## Examples
2019-04-18 07:03:57 +08:00
Show a button for the air conditioner (blue when on, `var(--disabled-text-color)` when off):
2018-09-02 11:31:47 +08:00
2018-09-04 01:38:48 +08:00
![ac ](examples/ac.png )
2018-09-02 11:31:47 +08:00
2018-08-26 23:52:54 +08:00
```yaml
- type: "custom:button-card"
entity: switch.ac
icon: mdi:air-conditioner
color: rgb(28, 128, 199)
```
2019-04-18 07:03:57 +08:00
Redefine the color when the state if off to red:
2019-04-18 08:30:57 +08:00
2019-04-18 07:03:57 +08:00
```yaml
- type: "custom:button-card"
entity: switch.ac
icon: mdi:air-conditioner
color: rgb(28, 128, 199)
state:
2019-04-18 08:30:57 +08:00
- value: "off"
2019-04-18 07:03:57 +08:00
color: rgb(255, 0, 0)
```
2019-04-18 08:30:57 +08:00
---
2018-08-26 23:52:54 +08:00
2018-08-28 08:06:51 +08:00
Show an ON/OFF button for the home_lights group:
2018-09-02 11:31:47 +08:00
2018-09-04 01:38:48 +08:00
![no-icon ](examples/no_icon.png )
2018-09-02 11:31:47 +08:00
2018-08-26 23:52:54 +08:00
```yaml
- type: "custom:button-card"
entity: group.home_lights
2019-04-19 03:12:46 +08:00
show_icon: false
2018-09-02 11:31:47 +08:00
show_state: true
2018-08-26 23:52:54 +08:00
```
2018-08-28 08:06:51 +08:00
2019-04-18 08:30:57 +08:00
---
2018-09-02 11:31:47 +08:00
2018-09-04 01:38:48 +08:00
Light entity with custom icon and "more info" pop-in:
2018-09-02 11:31:47 +08:00
2018-09-04 01:38:48 +08:00
![sofa ](examples/sofa.png )
2018-09-02 11:31:47 +08:00
2018-08-28 08:06:51 +08:00
```yaml
- type: "custom:button-card"
entity: light.living_room_lights
icon: mdi:sofa
2018-09-02 11:31:47 +08:00
color: auto
2019-04-18 07:03:57 +08:00
tap_action:
action: more-info
2018-08-28 08:06:51 +08:00
```
2019-04-18 08:30:57 +08:00
---
2018-09-02 11:31:47 +08:00
Light card with card color type, name, and automatic color:
2018-09-04 01:38:48 +08:00
![color ](examples/color.gif )
2018-09-02 11:31:47 +08:00
```yaml
- type: "custom:button-card"
entity: light._
icon: mdi:home
color: auto
color_type: card
2019-04-18 07:03:57 +08:00
tap_action:
action: more-info
2018-09-02 11:31:47 +08:00
name: Home
2019-05-01 19:40:20 +08:00
styles:
card:
- font-size: 12px
- font-weight: bold
2018-09-02 11:31:47 +08:00
```
2019-04-18 08:30:57 +08:00
---
2018-09-02 11:31:47 +08:00
2018-09-04 01:38:48 +08:00
Horizontal stack with :
2018-09-02 11:31:47 +08:00
2019-04-18 08:30:57 +08:00
- 2x blank cards
- 1x volume up button with service call
- 1x volume down button with service call
- 2x blank cards
2018-09-02 11:31:47 +08:00
2019-04-18 08:30:57 +08:00
![volume ](examples/volume.png )
2018-09-02 11:31:47 +08:00
```yaml
- type: horizontal-stack
cards:
- type: "custom:button-card"
2018-09-04 01:38:48 +08:00
color_type: blank-card
- type: "custom:button-card"
color_type: blank-card
- type: "custom:button-card"
2018-09-02 11:31:47 +08:00
color_type: card
2018-09-04 01:38:48 +08:00
color: rgb(223, 255, 97)
icon: mdi:volume-plus
2019-04-18 07:03:57 +08:00
tap_action:
2019-04-26 23:54:55 +08:00
action: call-service
2019-04-18 07:03:57 +08:00
service: media_player.volume_up
service_data:
2018-09-04 01:38:48 +08:00
entity_id: media_player.livimg_room_speaker
2018-09-02 11:31:47 +08:00
- type: "custom:button-card"
2018-09-04 01:38:48 +08:00
color_type: card
color: rgb(223, 255, 97)
icon: mdi:volume-minus
2019-04-18 07:03:57 +08:00
tap_action:
2019-04-26 23:54:55 +08:00
action: call-service
2019-04-18 07:03:57 +08:00
service: media_player.volume_down
service_data:
2018-09-04 01:38:48 +08:00
entity_id: media_player.livimg_room_speaker
2018-09-02 11:31:47 +08:00
- type: "custom:button-card"
2018-09-04 01:38:48 +08:00
color_type: blank-card
2018-09-02 11:31:47 +08:00
- type: "custom:button-card"
2018-09-04 01:38:48 +08:00
color_type: blank-card
2018-09-02 11:31:47 +08:00
```
2019-04-18 08:30:57 +08:00
---
2018-10-09 22:08:39 +08:00
Vertical Stack with :
2019-04-18 08:30:57 +08:00
- 1x label card
- Horizontal Stack with :
- 1x Scene 1 Button
- 1x Scene 2 Button
- 1x Scene 3 Button
- 1x Scene 4 Button
- 1x Scene Off Button
2018-10-09 22:08:39 +08:00
2019-04-18 08:30:57 +08:00
![scenes ](examples/scenes.png )
2018-10-09 22:08:39 +08:00
```yaml
- type: vertical-stack
cards:
- type: "custom:button-card"
color_type: label-card
color: rgb(44, 109, 214)
name: Kitchen
- type: horizontal-stack
cards:
- type: "custom:button-card"
entity: switch.kitchen_scene_1
color_type: card
color: rgb(66, 134, 244)
icon: mdi:numeric-1-box-outline
- type: "custom:button-card"
entity: switch.kitchen_scene_2
color_type: card
color: rgb(66, 134, 244)
icon: mdi:numeric-2-box-outline
- type: "custom:button-card"
entity: switch.kitchen_scene_3
color_type: card
color: rgb(66, 134, 244)
icon: mdi:numeric-3-box-outline
- type: "custom:button-card"
entity: switch.kitchen_scene_4
color_type: card
color: rgb(66, 134, 244)
icon: mdi:numeric-4-box-outline
- type: "custom:button-card"
entity: switch.kitchen_off
color_type: card
color: rgb(66, 134, 244)
icon: mdi:eye-off-outline
```
2019-01-15 04:09:31 +08:00
### Configuration with states
2019-04-18 08:30:57 +08:00
2019-01-15 04:09:31 +08:00
Input select card with select next service and custom color and icon for states. In the example below the icon `mdi:cube-outline` will be used when value is `sleeping` and `mdi:cube` in other cases.
2018-10-16 10:58:20 +08:00
![cube ](examples/cube.png )
2019-04-13 23:07:02 +08:00
#### Default behavior
2019-04-18 08:30:57 +08:00
2019-04-18 07:03:57 +08:00
If you don't specify any operator, `==` will be used to match the current state against the `value`
2019-04-18 08:30:57 +08:00
2018-10-16 10:58:20 +08:00
```yaml
2019-04-18 07:03:57 +08:00
- type: "custom:button-card"
entity: input_select.cube_mode
icon: mdi:cube
tap_action:
2019-04-26 23:54:55 +08:00
action: call-service
2019-04-18 23:16:36 +08:00
service: input_select.select_next
service_data:
entity_id: input_select.cube_mode
2019-04-18 07:03:57 +08:00
show_state: true
state:
2019-04-18 08:30:57 +08:00
- value: "sleeping"
2019-04-18 07:03:57 +08:00
color: var(--disabled-text-color)
icon: mdi:cube-outline
2019-04-18 08:30:57 +08:00
- value: "media"
2019-04-18 07:03:57 +08:00
color: rgb(5, 147, 255)
2019-04-18 08:30:57 +08:00
- value: "light"
2019-04-18 07:03:57 +08:00
color: rgb(189, 255, 5)
2018-10-16 10:58:20 +08:00
```
2019-04-13 23:07:02 +08:00
#### With Operator on state
2019-04-18 08:30:57 +08:00
2019-04-13 23:07:02 +08:00
The definition order matters, the first item to match will be the one selected.
2019-04-18 08:30:57 +08:00
2019-04-13 23:07:02 +08:00
```yaml
2019-04-18 07:03:57 +08:00
- type: "custom:button-card"
entity: sensor.temperature
show_state: true
state:
- value: 15
operator: '< ='
color: blue
icon: mdi:thermometer-minus
- value: 25
operator: '>='
color: red
icon: mdi:thermometer-plus
- operator: 'default' # used if nothing matches
color: yellow
icon: mdi: thermometer
2019-05-01 19:40:20 +08:00
styles:
card:
- opacity: 0.5
2019-04-13 23:07:02 +08:00
```
2019-04-19 14:22:39 +08:00
#### `tap_action` Navigate
2019-04-18 08:30:57 +08:00
2019-04-19 14:22:39 +08:00
Buttons can link to different views using the `navigate` action:
2019-04-18 08:30:57 +08:00
2019-04-18 07:03:57 +08:00
```yaml
- type: "custom:button-card"
color_type: label-card
icon: mdi:home
name: Go To Home
tap_action:
2019-04-19 14:22:39 +08:00
action: navigate
2019-04-18 07:03:57 +08:00
navigation_path: /lovelace/0
```
2018-09-02 11:31:47 +08:00
2019-04-19 14:22:39 +08:00
The `navigation_path` also accepts any Home Assistant internal URL such as /dev-info or /hassio/dashboard for example.
2019-04-18 07:03:57 +08:00
#### blink
2019-04-18 08:30:57 +08:00
2019-04-18 07:03:57 +08:00
You can make the whole button blink:
2019-04-20 12:44:35 +08:00
2019-04-18 07:03:57 +08:00
![blink-animation ](examples/blink-animation.gif )
2019-04-18 08:30:57 +08:00
2019-04-18 07:03:57 +08:00
```yaml
- type: "custom:button-card"
color_type: card
entity: binary_sensor.intruder
name: Intruder Alert
state:
2019-04-18 08:30:57 +08:00
- value: "on"
2019-04-18 07:03:57 +08:00
color: red
icon: mdi:alert
2019-05-01 19:40:20 +08:00
styles:
card:
- animation: blink 2s ease infinite
2019-04-18 07:03:57 +08:00
- operator: default
color: green
icon: mdi:shield-check
```
2018-09-02 11:31:47 +08:00
2019-04-29 16:50:13 +08:00
### Play with width, height and icon size
Through the `styles` you can specify the `width` and `height` of the card, and also the icon size through the main `size` option. Playing with icon size will growth the card unless a `height` is specified.
If you specify a width for the card, it has to be in `px` . All the cards without a `width` defined will use the remaining space on the line.
![height-width ](examples/width_height.png )
```yaml
- type: horizontal-stack
cards:
- type: "custom:button-card"
entity: light.test_light
color: auto
name: s:default h:200px
2019-05-01 19:40:20 +08:00
styles:
card:
- height: 200px
2019-04-29 16:50:13 +08:00
- type: "custom:button-card"
entity: light.test_light
color_type: card
color: auto
name: s:100% h:200px
size: 100%
2019-05-01 19:40:20 +08:00
styles:
card:
- height: 200px
2019-04-29 16:50:13 +08:00
- type: "custom:button-card"
entity: light.test_light
color_type: card
color: auto
size: 10%
name: s:10% h:200px
2019-05-01 19:40:20 +08:00
styles:
card:
- height: 200px
2019-04-29 16:50:13 +08:00
- type: horizontal-stack
cards:
- type: "custom:button-card"
entity: light.test_light
color: auto
name: 60px
2019-05-01 19:40:20 +08:00
styles:
card:
- height: 60px
- width: 60px
2019-04-29 16:50:13 +08:00
- type: "custom:button-card"
entity: light.test_light
color_type: card
color: auto
name: 80px
2019-05-01 19:40:20 +08:00
styles:
card:
- height: 80px
- width: 30px
2019-04-29 16:50:13 +08:00
- type: "custom:button-card"
entity: light.test_light
color_type: card
color: auto
name: 300px
2019-05-01 19:40:20 +08:00
styles:
card:
- height: 300px
2019-04-29 16:50:13 +08:00
```
2019-04-30 00:44:04 +08:00
### Templates Support
#### Playing with label templates
![label_template ](examples/labels.png )
```yaml
- type: "custom:button-card"
color_type: icon
entity: light.test_light
label_template: >
var bri = states['light.test_light'].attributes.brightness;
return 'Brightness: ' + (bri ? bri : '0') + '%';
show_label: true
size: 15%
2019-05-01 19:40:20 +08:00
styles:
card:
- height: 100px
2019-04-30 00:44:04 +08:00
- type: "custom:button-card"
color_type: icon
entity: light.test_light
layout: icon_label
label_template: >
return 'Other State: ' + states['switch.skylight'].state;
show_label: true
show_name: false
2019-05-01 19:40:20 +08:00
styles:
card:
- height: 100px
2019-04-30 00:44:04 +08:00
```
#### State Templates
The javascript code inside `value` needs to return `true` of `false` .
Example with `template` :
```yaml
- type: "custom:button-card"
color_type: icon
entity: switch.skylight
show_state: true
show_label: true
state:
- operator: template
value: >
return states['light.test_light'].attributes
& & (states['light.test_light'].attributes.brightness < = 100)
icon: mdi:alert
- operator: default
icon: mdi:lightbulb
- type: "custom:button-card"
color_type: icon
entity: light.test_light
show_label: true
state:
- operator: template
value: >
return states['input_select.light_mode'].state === 'night_mode'
icon: mdi:weather-night
label: Night Mode
- operator: default
icon: mdi:white-balance-sunny
label: Day Mode
```
2019-04-29 16:50:13 +08:00
2019-05-01 19:40:20 +08:00
### Styling
![per-style-config ](examples/per-style-config.gif )
```yaml
- type: "custom:button-card"
color_type: icon
entity: light.test_light
label_template: >
var bri = states['light.test_light'].attributes.brightness;
return 'Brightness: ' + (bri ? bri : '0') + '%';
show_label: true
show_state: true
size: 10%
styles:
card:
- height: 100px
label:
- color: gray
- font-size: 9px
- justify-self: start
- padding: 0px 5px
name:
- text-transform: uppercase
- letter-spacing: 0.5em
- font-familly: cursive
- justify-self: start
- padding: 0px 5px
state:
- justify-self: start
- font-size: 10px
- padding: 0px 5px
state:
- value: 'on'
styles:
state:
- color: green
- value: 'off'
styles:
state:
- color: red
card:
- filter: brightness(40%)
- type: "custom:button-card"
color_type: icon
entity: light.test_light
layout: icon_label
label_template: >
return 'Other State: ' + states['switch.skylight'].state;
show_label: true
show_name: false
size: 100%
styles:
card:
- height: 200px
label:
- font-weight: bold
- writing-mode: vertical-rl
- text-orientation: mixed
state:
- value: 'on'
styles:
label:
- color: red
- value: 'off'
styles:
label:
- color: green
```
2019-05-04 19:20:33 +08:00
### Lock
![lock-animation ](examples/lock.gif )
```yaml
- type: horizontal-stack
cards:
- type: "custom:button-card"
entity: switch.test
lock: true
- type: "custom:button-card"
color_type: card
lock: true
color: black
entity: switch.test
```
2019-05-24 18:54:42 +08:00
### Aspect Ratio
![aspect-ratio-image ](examples/aspect_ratio.png )
```yaml
- type: vertical-stack
cards:
- type: horizontal-stack
cards:
- type: custom:button-card
name: 1/1
icon: mdi:lightbulb
aspect_ratio: 1/1
- type: custom:button-card
name: 2/1
icon: mdi:lightbulb
aspect_ratio: 2/1
- type: custom:button-card
name: 3/1
icon: mdi:lightbulb
aspect_ratio: 3/1
- type: custom:button-card
name: 4/1
icon: mdi:lightbulb
aspect_ratio: 4/1
- type: horizontal-stack
cards:
- type: custom:button-card
name: 1/1.2
icon: mdi:lightbulb
aspect_ratio: 1/1.2
- type: custom:button-card
name: 1/1.3
icon: mdi:lightbulb
aspect_ratio: 1/1.3
- type: custom:button-card
name: 1/1.4
icon: mdi:lightbulb
aspect_ratio: 1/1.4
- type: custom:button-card
name: 1/1.5
icon: mdi:lightbulb
aspect_ratio: 1/1.5
```
2018-08-28 08:06:51 +08:00
## Credits
2019-04-18 08:30:57 +08:00
- [ciotlosm ](https://github.com/ciotlosm ) for the readme template and the awesome examples
2019-02-24 04:55:19 +08:00
2019-02-26 10:30:02 +08:00
[commits-shield]: https://img.shields.io/github/commit-activity/y/custom-cards/button-card.svg?style=for-the-badge
2019-02-24 04:55:19 +08:00
[commits]: https://github.com/custom-cards/button-card/commits/master
[discord]: https://discord.gg/Qa5fW2R
2019-03-17 04:18:30 +08:00
[discord-shield]: https://img.shields.io/discord/330944238910963714.svg?style=for-the-badge
2019-02-26 10:30:02 +08:00
[forum-shield]: https://img.shields.io/badge/community-forum-brightgreen.svg?style=for-the-badge
2019-02-24 04:55:19 +08:00
[forum]: https://community.home-assistant.io/t/lovelace-button-card/65981
2019-02-26 10:30:02 +08:00
[license-shield]: https://img.shields.io/github/license/custom-cards/button-card.svg?style=for-the-badge
2019-03-17 04:18:30 +08:00
[maintenance-shield]: https://img.shields.io/maintenance/yes/2019.svg?style=for-the-badge
2019-02-26 10:30:02 +08:00
[releases-shield]: https://img.shields.io/github/release/custom-cards/button-card.svg?style=for-the-badge
2019-02-24 04:55:19 +08:00
[releases]: https://github.com/custom-cards/button-card/releases