Background: My fiancée and I often access a Cookbook plugin within NextCloud from her tablet or one of our phones while making dinner. While we could add the url as a browser bookmark for all of our devices and within each of our browsers, we wanted a way to access NextCloud (or any other urls!) with one quick tap from Home Assistant sidebar.
I wasn’t able to find a step-by-step solution for adding the capability to open a target url in a new window by clicking on a sidebar item. I first attempted to use an iframe panel which would only try (unsuccessfully) to embed my target url into the HA window. I also tried a custom panel, which I couldn’t immediately figure out and frankly didn’t want to spend the time possibly being able to achieve our goal. I wanted a solution that was easier to implement and maintain.
After some research into possible solutions, I came across Villhellm’s Frontend module for Custom Sidebar (https://github.com/Villhellm/custom-sidebar), available in HACS. From my perspective, the Custom Sidebar mod’s summary seems largely centered around its global reordering functionality (which is awesome, since HA native reordering is per user, and per device).
The feature of this mod that we’re after is the “new_item”. While many examples implement new_item in order to add sidebar links to internal HA resources (a direct link from the sidebar to the System Config page, for example), we can leverage it to point to external resources which will open in a new window.
Steps:
-
Install the Custom Sidebar module using HACS (or otherwise following the linked installation guide for the Custom Sidebar repository).
-
In HA, navigate to Configuration -> Lovelace Dashboards -> Resources button (lower right poison of the screen, looks like a “file copy” button - two documents stacked upon one another).
-
Click on the Add Resources button and paste the following Javascript Module path:
/hacsfiles/custom-sidebar/custom-sidebar.js
-
Using the File Editor addon or any other method of creating files on your HA box, create the following file:
/config/www/sidebar-order.yaml
-
In the sidebar-order.yaml file, add the following:
order:
- new_item: true
item: Cookbook
href: https://192.168.x.x/index.php/apps/cookbook/
icon: "mdi:silverware-fork-knife"
bottom: true
- new_item: true
item: Item2
href: https://192.168.x.x/index.php/path/to/another/thing/
icon: "mdi:timer"
bottom: true
(Default for bottom is false, so new items will normally appear on top - I chose to have the Cookbook entry appear underneath all other sidebar entries, so I explicitly set bottom to true. See the Custom Sidebar documentation for additional info)
- Refresh your browser cache (or otherwise clear/reload your application’s cache) and you’ll see the sidebar changes.