navbar-card

repository·main·Indexed 21 days ago

https://github.com/joseluis9595/lovelace-navbar-card

A custom Home Assistant Lovelace card providing a responsive, Material Design-inspired navigation interface for dashboards. Version 1.6.1 features include configurable routes, desktop and mobile layout settings, haptic feedback, auto-padding to prevent UI overlaps, and a media player widget with carousel support and dynamic entity selection via JSTemplate.

Tokens
17.4K
Snippets
53
Records
71
Agent score
72%

What's inside navbar-card

  1. Available Context Variables in JavaScript Templates

    main

    When writing JavaScript templates, you have access to four predefined global variables:

    VariableDescription
    statesGlobal state of all Home Assistant entities
    userInformation about the current Home Assistant user
    hassThe Home Assistant instance object
    navbarInternal state of the Navbar card (e.g., device type)

    Use these variables to drive logic, such as checking entity states, user permissions, or whether the user is on a desktop device.

  2. Override template properties in a navbar-card

    main

    Properties defined directly within a navbar-card instance take priority over those inherited from the template. This allows you to use a standard template while applying specific overrides (such as custom CSS styles) to individual cards.

    For example, you can use a template but override the primary color using the styles property.

    type: custom:navbar-card
    template: your_template_name
    styles: |
      .navbar {
        --navbar-primary-color: red;
      }
  3. Configure the Media Player widget

    main

    The media_player configuration enables a widget that displays media playback information above or alongside the navbar.

    Key Behaviors:

    • Visibility: The widget automatically appears when any configured player is in a playing or paused state. You can override this using the show option.
    • Multiple Players: If you provide multiple players in the players array, the widget renders as a carousel with dot indicators and supports swipe/drag navigation.
    • Desktop vs. Mobile: On desktop, you can specify the position using desktop_position. On mobile, the widget is always displayed at the bottom of the view.
    media_player:
      players:
        - entity: media_player.living_room
  4. Customize appearance with CSS

    main

    You can customize the Navbar Card's appearance using two methods:

    1. CSS Variables: Use these to modify predefined theme properties like colors and border radii.
    2. Direct CSS: Use this to apply custom styles to specific classes like .navbar-card or .navbar.

    Both methods are applied via the styles key.

    # Using CSS Variables
    type: custom:navbar-card
    styles: |
      .navbar {
        --navbar-primary-color: #4CAF50;
        --navbar-border-radius: 16px;
      }
    
    # Using Direct CSS
    type: custom:navbar-card
    styles: |
      .navbar-card {
        background: rgba(0,0,0,0.7);
        backdrop-filter: blur(10px);
      }
  5. Define navbar templates in Lovelace YAML

    main

    Templates must be defined under the navbar-templates key at the top level of your dashboard's Raw Configuration Editor.

    Steps to add a template:

    1. Open your dashboard.
    2. Click the three dots menu (⋮) in the top right.
    3. Select "Edit Dashboard".
    4. Click the three dots menu (⋮) again.
    5. Select "Raw Configuration Editor".
    6. Add your navbar-templates block at the very top of the file.
    navbar-templates:
      my_template:
        desktop:
          show_labels: true
        mobile:
          show_labels: false
        routes:
          - icon: mdi:home
            url: /lovelace/home
            label: Home
    views:
      # Your normal lovelace configuration
      ...
  6. Manage dashboard padding with automatic padding

    main

    To prevent the navbar-card from overlapping with other dashboard cards, use the automatic padding feature. This feature is enabled by default and automatically adjusts padding based on the navbar's position (top, bottom, left, or right) and device type (desktop vs. mobile).

    Key behaviors:

    • Desktop: Adds padding relative to the desktop.position setting.
    • Mobile: Adds bottom padding to prevent overlap with bottom-docked navbars.
    • Media player widget: If a media player widget is visible, you can specify extra padding using layout.auto_padding.media_player_px to ensure both the navbar and media player remain clear of dashboard cards.
    type: custom:navbar-card
    layout:
      auto_padding:
        enabled: true
        media_player_px: 80 # Example value for media player clearance
  7. Configure Popup Menus for Routes

    main

    A popup menu allows you to group multiple routes under a single navbar item. To trigger a popup, you must use the open-popup action within either a tap_action or a hold_action on the parent route.

    Popup Item Configuration: Popup items share many properties with standard routes, including url, icon, image, badge, label, selected, and custom actions.

    Dynamic Popups with JSTemplate: You can use JSTemplate to dynamically generate popup items based on your Home Assistant state (e.g., generating a list of rooms from your configured areas).

    Example: Dynamic Area Popup This example creates a 'Rooms' route that, when tapped, opens a popup containing all areas defined in Home Assistant:

    - icon: mdi:sofa-outline
      icon_selected: mdi:sofa
      label: Rooms
      tap_action: { action: open-popup }
      popup: |
        [[[
          return Object.values(hass.areas).map(area => ({
            label: area.name,
            url: "/d-bubble/home#" + area.area_id,
            icon: area.icon
          }));
        ]]]
  8. Define reusable navbar templates

    main

    You can predefine custom configurations for navbar-card using the navbar-templates key in your dashboard's YAML configuration. This allows you to reuse the same navigation structure across multiple dashboards and update them all at once by modifying a single template.

    To define templates, open your dashboard, select "Edit YAML" from the menu, and add a navbar-templates section at the top level of your configuration.

    navbar-templates:
       your_template_name:
          routes:
             - label: Home
               icon: mdi:home
               url: /lovelace/home
             - label: Settings
               icon: mdi:cog
               url: /lovelace/settings
    
    views:
      - title: Home
        cards: ...
  9. Hide native Home Assistant tabs using card-mod

    main

    To create a cleaner look, you can hide the native Home Assistant ha-tabs element while keeping the edit, search, and assist buttons visible. This requires using card-mod within a custom Home Assistant theme.

    The CSS selector required depends on your Home Assistant version.

    ### For Home Assistant < 2025.0
    ```yaml
    your_theme:
      app-header-background-color: transparent
      app-header-text-color: var(--primary-text-color)
    
      card-mod-theme: your_theme
      card-mod-root-yaml: |
        .: |
          ha-tabs {
            pointer-events: none;
            opacity: 0;
          }

    For Home Assistant between 2025.0 and 2025.9

    your_theme:
      app-header-background-color: transparent
      app-header-text-color: var(--primary-text-color)
    
      card-mod-theme: your_theme
      card-mod-root-yaml: |
        .: |
          .toolbar > sl-tab-group {
            pointer-events: none;
            opacity: 0;
          }

    For Home Assistant ≥ 2025.10

    your_theme:
      app-header-background-color: transparent
      app-header-text-color: var(--primary-text-color)
    
      card-mod-theme: your_theme
      card-mod-root-yaml: |
        .: |
          .toolbar > ha-tab-group {
            pointer-events: none;
            opacity: 0;
          }