The ha-date-range-picker is specifically for a range of dates times from a to b, but most importantly its not loaded on the dashboard, so you CAN’T use it (unless you have navigated to the history page before you visit the dashboard since its a single page app the element will still be loaded)
There’s an time selector for selecting time, and a datetime selector for selecting dates + time
you can load any of the built in selectors from Selectors - Home Assistant by passing a struct into ha-form.
<ha-form
.hass=${this.hass}
.data=${this._config} <!-- needs to be the object that has my_time -->
.schema=${[{name: "my_time", selector: { time: {} }}]}
.computeLabel=${this._computeLabel}
@value-changed=${this._valueChanged} <!-- will return mutated object passed in "data" as ev.target.value -->
></ha-form>
if you specifically need the ha-date-range-picker
this is how you “would” use it, provided you could make sure its loaded. There are probably some hacks you can use to force that component to load, or manually load it, or duplicated it for your component and rename it.
<ha-date-range-picker
.hass=${this.hass}
?disabled=${false}
.startDate=${new Date()}
.endDate=${new Date()}
.ranges=${{
// key is name that appears in list, array is start/end date time obj. Omit this whole object to not see that list of shortcuts
"today": [new Date(), new Date()]
}}
@change=${
//bubbles from the inner date-range-picker control that ha-date-range-picker wraps, value is {startDate: Date, endDate: date}
this._dateRangeChanged
}
></ha-date-range-picker>
notice that the customElement is not defined but after I navigate to the history page, it is loaded.
The built in components of home assistant aren’t really intended to be used by custom cards, but most of the developers certainly use the selectors for ha-form. If ha-form doesn’t happen to be loaded you can force it to load with the hack
if (!customElements.get("ha-form")) {
(customElements.get("hui-button-card") as any)?.getConfigElement();
}
//^^^ borrowed from lovelace-mushroom.
But again, technically they don’t provide an api to load the elements you might need from the UI, you can just use them if you know where to find them.