Home

Awesome

Lovelace Mini Graph Card

A minimalistic and customizable graph card for Home Assistant Lovelace UI.

The card works with entities from within the sensor & binary_sensor domain and displays the sensors current state as well as a line graph representation of the history.

Preview

Install

HACS (recommended)

This card is available in HACS (Home Assistant Community Store). <small>HACS is a third party community store and is not included in Home Assistant out of the box.</small>

Manual install

  1. Download and copy mini-graph-card-bundle.js from the latest release into your config/www directory.

  2. Add the resource reference as decribed below.

CLI install

  1. Move into your config/www directory.

  2. Grab mini-graph-card-bundle.js:

$ wget https://github.com/kalkih/mini-graph-card/releases/download/v0.12.1/mini-graph-card-bundle.js
  1. Add the resource reference as decribed below.

Add resource reference

If you configure Lovelace via YAML, add a reference to mini-graph-card-bundle.js inside your configuration.yaml:

resources:
  - url: /local/mini-graph-card-bundle.js?v=0.12.1
    type: module

Else, if you prefer the graphical editor, use the menu to add the resource:

  1. Make sure, advanced mode is enabled in your user profile (click on your user name to get there)
  2. Navigate to Configuration -> Lovelace Dashboards -> Resources Tab. Hit orange (+) icon
  3. Enter URL /local/mini-graph-card-bundle.js and select type "JavaScript Module". (Use /hacsfiles/mini-graph-card/mini-graph-card-bundle.js and select "JavaScript Module" for HACS install)
  4. Restart Home Assistant.

Updating

If you have a version older than v0.0.8 installed, please delete the current files and follow the installation instructions again.

  1. Find your mini-graph-card-bundle.js file in config/www or wherever you ended up storing it.

  2. Replace the local file with the latest one attached in the latest release.

  3. Add the new version number to the end of the cards reference url in your ui-lovelace.yaml like below:

resources:
  - url: /local/mini-graph-card-bundle.js?v=0.12.1
    type: module

You may need to empty the browsers cache if you have problems loading the updated card.

Using the card

We recommend looking at the Example usage section to understand the basics to configure this card. (also) pay attention to the required options mentioned below.

Options

Card options

NameTypeDefaultSinceDescription
type (required)stringv0.0.1custom:mini-graph-card.
entities (required)listv0.2.0One or more sensor entities in a list, see entities object for additional entity options.
iconstringv0.0.1Set a custom icon from any of the available mdi icons.
icon_imagestringv0.12.0Override icon with an image url
namestringv0.0.1Set a custom name which is displayed beside the icon.
unitstringv0.0.1Set a custom unit of measurement.
tap_actionaction objectv0.7.0Action on click/tap.
groupbooleanfalsev0.2.0Disable paddings and box-shadow, useful when nesting the card.
hours_to_showinteger24v0.0.2Specify how many hours of history the graph should present.
points_per_hournumber0.5v0.2.0Specify amount of data points the graph should display for each hour, (basically the detail/accuracy/smoothing of the graph).
aggregate_funcstringavgv0.8.0Specify aggregate function used to calculate point/bar in the graph.
group_bystringintervalv0.8.0Specify type of grouping of data, dynamic interval, date or hour.
update_intervalnumberv0.4.0Specify a custom update interval of the history data (in seconds), instead of on every state change.
cachebooleantruev0.9.0Enable/disable local caching of history data.
showlistv0.2.0List of UI elements to display/hide, for available items see available show options.
animatebooleanfalsev0.2.0Add a reveal animation to the graph.
heightnumber150v0.0.1Set a custom height of the line graph.
bar_spacingnumber4v0.9.0Set the spacing between bars in bar graph.
line_widthnumber5v0.0.1Set the thickness of the line.
line_colorstring/listvar(--accent-color)v0.0.1Set a custom color for the graph line, provide a list of colors for multiple graph entries.
color_thresholdslistv0.2.3Set thresholds for dynamic graph colors, see Line color object.
color_thresholds_transitionstringsmoothv0.4.3Color threshold transition, smooth or hard.
decimalsintegerv0.0.9Specify the exact number of decimals to show for states.
hour24booleanfalsev0.2.1Set to true to display times in 24-hour format.
font_sizenumber100v0.0.3Adjust the font size of the state, as percentage of the original size.
font_size_headernumber14v0.3.1Adjust the font size of the header, size in pixels.
align_headerstringdefaultv0.2.0Set the alignment of the header, left, right, center or default.
align_iconstringrightv0.2.0Set the alignment of the icon, left, right or state.
align_statestringleftv0.2.0Set the alignment of the current state, left, right or center.
lower_boundnumber or stringv0.2.3Set a fixed lower bound for the graph Y-axis. String value starting with ~ (e.g. ~50) specifies soft bound.
upper_boundnumber or stringv0.2.3Set a fixed upper bound for the graph Y-axis. String value starting with ~ (e.g. ~50) specifies soft bound.
min_bound_rangenumberv0.x.xApplied after everything, makes sure there's a minimum range that the Y-axis will have. Useful for not making small changes look large because of scale.
lower_bound_secondarynumber or stringv0.5.0Set a fixed lower bound for the graph secondary Y-axis. String value starting with ~ (e.g. ~50) specifies soft bound.
upper_bound_secondarynumber or stringv0.5.0Set a fixed upper bound for the graph secondary Y-axis. String value starting with ~ (e.g. ~50) specifies soft bound.
min_bound_range_secondarynumberv0.x.xApplied after everything, makes sure there's a minimum range that the secondary Y-axis will have. Useful for not making small changes look large because of scale.
smoothingbooleantruev0.8.0Whether to make graph line smooth.
state_mapstate map objectv0.8.0List of entity states to convert (order matters as position becomes a value on the graph).
value_factornumber0v0.9.4Scale value by order of magnitude (e.g. convert Watts to kilo Watts), use negative value to scale down.
logarithmicbooleanfalsev0.10.0Use a Logarithmic scale for the graph

Entities object

Entities may be listed directly (as per sensor.temperature in the example below), or defined using properties of the Entity object detailed in the following table (as per sensor.pressure in the example below).

NameTypeDefaultDescription
entity (required)stringEntity id of the sensor.
attributestringRetrieves an attribute or sub-attribute (attr1.attr2...) instead of the state
namestringSet a custom display name, defaults to entity's friendly_name.
colorstringSet a custom color, overrides all other color options including thresholds.
unitstringSet a custom unit of measurement, overrides unit set in base config.
aggregate_funcstringOverride for aggregate function used to calculate point on the graph, avg, median, min, max, first, last, sum.
show_statebooleanDisplay the current state.
show_indicatorbooleanDisplay a color indicator next to the state, (only when more than two states are visible).
show_graphbooleanSet to false to completely hide the entity in the graph.
show_linebooleanSet to false to hide the line.
show_fillbooleanSet to false to hide the fill.
show_pointsbooleanSet to false to hide the points.
show_legendbooleanSet to false to turn hide from the legend.
state_adaptive_colorbooleanMake the color of the state adapt to the entity color.
y_axisstringIf 'secondary', displays using the secondary y-axis on the right.
fixed_valuebooleanSet to true to graph the entity's current state as a fixed value instead of graphing its state history.
smoothingbooleanOverride for a flag indicating whether to make graph line smooth.
entities:
  - sensor.temperature
  - entity: sensor.pressure
    name: Pressure
    show_state: true
  - sensor.humidity

Available show options

All properties are optional.

NameDefaultOptionsDescription
nametruetrue / falseDisplay name.
icontruetrue / falseDisplay icon.
statetruetrue / false / lastDisplay current state. last will show the last graph point's value.
graphlineline / bar / falseDisplay option for the graph. If set to bar a maximum of 96 bars will be displayed.
filltruetrue / false / fadeDisplay the line graph fill.
pointshovertrue / false / hoverDisplay graph data points.
legendtruetrue / falseDisplay the graph legend (only shown when graph contains multiple entities).
averagefalsetrue / falseDisplay average information.
extremafalsetrue / falseDisplay max/min information.
labelshovertrue / false / hoverDisplay Y-axis labels.
labels_secondaryhovertrue / false / hoverDisplay secondary Y-axis labels.
name_adaptive_colorfalsetrue / falseMake the name color adapt with the primary entity color.
icon_adaptive_colorfalsetrue / falseMake the icon color adapt with the primary entity color.

Line color object

See dynamic line color for example usage.

NameTypeDefaultDescription
value (required except in interpolation (see below))numberThe threshold for the color stop.
color (required)stringColor in 6 digit hex format (e.g. #008080).
Line color interpolation of stop values

As long as the first and last threshold stops have value properties, intermediate stops can exclude value; they will be interpolated linearly. For example, given stops like:

color_thresholds:
  - value: 0
    color: "#ff0000"
  - color: "#ffff00"
  - color: "#00ff00"
  - value: 4
    color: "#0000ff"

The values will be interpolated as:

color_thresholds:
  - value: 0
    color: "#ff0000"
  - value: 1.333333
    color: "#ffff00"
  - value: 2.666667
    color: "#00ff00"
  - value: 4
    color: "#0000ff"

The example above will result in the following colors of the graph: if value is

As a shorthand, you can just use a color string for the stops that you want interpolated:

  - value: 0
    color: "#ff0000"
  - "#ffff00"
  - "#00ff00"
  - value: 4
    color: "#0000ff"

Action object options

NameTypeDefaultOptionsDescription
actionstringmore-infomore-info / navigate / call-service / url / noneAction to perform.
entitystringAny entity idOverride default entity of more-info, when action is defined as more-info.
servicestringAny serviceService to call (e.g. media_player.toggle) when action is defined as call-service.
service_dataobjectAny service dataService data to include with the service call (e.g. entity_id: media_player.office).
navigation_pathstringAny pathPath to navigate to (e.g. /lovelace/0/) when action is defined as navigate.
urlstringAny URLURL to open when action is defined as url.

State map object

NameTypeDefaultDescription
value (required)stringValue to convert.
labelstringsame as valueString to show as label (if the value is not precise).

Aggregate functions

Recorded values are grouped in time buckets which are determined by group_by, points_per_hour configuration. These buckets are converted later to single point/bar on the graph. Aggregate function defines the methods of that conversion.

NameSinceDescription
avgv0.8.0Average
medianv0.11.0Median
minv0.8.0Minimum - lowest value
maxv0.8.0Maximum - largest value
firstv0.9.0
lastv0.9.0
sumv0.9.2
deltav0.9.4Calculates difference between max and min value
diffv0.11.0Calculates difference between first and last value

Theme variables

The following theme variables can be set in your HA theme to customize the appearance of the card.

NameDefaultDescription
mcg-title-letter-spacingLetter spacing of the card title (name option).
mcg-title-font-weight500Font weight of the card title.

Example usage

Single entity card

Single entity card

type: custom:mini-graph-card
entities:
 - sensor.illumination

Alternative style

Alternative style

type: custom:mini-graph-card
entities:
 - sensor.illumination
align_icon: left
align_state: center
show:
  fill: false

Multiple entities card

Multiple entities card

type: custom:mini-graph-card
name: SERVER
icon: mdi:server
entities:
  - entity: sensor.server_total
    name: TOTAL
  - sensor.server_sent
  - sensor.server_received

Bar chart card

Bar chart card

type: custom:mini-graph-card
entities:
  - entity: sensor.energy_consumption
name: ENERGY CONSUMPTION
show:
  graph: bar

Show data from the past week

Show data from the past week

Use the hours_to_show option to specify how many hours of history the graph should represent. Use the points_per_hour option to specify the accuracy/detail of the graph.

type: custom:mini-graph-card
entities:
  - sensor.living_room_temp
name: LIVING ROOM
hours_to_show: 168
points_per_hour: 0.25

Graph only card

Use the show option to show/hide UI elements.

type: custom:mini-graph-card
entities:
  - sensor.humidity
show:
  icon: false
  name: false
  state: false

Horizontally stacked cards

You can stack cards horizontally by using one or more horizontal-stack(s).

Horizontally stacked cards

type: horizontal-stack
cards:
  - type: custom:mini-graph-card
    entities:
      - sensor.humidity
    line_color: blue
    line_width: 8
    font_size: 75
  - type: custom:mini-graph-card
    entities:
      - sensor.illumination
    line_color: '#e74c3c'
    line_width: 8
    font_size: 75
  - type: custom:mini-graph-card
    entities:
      - sensor.temperature
    line_color: var(--accent-color)
    line_width: 8
    font_size: 75

Dynamic line color

Have the graph change line color dynamically.

Dynamic line color

type: custom:mini-graph-card
entities:
  - sensor.sensor_temperature
show:
  labels: true
color_thresholds:
  - value: 20
    color: "#f39c12"
  - value: 21
    color: "#d35400"
  - value: 21.5
    color: "#c0392b"

Alternate y-axis

Have one or more series plot on a separate y-axis, which appears on the right side of the graph. This example also shows turning off the line, points and legend.

Alternate y-axis

type: custom:mini-graph-card
entities:
  - entity: sensor.verandah
    name: Verandah
  - entity: sensor.lounge
    name: Lounge
  - entity: sensor.kitchen
    name: Kitchen
  - color: gray
    entity: input_number.nighttime
    name: Night
    show_line: false
    show_points: false
    show_legend: false
    y_axis: secondary
show:
  labels: true
  labels_secondary: true

Grouping by date

mini_energy_daily

You can group values by date, this way you can visualize for example daily energy consumption.

type: custom:mini-graph-card
entities:
  - entity: sensor.energy_daily
name: Energy consumption
hours_to_show: 168
aggregate_func: max
group_by: date
show:
  graph: bar

Data aggregation functions

You can decide how values are aggregated for points on graph. Example how to display min, max, avg temperature per day from last week.

mini_temperature_aggregate_daily

type: custom:mini-graph-card
entities:
  - entity: sensor.outside_temp
    aggregate_func: max
    name: Max
    color: "#e74c3c"
  - entity: sensor.outside_temp
    aggregate_func: min
    name: Min
  - entity: sensor.outside_temp
    aggregate_func: avg
    name: Avg
    color: green
name: Temp outside daily (last week)
hours_to_show: 168
group_by: date

Non-numeric sensor states

mini_binary_sensor

You can render non-numeric states by providing state_map config. For example this way you can show data coming from binary sensors.

type: custom:mini-graph-card
entities:
  - entity: binary_sensor.living_room_motion
    name: Living room
  - entity: binary_sensor.corridor_motion
    name: Corridor
  - entity: binary_sensor.master_bed_motion
    name: Master bed.
    color: green
  - entity: binary_sensor.bedroom_motion
    name: Bedroom
name: Motion last hour
hours_to_show: 1
points_per_hour: 60
update_interval: 30
aggregate_func: max
line_width: 2
smoothing: false
state_map:
  - value: "off"
    label: Clear
  - value: "on"
    label: Detected

Showing additional info on the card

изображение

It is possible to show a state without displaying a graph for a sensor. Imagine there are two CO-2 sensors & one humidity sensor; graphs are displayed for the CO-2 only, and the humidity is shown as a state only.

type: custom:mini-graph-card
entities:
  - entity: sensor.xiaomi_cg_1_humidity
    show_state: true
    show_graph: false
  - entity: sensor.xiaomi_cg_1_co2
    color: green
    show_state: false
    name: CO2-1
  - entity: sensor.xiaomi_cg_2_co2
    color: orange
    show_state: false
    name: CO2-2
name: Humidity
hours_to_show: 4
points_per_hour: 60
show:
  name: true
  legend: true
  icon: false
  labels: true

This method may be also used to add a calculated value with it's own aggregate_func option.

Accessing attributes in complex structures

When using the attribute option in the entities object, you can access data in structured attributes, such as dictionaries and lists.

Accessing dictionary attributes

Suppose you have data stored inside a dictionary attribute named dict_attribute

dict_attribute:
  value_1: 53
  value_2: 64
  value_3: 72

Such data should be addressed as dict_attribute.sub_attribute:

type: custom:mini-graph-card
entities:
  - entity: sensor.testing_object_data
    attribute: dict_attribute.value_1
    name: value_1 from dictionary attribute

image

Accessing list attributes

Suppose you have data stored inside a list attribute named list_attribute:

list_attribute:
  - value_1: 67
    value_2: 65
    value_3: 93
  - value_1: 134
    value_2: 130
    value_3: 186
  - value_1: 201
    value_2: 195
    value_3: 279

Such data should be addressed as list_attribute.index.sub_attribute:

type: custom:mini-graph-card
entities:
  - entity: sensor.testing_object_data_list
    attribute: list_attribute.0.value_1
    name: value_1 from first element of list attribute

image

Development

  1. Clone this repository into your config/www folder using git:
$ git clone https://github.com/kalkih/mini-graph-card.git
  1. Add a reference to the card in your ui-lovelace.yaml:
resources:
  - url: /local/mini-graph-card/dist/mini-graph-card-bundle.js
    type: module

Instructions

Requires nodejs & npm.

  1. Move into the mini-graph-card repo, checkout the dev branch & install dependencies:
$ cd mini-graph-card && git checkout dev && npm install
  1. Make changes to the source code.

  2. Build the source by running:

$ npm run build
  1. Refresh the browser to see changes.

    Make sure cache is cleared or disabled.

  2. (Optional) Watch the source and automatically rebuild on save:

$ npm run watch

The new mini-graph-card-bundle.js will be build and ready inside /dist.

Note that the dev branch is the most up-to-date and matches our beta releases.

Please refer to the Contribution Guidelines if you're interested in contributing to the project. (And thanks for considering!)

Getting errors?

Make sure you have javascript_version: latest in your configuration.yaml under frontend:.

Make sure you have the latest versions of mini-graph-card.js & mini-graph-lib.js.

If you have issues after updating the card, try clearing your browser cache.

If you have issues displaying the card in older browsers, try changing type: module to type: js at the card reference in ui-lovelace.yaml.

License

This project is under the MIT license.