Phone-first Home Assistant dashboards, built as code

A Home Assistant dashboard made for a phone: photo tiles per room, a page of everything that runs itself, and no tile that moves anything by accident.

The Rooms section of the dashboard: a grid of nine room photo tiles, each with the room name and how many lights are on, and a four-button tab bar underneath
Difficulty
Moderate
Parts cost
Free software. AI room pictures cost about US$0.10 each, if you use them
Build time
Built in stages over about two months, August to October
Skills
Home Assistant, YAML, Python

The problem

My old Home Assistant dashboard was built on a laptop screen, one card at a time, and it grew. On a phone it was a long scroll of switches. Everyone in the house uses a phone, not a laptop.

So I built a second dashboard, side by side with the old one, made for a phone first. It has a Home page with a tile and a photo for each room, a Runs itself page that lists everything that’s automated, and a Power page. The whole thing is written as code and pushed into Home Assistant by a script, not clicked together in the editor. That turned out to matter most for one reason: the script refuses to deploy a dashboard where a tap could switch off something important.

How it works

How the phone-first dashboard gets built and deployed A Python build script writes the whole dashboard as code. Safety checks refuse any tile that could switch off a plug or move a blind. If the checks pass, the config is saved into Home Assistant over its websocket API with no restart. The phone shows Home, Runs itself and Power pages with a tab bar along the bottom. Build script the whole dashboard, written as code Safety checks ✓ only lights (and one candle) toggle ✓ plugs that feed things: readings only ✓ blinds open details, never move ✓ Power page is display only Home Assistant saved over the websocket API, no restart Your phone Home: a photo tile per room Runs itself: the automations Power: use and cost tab bar along the bottom ↓ Home Runs itself Power If a check fails, nothing is deployed.

A Python script builds the whole dashboard config, checks it, and saves it into Home Assistant through its websocket API (the same channel the Home Assistant app talks over). No restart. A second command removes it again, so trying something new is cheap.

The old dashboard was never touched. When I rebuilt it earlier, I saved the old layout as its own dashboard called “Classic” first, so going back is one save away.

Each person’s phone can land somewhere different. The kids’ phones open on their own room, picked by their Home Assistant user.

What you need

  • Home Assistant, with your lights, plugs and sensors already working.
  • A dashboard in “sections” view. That’s the built-in grid layout with tiles. The tiles themselves need no add-ons.
  • HACS (the community add-on store) for:
    • Bubble Card, for the tab bar along the bottom
    • Power Flow Card Plus (I used v0.3.7)
    • ApexCharts Card (v2.2.3)
    • Sankey Chart by MindFreeze (v6.4.0)
  • Python on a computer, to run the build script.
  • Photos of each room. Stock photos work to start with. Real ones come later.
  • Optional: an AI image model for the room-picture pages. I used Gemini 3.1 Flash Image through OpenRouter.

Structure

Page What’s on it
Home Two sections. Runs itself sits at the top: a tile each for the dishwasher, washer, dryer, garage, alarm, vacuum, bins and aircon, each with one line saying what it’s doing. Rooms is under that: a photo tile for each room (lounge, kitchen, dining, theatre, master, three bedrooms, hallways). The photo changes for day, night, and night with the lights on. Under the room name is a second line like “1 on · 22°”: how many lights are on, and the room temperature where the room has a sensor.
A room Tap a room tile and you get that room’s own page. There’s no Rooms tab. You always get to a room from Home.
Runs itself The full page for everything that’s automated, one heading per machine. It’s mostly status, so you can see what it’s doing without poking it. The few real controls ask “are you sure?” before anything moves.
Power “Using right now” in watts, with what that costs in cents per hour. “Today so far” in dollars, with what the whole day is on track to cost. “Biggest users today” as bars in kWh. “This week vs last” as bars, day by day.
Tab bar Four buttons along the bottom, like a phone app: Home, Runs itself, Power, More. It’s a Bubble Card horizontal-buttons-stack. The kids’ phones only get Home and Runs itself.

A few things about the sections layout that took me a while to learn:

  • A tile has a 6-column minimum. A tile with its controls inline beside it needs 12 columns.
  • A normal section is a 12-column grid. A section with column_span: 2 is a 24-column grid, so there columns: 6 is a quarter of the width and columns: 12 is half.
  • Put a plug’s on/off control at features_position: bottom and two of them fit per row, each next to its power reading.
  • The clock and media cards draw a beat late. Wait before you decide they’re broken.

The safety rules

A dashboard on a phone gets tapped by accident: in a pocket, by a kid, while scrolling. So these rules are built into the script, and it won’t deploy if one is broken:

  • Only lights can be toggled. Light groups, to be exact. A fitting with two bulbs is controlled through its group, so both bulbs always agree. The one exception is a decorative electric candle.
  • Plugs that power other things are readings only. One plug feeds my home server and the internet router. Another feeds the TV and its streaming stick. Others feed the fridge and the beer fridge. A tap on any of these shows the reading. It never switches the plug.
  • Blinds open their details panel. They never move from a single tap.
  • The Power page is display only. Every tap opens the details of a sensor.
  • There’s a tile for the house alarm. That’s all I’ll say about it.

The dashboard config

A sections page with tiles

This is the shape of the Runs itself page. Every tile opens its details on tap, including a tap on the icon, because a tile’s icon can toggle things by default.

views:
  - title: Runs itself
    path: runs-itself
    icon: mdi:robot
    type: sections
    max_columns: 4
    sections:
      - type: grid
        cards:
          - type: heading
            heading: Runs itself
          - type: tile
            entity: sensor.dishwasher_status
            name: Dishwasher
            tap_action:
              action: more-info
            icon_tap_action:
              action: more-info
            grid_options:
              columns: 6
          - type: tile
            entity: input_select.washer_state
            name: Washer
            tap_action:
              action: more-info
            icon_tap_action:
              action: more-info
            grid_options:
              columns: 6
          - type: tile
            entity: input_select.dryer_state
            name: Dryer
            tap_action:
              action: more-info
            icon_tap_action:
              action: more-info
            grid_options:
              columns: 6
          - type: tile
            entity: vacuum.robot_vacuum
            name: Vacuum
            tap_action:
              action: more-info
            icon_tap_action:
              action: more-info
            grid_options:
              columns: 6
          - type: tile
            entity: climate.living_room
            name: Aircon
            tap_action:
              action: more-info
            icon_tap_action:
              action: more-info
            grid_options:
              columns: 6
          - type: tile
            entity: sensor.next_bin_day
            name: Bins
            tap_action:
              action: more-info
            icon_tap_action:
              action: more-info
            grid_options:
              columns: 6

A light tile with a brightness slider under it looks like this:

- type: tile
  entity: light.example_light
  features:
    - type: light-brightness
  features_position: bottom
  grid_options:
    columns: 12

A room picture that changes with the light

This is the direction I’m heading for every room. It’s a picture-elements card (a picture with live icons placed on top) with three backgrounds: day, night with the lights on, and night with them off. Three conditional cards in a stack pick which one shows. The anchor (&room) saves pasting the same list of icons three times. Home Assistant expands it when you save.

type: vertical-stack
cards:
  - type: conditional
    conditions:
      - condition: state
        entity: sun.sun
        state: above_horizon
    card:
      type: picture-elements
      image: /local/rooms/example_day_v2.jpg
      elements: &room
        - type: state-icon
          entity: light.example_light
          title: Ceiling light
          state_color: true
          tap_action:
            action: toggle
          hold_action:
            action: more-info
          style:
            left: 42%
            top: 18%
        - type: state-label
          entity: sensor.example_plug_power
          prefix: "TV unit "
          tap_action:
            action: more-info
          style:
            left: 70%
            top: 64%
  - type: conditional
    conditions:
      - condition: state
        entity: sun.sun
        state: below_horizon
      - condition: state
        entity: light.example_light
        state: "on"
    card:
      type: picture-elements
      image: /local/rooms/example_night_on_v2.jpg
      elements: *room
  - type: conditional
    conditions:
      - condition: state
        entity: sun.sun
        state: below_horizon
      - condition: state
        entity: light.example_light
        state_not: "on"
    card:
      type: picture-elements
      image: /local/rooms/example_night_off_v2.jpg
      elements: *room

The light is a state-icon: tap toggles it, hold opens its details. The plug is a state-label: it only ever shows a reading. Put the room’s light group in the conditions, so “lights on” means the room, not one bulb.

Where the power goes

The Sankey Chart draws house → each plug, and splits a plug further when one plug is plugged into another. My beer fridge plug sits downstream of a hallway plug, so the hallway plug’s reading already includes the fridge. Add both and you count the fridge twice. A remaining_parent_state node shows “the rest” instead. Version 6 of the card uses nodes and links (older examples online use sections and children, which won’t work).

type: custom:sankey-chart
show_names: true
sort_by: state
nodes:
  - id: sensor.house_power
    section: 0
    name: House
  - id: sensor.hallway_plug_power
    section: 1
    name: Hallway
  - id: sensor.beer_fridge_power
    section: 2
    name: Beer fridge
  - id: hallway_rest
    section: 2
    type: remaining_parent_state
    name: Hallway (rest)
links:
  - source: sensor.house_power
    target: sensor.hallway_plug_power
  - source: sensor.hallway_plug_power
    target: sensor.beer_fridge_power
  - source: sensor.hallway_plug_power
    target: hallway_rest

I don’t have a whole-house meter, so sensor.house_power is an estimate: the smart plugs’ readings added up, plus a modelled figure for what has no plug (each bulb, the bedroom fan, the aircon in summer). How that’s built is in the energy meter guide. For the day-by-day version, add energy_date_selection: true and an energy-date-selection card above it, and point the nodes at energy (kWh) sensors instead of watts.

On a second, fuller Power dashboard I also have tiles for the current tariff, the rate, dollars per hour and house watts; Power Flow Card Plus with only the four biggest users shown as circles; and ApexCharts for daily cost over 30 days (statistics type: state, period: day) and stacked daily kWh per device over 14 days (statistics type: change).

The safety check in the build script

The script turns the finished config into text and refuses to deploy if a switch it doesn’t know about appears, or if anything other than a light (or the candle) can be toggled:

import json, re

text = json.dumps(cfg)
switches = set(re.findall(r"switch\.[a-z0-9_]+", text))
assert switches <= {"switch.example_candle"}, switches

toggles = set(re.findall(
    r'"entity": "([a-z_]+\.[a-z0-9_]+)"[^{}]*"tap_action": \{"action": "toggle"\}', text))
assert all(t.startswith("light.") or t == "switch.example_candle" for t in toggles), toggles

Saving it into Home Assistant

The script sends two websocket messages. The first creates the dashboard, the second saves the config:

{"type": "lovelace/dashboards/create", "url_path": "home-v2", "title": "Home",
 "icon": "mdi:home", "show_in_sidebar": true, "require_admin": false, "mode": "storage"}
{"type": "lovelace/config/save", "url_path": "home-v2", "config": { "views": [] }}

The url_path must have a hyphen in it. floorplan is rejected, home-floorplan works.

Step by step

  1. Save your current dashboard somewhere safe first (I copied mine to a dashboard called “Classic”).
  2. Write the build script to output the dashboard as one Python dict: views, sections, tiles.
  3. Add the safety checks above. Run them before every deploy, plus your tests (I use pytest).
  4. Deploy with the two websocket messages. Open the new dashboard on a phone.
  5. Add room photos. Name them <room>-<day|night|on>, shrink them to 1280 px, and strip the location data out of them. My script accepts iPhone HEIC files. The family drop photos into a shared Immich album and a script pulls them down. Until then, stock photos fill in.
  6. Serve the photos from a folder under /local with a name nobody could guess, and keep that name out of git.
  7. For room-picture pages: take one photo per room, ideally from the doorway in daylight, and mark where the lights and plugs are. Make the day image first, then the two night images from the day image. Place an icon at each mark.
  8. Give every new image a new file name. Phones hold on to the old one.

Testing it

Don’t press anything to test it. Not the lights, not the garage, not the locks. Open each page and read it. If a tile shows the right state and its tap opens the right details, that’s the test.

  • Check every page renders with live data and no red error cards.
  • Check the Power page: every tap should open a sensor’s details, nothing else.
  • If a change “didn’t work”, compare three things before touching the deploy: the file on your computer, the file on Home Assistant, and what Home Assistant actually serves to the browser. If all three match, it’s the browser cache, not your deploy.
  • The room-picture page loads slowly. Scroll with your finger (or mouse) over the picture.

The floorplan experiment

Before the room pictures, I tried a live floorplan of the house we’re building, drawn from the architect’s plans. It’s a 3D cutaway, rendered by Sweet Home 3D driven entirely from code, with each room glowing when its lights are on. It works, and I learnt a lot, but room photos are easier to read on a phone, so that’s the way I’m going. What it taught me is in the lessons below.

Lessons learnt

A markdown card won’t draw SVG. My first floorplan was a picture drawn as SVG inside a markdown card. Home Assistant’s template tester showed it perfectly. The real page showed the raw source as text, because the markdown card strips HTML and SVG for safety. Anything visual has to be an image in /config/www (served at /local/...) shown with picture-elements, with state-icon elements for the live state.

“The dashboard didn’t change” was the browser. Images under /local are cached hard. The file on my laptop, the file on Home Assistant and the file Home Assistant served all matched, byte for byte. The browser just kept its old copy. Fix: put a version or date in the file name every time you change an image. A name the browser has never seen can’t come from its cache.

The room moved between day and night. Ask an AI model for a day picture and a night picture of the same room separately, and you get two slightly different rooms. Make the night pictures from the day picture. And give it a landscape photo (I use 3:2). I fed it a portrait photo to widen, and it invented a second window.

Two plugs, one fridge. The beer fridge plugs into a plug that’s already measured. Add them together and the fridge counts twice. Use remaining_parent_state for “the rest of that plug”.

One tap could have taken the house offline. A plug on my dashboard powers the home server and the internet router. On a phone, one stray tap would have switched both off. That’s why plugs that feed other things are readings only, and why the build script checks it rather than me remembering.

A blank render passed for a finished one. When I turned the SVG into a PNG with cairosvg, it came out blank, because the SVG had style="width:100%" on it. Set a real width and height first. Then look at the image, don’t just check the file exists.

3D from code has traps. Sweet Home 3D’s Java 3D won’t run headless; it needs a display (a virtual one works). Full-height walls hide everything, so I cut them to about 110 cm. And a ceiling light added as plain furniture gives no light at all, so lit and unlit renders came out identical. It has to be added as a light.

card-mod’s release had nothing in it. The card-mod v4.2.1 release on GitHub has no files attached. The real card-mod.js is at the top of the repository, and the /dist/ links return a tiny error page. Check the size of what you downloaded.

Questions and comments

Loading comments…

    Your name and comment show publicly. To stop spam, a scrambled code made from your internet address is kept, never the address itself. Comments with links wait for a quick check before they show. Be decent: I'll remove anything that isn't.