Skip to content

Instantly share code, notes, and snippets.

@dale3h
Last active August 26, 2021 17:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dale3h/1cc3360d157366243cd0902e67d492a5 to your computer and use it in GitHub Desktop.
Save dale3h/1cc3360d157366243cd0902e67d492a5 to your computer and use it in GitHub Desktop.
[Home Assistant] Lovelace Custom QuickBar Commands
customElements.whenDefined("ha-quick-bar").then(() => {
const fireEvent = (node, type, detail, options) => {
options = options || {};
detail = detail === null || detail === undefined ? {} : detail;
const event = new Event(type, {
bubbles: options.bubbles === undefined ? true : options.bubbles,
cancelable: Boolean(options.cancelable),
composed: options.composed === undefined ? true : options.composed,
});
event.detail = detail;
node.dispatchEvent(event);
return event;
};
const navigate = (path, replace = false) => {
if (replace) {
history.replaceState(null, "", path);
} else {
history.pushState(null, "", path);
}
fireEvent(window, "location-changed", {
replace,
});
};
const haQuickBar = customElements.get("ha-quick-bar");
haQuickBar.prototype._generateServerControlCommandsDefault = haQuickBar.prototype._generateServerControlCommands;
haQuickBar.prototype._generateServerControlCommands = function() {
let commands = [
{
text: "Navigate to Overview",
icon: "mdi:view-dashboard",
action: () => navigate("/lovelace"),
},
{
text: "Navigate to Integrations",
icon: "mdi:puzzle",
action: () => navigate("/config/integrations"),
},
{
text: "Navigate to States",
icon: "mdi:code-tags",
action: () => navigate("/developer-tools/state"),
},
{
text: "Navigate to Services",
icon: "mdi:remote",
action: () => navigate("/developer-tools/service"),
},
{
text: "Navigate to Template",
icon: "mdi:file-code",
action: () => navigate("/developer-tools/template"),
},
{
text: "Navigate to Events",
icon: "mdi:radio-tower",
action: () => navigate("/developer-tools/event"),
},
{
text: "Navigate to Lovelace Dashboards",
icon: "mdi:view-dashboard",
action: () => navigate("/config/lovelace/dashboards"),
},
{
text: "Navigate to Lovelace Resources",
icon: "mdi:cog-box",
action: () => navigate("/config/lovelace/resources"),
},
];
return [...commands, ...this._generateServerControlCommandsDefault()];
};
});
@blizzrdof77
Copy link

Love this gist by the way! It stopped working for me a few months ago -- have you had any recent issues with it @dale3h ?

@blizzrdof77
Copy link

image
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment