Custom Energy dashboard and floating date/time selection field

Hi All,

i have create custom energy dashboard. As i would like to go back in time checking the past consumption i would like to mimic the behaviour of type: energy-date-selection which is that bar where you can select the date/time span from the built Energy Dashboard. Is sort of floating there and it is always visible when you scroll down.

I am able to put in in my custom dashboard it is kind of static, staying in one place, so when i scroll down it disappears with the rest of content.

I was looking in the files for the built in energy dashboard but i cannot find to replicate the code.

Does anyone know to make type: energy-date-selection floating and center at the bottom of the screen just like it is on the built in energy dashboard?

I have the same Problem. You can put the Datepicker in the Header Bar using a custom card:

see here:

header_cards:
  justify_content: null
  cards:
    - type: energy-date-selection
      card_mod:
        style: |
          ha-card {
            color: white;
            --ha-card-background: "rgba(30, 30, 30, 0.0)";
            --ha-card-border-width: 0px;
            --ha-card-border-radius: 1px
          }

But I would much prefer it to be floating, like the new one.

Might be related:

You can use Custom:mod-card to place it i.e at the bottom,centered
or other ways, using position and z-index etc

Can you elaborate on this? Thx

Are you using card-mod ?, do you know there is some huge Topics in here in regards to this( Card-Mod ), and as well as documentation in the Cards Github.
If you can’t get it to “linger” anyone or both of you can post your card-code

I’m not sure what exactly you want me to “elaborate” Beside what i mentioned, yes you can use card-mod inside also, choose/set width/height etc

thx @boheme61

Well turned out, this might be tricky, as the date-selection open it’s calendar, down, so you wont see it if it’s “fixed” at the bottom. So you can only uses the forward<>backward button and Now/Compare
So either this “.js function” has to be changed, or you could choose to have the selector at the left or right side or the Graph

Edit: Wait i see the new in Current version, open the calendar up, so they have changed that ( I was testing on the old version ( My “old” Offline HA Install )
So the new version of energy-date-selection should work inside a fixed custom:mod-card , For OP & You if you want it to be fixed, and always visible at the bottom, of screen (Viewport)

As mentioned you can place it anywhere on your screen and it’s fixed there

I got it:

          - type: energy-date-selection
            card_mod:
              style: |
                ha-card {
                  /* Fixierung am unteren Rand */
                  position: fixed !important;
                  bottom: 30px !important;
                  
                  /* Zentrierung unter BerĂĽcksichtigung der Sidebar */
                  left: calc(50% + var(--mdc-drawer-width, 0px) / 2) !important;
                  transform: translateX(-50%) !important;
                  
                  /* Dimensionen */
                  width: auto !important;
                  min-width: 450px !important;
                  height: 58px !important;
                  padding: 0 40px !important; 
                  
                  /* Design */
                  z-index: 9999 !important;
                  background: rgba(25, 25, 25, 0.95) !important;
                  backdrop-filter: blur(15px);
                  box-shadow: 0px 10px 40px rgba(0,0,0,0.8) !important;
                  border-radius: 30px !important;
                  border: 1px solid rgba(255, 255, 255, 0.15) !important;
                  
                  display: flex !important;
                  align-items: center !important;
                }

                .card-content {
                  padding: 0 !important;
                  width: 100% !important;
                  display: flex !important;
                  justify-content: space-between !important;
                  align-items: center !important;
                }

                :host {
                  position: absolute !important;
                  width: 0 !important;
                  height: 0 !important;
                  z-index: 9999 !important;
                }

Many ways apparently :wink:

unfortunately the calendar opens to the bottom and is not visible when floating at lower screen position. Does anyone have a solution for that?


- type: energy-date-selection
  card_mod:
    style: |
      ha-card {
        /* Fixed position at the bottom */
        position: fixed !important;
        bottom: 30px !important;
        
        /* NEW CENTERING STRATEGY WITHOUT TRANSFORM */
        /* Span the box across the available width (accounting for sidebar) ... */
        left: var(--mdc-drawer-width, 0px) !important;
        right: 0 !important;
        /* ... and use auto margins to center it horizontally */
        margin-left: auto !important;
        margin-right: auto !important;
        
        /* Dimensions */
        width: fit-content !important; /* Adapt width to content size */
        min-width: 450px !important;
        height: 58px !important;
        padding: 0 40px !important; 
        
        /* Styling */
        z-index: 9999 !important;
        background: rgba(25, 25, 25, 0.95) !important;
        backdrop-filter: blur(15px);
        box-shadow: 0px 10px 40px rgba(0,0,0,0.8) !important;
        border-radius: 30px !important;
        border: 1px solid rgba(255, 255, 255, 0.15) !important;
        
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
      }
      
      .card-content {
        padding: 0 !important;
        width: 100% !important;
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
      }

      /* IMPORTANT: Ensure the host element takes up no layout space */
      :host {
        position: absolute !important;
        width: 0 !important;
        height: 0 !important;
        z-index: 9999 !important;
      }

I think you have to “dig deeper” as it’s the" calendar-container" which opens, or above the “ha-date-range-picker”

Success! This works like a charm.

- type: energy-date-selection
  card_mod:
    style:
      # 1. THE INTERNALS (The calendar popup itself)
      hui-energy-period-selector$:
        ha-date-range-picker$:
          date-range-picker$: |
            /* Forces the popup to open upwards */
            .daterangepicker {
              top: auto !important;
              bottom: 50px !important; /* Pushes it above the floating bar */
              margin-top: 0 !important;
              transform-origin: bottom left !important;
            }
            /* Flip the popup arrow (optional, cosmetic) */
            .daterangepicker:before {
              border-top: 7px solid #ccc !important;
              border-bottom: none !important;
              bottom: -7px !important;
              top: auto !important;
            }
            .daterangepicker:after {
              border-top: 6px solid #fff !important;
              border-bottom: none !important;
              bottom: -6px !important;
              top: auto !important;
            }

      # 2. THE CARD EXTERIOR (The floating bar)
      .: |
        ha-card {
          /* Fixed position at the bottom */
          position: fixed !important;
          bottom: 30px !important;
          
          /* Horizontal centering (Stable method) */
          left: var(--mdc-drawer-width, 0px) !important;
          right: 0 !important;
          margin-left: auto !important;
          margin-right: auto !important;
          
          /* Styling / Dimensions */
          width: fit-content !important;
          min-width: 450px !important;
          height: 58px !important;
          padding: 0 40px !important; 
          
          z-index: 9000 !important;
          background: rgba(25, 25, 25, 0.95) !important;
          backdrop-filter: blur(15px);
          box-shadow: 0px 10px 40px rgba(0,0,0,0.8) !important;
          border-radius: 30px !important;
          border: 1px solid rgba(255, 255, 255, 0.15) !important;
          
          display: flex !important;
          align-items: center !important;
          justify-content: center !important;
        }
        
        .card-content {
          padding: 0 !important;
          width: 100% !important;
          display: flex !important;
          justify-content: space-between !important;
          align-items: center !important;
        }

        /* Hides the host element in the grid layout */
        :host {
          position: absolute !important;
          width: 0 !important;
          height: 0 !important;
          z-index: 9000 !important;
        }

For reference here is the complete Element:

<ha-card>
  <template shadowrootmode="open">
    <slot></slot>
  </template>

  <div class="card-content">
    
    <hui-energy-period-selector narrow="">
      <template shadowrootmode="open">
        
        <div class="row datepicker-open">
          <div class="backdrop"></div>
          
          <div class="label">December 2025</div>

          <div class="time-handle">
            
            <ha-icon-button-prev>
              <template shadowrootmode="open">
                <ha-icon-button>
                  </ha-icon-button>
              </template>
            </ha-icon-button-prev>

            <ha-icon-button-next>
              </ha-icon-button-next>

            <ha-date-range-picker minimal="" header-position="">
              <template shadowrootmode="open">
                
                <date-range-picker time-picker="false" twentyfour-hours="true" opening-direction="center" ... >
                  <template shadowrootmode="open">
                    
                    <style>
                      /* ... Sehr langes internes CSS ... */
                      .daterangepicker { position: absolute; ... }
                    </style>

                    <div class="vue-daterange-picker">
                      
                      <div class="form-control reportrange-text">
                        <slot name="input">
                          <div slot="input" class="date-range-inputs">
                            <ha-icon-button>
                              </ha-icon-button>
                          </div>
                        </slot>
                      </div>

                      <div class="daterangepicker ltr show-calendar show-ranges openscenter linked">
                        
                        <slot name="header"></slot>
                        
                        <div class="calendars">
                          <slot name="ranges">
                            <div class="date-range-ranges">
                              <ha-list activatable="">
                                <ha-list-item>Today</ha-list-item>
                                <ha-list-item>Yesterday</ha-list-item>
                                </ha-list>
                            </div>
                          </slot>

                          <div class="calendars-container">
                            <div class="drp-calendar col left">
                              <div class="calendar-table">
                                </div>
                            </div>

                            <div class="drp-calendar col right">
                              <div class="calendar-table">
                                </div>
                            </div>
                          </div>
                        </div>

                        <slot name="footer">
                          <div class="date-range-footer">
                            <ha-button>Cancel</ha-button>
                            <ha-button>Select</ha-button>
                          </div>
                        </slot>

                      </div> </div>
                  </template>
                </date-range-picker>

                <card-mod slot="none" card-mod-type="card-child-child">
                  <style>
                    /* Zwingt das Popup nach oben */
                    .daterangepicker {
                      top: auto !important;
                      bottom: 50px !important;
                      margin-top: 0 !important;
                      transform-origin: bottom left !important;
                    }
                    /* ... */
                  </style>
                </card-mod>

              </template>
            </ha-date-range-picker>
          </div>

          <ha-dropdown placement="bottom-end" size="medium">
            </ha-dropdown>
          
        </div>

        <card-mod slot="none" card-mod-type="card-child">
          <style>
             /* Styles fĂĽr ha-card Positionierung */
          </style>
        </card-mod>

      </template>
    </hui-energy-period-selector>

  </div>
</ha-card>

I love your Energy Dashboard, strange that HA-Devs don’t have more “fantasy” or “Design” experience

I love this, many thanks for sharing! I have an issue with the rendering being broken, it worked a coupe of times but now I only see parts of the picker. Anyone else seing this?

If I typo the .card-content to e.g. “display: falex !important;” it works as it should. Hmm.

@haraldh That typo fixing the issue (“falex”) actually points exactly to the root cause: you are experiencing a severe flexbox collapse.

The old CSS hack stopped working because Home Assistant completely rebuilt the underlying DOM for the hui-energy-period-selector card recently. It is now extremely fragile when manipulated with card_mod.

We just spent hours fighting this exact behavior. Here is what is happening under the hood:

  1. The Javascript ResizeObserver: HA added a hardcoded JavaScript observer that constantly measures the width of this card. If the card drops below ~450px, the JS physically deletes the arrow buttons from the DOM and moves them into the 3-dot overflow menu. If it drops below ~600px, it removes the “Now” button too. CSS cannot bring back elements that JS deleted.
  2. The Flexbox Collapse: The date text (.date-range) now has a flex-grow property. If you try to squeeze the card, the flexbox collapses and cuts off the text (turning “Mar 17” into “M”). Disabling flex entirely (which your typo “falex” effectively does since the browser ignores invalid CSS) works around the collapse, but breaks the intended layout flow.

The Solution: We have to separate the logic from the visuals using a brute-force scaling hack.

We force the card to be 600px wide. This tricks the HA JavaScript into thinking it has a massive screen, so it keeps all the arrows and the “Now” button in the DOM. To make this fit on a mobile screen, we use a media query to apply transform: scale(0.6) which shrinks the rendered 600px card down to a neat 360px.

To prevent the touch hitboxes from misaligning during the scale (which makes the buttons unclickable), we center it on mobile using an old-school negative margin (left: 50%; margin-left: -300px;).

Here is the fully working code with all fixes applied:


  - type: energy-date-selection
	card_mod:
	  style:
		hui-energy-period-selector$:
		  ha-date-range-picker$:
			date-range-picker$: |
			  /* 1. THE POPUP (Opens upwards) */
			  .daterangepicker {
				top: auto !important;
				bottom: 75px !important;
				margin-top: 0 !important;
				transform-origin: bottom center !important;
			  }
			  /* Flip the arrows */
			  .daterangepicker:before {
				border-top: 7px solid var(--divider-color, #ccc) !important;
				border-bottom: none !important;
				bottom: -7px !important;
				top: auto !important;
			  }
			  .daterangepicker:after {
				border-top: 6px solid var(--card-background-color) !important;
				border-bottom: none !important;
				bottom: -6px !important;
				top: auto !important;
			  }
		  .: |
			/* 2. ALIGNMENT (Fixes flexbox collapse and huge empty gaps) */
			.content {
			  justify-content: center !important;
			  gap: 10px !important;
			}
			/* Remove flex-grow from the date to prevent it pushing arrows away */
			.date-range {
			  flex: 0 1 auto !important;
			  margin: 0 !important; 
			}
		.: |
		  ha-card {
			/* 3. THE FLOATING BAR (Desktop Base) */
			position: fixed !important;
			bottom: 30px !important;
			z-index: 9000 !important;
			
			/* Dynamic centering (Sidebar-aware for desktop) */
			left: var(--mdc-drawer-width, 0px) !important;
			right: 0 !important;
			margin-left: auto !important;
			margin-right: auto !important;
			
			/* Fix hitboxes */
			pointer-events: auto !important;
			
			/* THE TRICK: Force 600px width so the HA Javascript keeps ALL icons (arrows + 'Now') */
			width: 600px !important;
			height: 58px !important;
			padding: 0 15px !important;
			box-sizing: border-box !important;
			
			/* Visuals */
			background: rgba(25, 25, 25, 0.95) !important;
			backdrop-filter: blur(15px) !important;
			box-shadow: 0px 10px 40px rgba(0,0,0,0.8) !important;
			border-radius: 30px !important;
			border: 1px solid rgba(255, 255, 255, 0.15) !important;
			
			/* Text contrast fixes */
			--primary-text-color: white !important;
			--secondary-text-color: white !important;
			--mdc-icon-color: white !important;
			--mdc-theme-text-primary-on-background: white !important;
		  }
		  
		  /* 4. THE MOBILE HACK (Scaling brute-force) */
		  @media (max-width: 500px) {
			ha-card {
			  /* Reset sidebar logic and hard-center using oldschool negative margin */
			  right: auto !important;
			  left: 50% !important;
			  margin-left: -300px !important; /* Exactly half of the 600px width */
			  
			  /* Shrink the 600px card to 360px (600 * 0.6) for mobile screens */
			  transform: scale(0.6) !important;
			  transform-origin: bottom center !important;
			}
		  }
		  
		  /* Hide the host element in the grid layout without breaking it */
		  :host {
			position: absolute !important;
			width: 100% !important;
			height: 0 !important;
			pointer-events: none !important;
		  }

I copied this exact code, the date picker popup still goes down. Everything else works fine. Strangely, the compare popup goes up, but the date picker goes down no matter where I put it.

Same problem as Paul, the date picker keeps going down.
I checked with the browser inspector and style .daterangepicker appears not to exist (anymore?).
Regards,
Ben