API: Get lovelace dashboard JSON

There does not appear to be any way to retrieve the JSON file for a lovelace dashboard configuration file.
It would be really useful to get the JSON that you can find in .storage via the REST and or WS API for custom dashboard implementations that do not use a web renderer and just need the structured data defining a dashboard to implement a new view based on that data.
One use case is low power embedded devices where you want to define the content of a screen via the web interface/a dashboard but the target device is not capable of rendering the web frontend.

If the target device can’t render the web frontend, much of the lovelace configuration would be useless. You’d have to re-implement views, sections, and (particularly) all the various kinds of cards out there(core and, potentially for many users, custom). If that isn’t all implemented in some fashion on the target device, getting the lovelace dashboard basically gets you the entities within it, and a bunch of web-dashboard-specific options for the cards they go in. Where would you go from there?

Don’t get me wrong, I like the idea of defining a ā€˜dashboard’ on the fly, in a web browser, for something like an esphome-powered small touchscreen, rather than having to build it in ā€œesphome-eseā€ (meaning lots of yaml & lambdas and such) or another platform entirely. I just don’t think we can easily translate directly from a lovelace dashboard to any embedded platform lacking modern web features – a better tactic might an add-on & HA component paired with a esphome component that can talk to each other. The add-on would be responsible for providing a builder-ui for designing embedded dashboards, the ha component would be a bridge between HA, the add-on, and the embedded device because it would be aware of devices, entities, etc, and finally, the esphome component would pull the UI ā€˜over the wire’ from the HA component. I realize that only covers esphome-powered devices…I just don’t have enough experience with any others to know if it’s even conceivable for them to tap into the same system.

I second this feature request, as I would like to update the dashboard configuration (the existing json structure) from an external tool (appdaemon in my case) via an API.

This would allow me to use my existing appdaemon project structure, which already knows about all of the relevant entities I have in home assistant, and enable it to generate dashboard configurations from it.

I know there are add-ons that enable similar features, like conditional cards and such, but this currently still requires a lot of manual editing in multiple places if I change anything in my home, since I want to have both a very dynamic dashboard that displays only currently relevant items, as well as other dashboards that display everything room related.

A simple GET/PUT API would suffice for me as a first step, since I can deal with a JSON or YAML syntax myself and figure out how to ā€œnot breakā€ anything.

I’m not sure this is true. (Context: I’m thinking about what would need to happen to support HA dashboards on trmnl)

It’s perfectly acceptable to say that a dashboard intended for an embedded system should only use a pre-defined subset of cards, a restricted view, etc. But even in that situation it’s useful to be able to plan out the dashboard using the Lovelace dashboard editor.

So if I had the ability to grab the dashboard config, I could then render each card element using simple, trmnl-focused HTML. Filling in the entity states etc. using the Jinja templating is easy enough as there is already an API endpoint for that.

I imagine it’s possible to do something equivalent with heavy use of card mod themes. But being able to generate super-simple HTML feels considerably cleaner.

Update: I’ve found a way to do this via the websockets API. If you send a message like

{"id": 1, "type": "lovelace/config", "url_path": "dashboardname"}

you get back an object with a views key containing the configuration of each view.

Specifically, here’s some Python code to connect to a HA instance and get the config for a dashboard:

import asyncio
import json

from websockets.asyncio.client import connect

ha_url = "homeassistant.local:8123"
access_token = "REDACTED"

async def get_dashboard_config(ha_url: str, access_token: str, url_path: str):
    async with connect(f"ws://{ha_url}/api/websocket") as websocket:
        message = json.loads(await websocket.recv())
        assert message["type"] == "auth_required", "Expected auth_required message"
        await websocket.send(json.dumps({"type": "auth", "access_token": access_token}))
        message = json.loads(await websocket.recv())
        assert message["type"] == "auth_ok", "Expected auth_ok message"
        await websocket.send(
            json.dumps({"id": 1, "type": "lovelace/config", "url_path": url_path})
        )
        message = json.loads(await websocket.recv())
        return message["result"]["views"]
1 Like