Header Cards - add badges and cards to the header

I was looking for a way to add cards into the header of a Lovelace dashboard, and had tried various ways of hacking this by using card-mod to move the card, but nothing quite worked.

So I ended up creating Header Cards

You can install this manually, or via HACS (by adding it as a custom repository currently, haven’t got it added to the standard ones yet - it has now been added to the standard repos).

You put the config at the top of the dashboard, similar to kiosk-mode, so it would look something like:

header_cards:
  badges:
    - entity: binary_sensor.motion_trigger
      name: ''
  cards:
    - type: markdown
      content: |
        Hello it is {{ states("sensor.time") }}
views:
...

Which would give you something like this at the right-shand side of the toolbar:

image

This seems to work particularly well with Mushroom (particularly the chips card), like this:

header_cards:
  cards:
    - type: custom:mushroom-chips-card
      chips:
        - type: weather
          entity: weather.dark_sky
          show_conditions: true
          show_temperature: true

will give

image

Note: Some cards may be a bit big for the toolbar, but you can use card-mod to tweak them to make them fit, with something like:

header_cards:
  cards:
    - type: 'some-big-card'
      style: |
        :host {
          transform: scale(0.75);
        }

Badges also currently display better if you remove the label by setting name to an empty string (I may be able to improve this in a future release).

8 Likes

Great card, I love it. Thank you for this work

Hi,
I had 2 times errors in the logs.

2022-03-05 06:43:59 ERROR (MainThread) [frontend.js.latest.202203010] https://homeassistant.local:8123/hacsfiles/lovelace-header-cards/lovelace-header-cards.js?hacstag=466196192002:1:3348 Uncaught TypeError: Cannot read properties of null (reading 'state')
Logger: frontend.js.latest.202203010
Source: components/system_log/__init__.py:190
First occurred: 08:11:14 (3 occurrences)
Last logged: 08:51:43

https://homeassistant.local:8123/hacsfiles/lovelace-header-cards/lovelace-header-cards.js?hacstag=466196192002:1:1603 Uncaught TypeError: Cannot read properties of undefined (reading 'addCardsToHeader')
header_cards:
  cards:
    - type: custom:mushroom-chips-card
      chips:
        - type: weather
          entity: weather.*********
          show_conditions: true
          show_temperature: true
        - type: entity
          entity: sensor.**********_wind_speed
          icon_color: blue-grey
        - type: entity
          entity: sun.sun
          icon_color: blue-grey
        - type: entity
          entity: sensor.moon
          icon_color: blue-grey

It looks like somehow there is a stage change being fired on your system with no new state.
I’ve just published a new version, 0.0.3, which includes additional null checks around this.
Can you please give that a go and let me know if it works for you?

Ok, I will try and let you know.

Logger: frontend.js.latest.202203010
Source: components/system_log/__init__.py:190
First occurred: 12:50:47 (2 occurrences)
Last logged: 12:52:12

https://homeassistant.local:8123/hacsfiles/lovelace-header-cards/lovelace-header-cards.js?hacstag=466196192003:1:285 Uncaught TypeError: Cannot read properties of undefined (reading 'addCardsToHeader')

if i refresh chrome from logs page and come back in my lovelace homepage. The chips do not appear, I refresh the page and it appears but there is an error.

It looks like there was an issue when reloading from a non-Lovelace page (e.g. config pages, Logbook, etc.). I’ve just released version 0.0.4, which fixes this. Can you please update and try again?

1 Like

it’s good, no more errors.
the header cards aren’t showing on my phone or tablet by home assistant companion. Is this normal?

Do you have the same Lovelace dashboard on the phone and tablet as on your desktop?
The config for this is per-dashboard so you will need to update all dashboards to include this.

If you have updated the phone and tablet dashboards, you may need to clear cache or reload in the app as it may be picking up an old version.

Also, particularly on phones, the width of the toolbar may be too narrow to fit the cards.
I have found that, on my phone (with the Android HA app), the most I can fit is probably around 3 tabs and one weather chip.

On my iPad (with the iOS HA app) in landscape mode I haven’t had any problems with fitting the cards in the header.

Thank you for the information, it works on my phone and tablet by emptying the cache :slight_smile:

It’s now been added to the standard repositories in HACS, so no need to add it as a custom repository now.

I have now released a new version, 0.0.7, which includes a justify_content option allowing control over the layout of the badges and cards.
This accepts any value supported by the justify-content CSS property.

2 Likes

Hi, would this work for a mobile theme back, home button in the header?

I’ve added:

header_cards:
  justify_content: left
  replace_tabs: true
  cards:
    - type: button
      name: ''
      icon: mdi:backspace
      icon_height: 30px
      tap_action:
        action: navigate
        navigation_path: /lovelace-mobile/0

to mine and do get a modestly sized button on Edge.
But in the HA companion app for IOS I get the following.

The other really big left arrow, was my my first iteration before I found our you could change the headers.

This looks like an issue with how the iOS app is applying styling.

If you have card-mod installed, you can work around it like this:

header_cards:
  justify_content: left
  replace_tabs: true
  cards:
    - type: button
      name: ''
      icon: mdi:backspace
      icon_height: 30px
      tap_action:
        action: navigate
        navigation_path: /lovelace-mobile/0
      style: |
        ha-card {
          width: 60px;
          background: rgba(0,0,0,0);
          box-shadow: none!important;
        }

This makes the card narrower and makes the card background transparent and removes any box shadow, so the header colour shows through.

thanks, I will look at what card_mod is how how to run that as well.

Here’s a link to the repository for card-mod if you need it:

Is this project still working with the latest version of Home assistant?
Installed and tried the following but it has no effect on the header.
The chip does work as a standalone card on the dashboard.

header_cards:
  justify_content: space-between
  cards:
    type: custom:mushroom-chips-card
    chips:
      - type: weather
        entity: weather.openweathermap
        show_conditions: true
        show_temperature: true