cd ../blog
#home-assistant#homeassistant#macos#menubar#smart-home

HassTray: Home Assistant in My Mac Menu Bar

HassTray is a free, open source menu bar app for Home Assistant on macOS. Pick your entities, toggle them from the tray, watch sensor graphs and keep up to five live values next to the clock. Built in Go with Wails.

Jaba Macharashvili 7 min read

In this post
  1. The tray
  2. Values next to the clock
  3. Graphs
  4. Eight themes and a mixer
  5. How it’s built
  6. It talks to your Home Assistant and nothing else
  7. Try it
A Mac menu bar with the HassTray icon and three live values, the app icon and name, two entity tiles switching on and a solar production graph drawing itself
HassTray logo

HassTray

A menu bar app for Home Assistant on macOS.

Go and Wails, one universal build, no server in between.

github.com/jaba0x/HassTray

Half of what I ask Home Assistant during the day is tiny. Is the pergola open? How much is the solar producing right now? Turn the living room light off. Every one of those was a browser tab, a search for the right tab, a dashboard loading, a click, then closing the tab again.

The phone app is quicker, but reaching for the phone while sitting in front of a Mac feels silly.

So I built HassTray. It puts the entities I care about behind one icon in the menu bar, with their graphs, and keeps a few live values next to the clock.

The screenshots are the real interface with sample entity names and readings.

HassTray features: entity tiles, sensor graphs, menu bar widgets, themes and a local-only connection

The tray

Click the icon and a panel drops down under it. Lights, switches, covers, locks, climate and media players are tiles you click to toggle. Scenes, scripts and buttons run on click. Everything else is a sensor row with its current value.

The HassTray panel open under the menu bar, with four entity tiles and four sensor rows

The order is yours. Each entity has an up and a down arrow in Settings, so the things you touch most sit at the top.

State arrives over Home Assistant’s WebSocket API. The app subscribes to state_changed once and then only gets what moved, so a light you switch at the wall shows up in the tray within a second or so. If the connection drops, it reconnects on its own and backs off up to 30 seconds between tries.

Values next to the clock

This is the part I use without opening anything. Up to five entities can show their value in the menu bar itself:

The menu bar showing the HassTray icon with 12.4 degrees, 3.2 kilowatts and 48 percent

Mine are outdoor temperature, solar production and indoor humidity. Any entity in the tray can be promoted with the Menu bar button in Settings, and five is the cap because macOS gives you one menu bar and other apps live there too. An entity that goes unavailable shows a dash instead of a stale number.

The entity settings with search, type filters, and Graph and Menu bar buttons on each entity

The picker lists every entity Home Assistant has, which on a house that has been automated for a while is a long list, so there is a search box and filters by type. What you tick is what the tray shows.

Graphs

Turn on Graph for a numeric entity and its row gets a sparkline of the last 24 hours. Click the row and the graph fills the panel:

A full-panel graph of solar production with 1 hour, 24 hour and 7 day ranges and the lowest, average and highest value

Three ranges: one hour, 24 hours, seven days. Under the chart are the lowest, average and highest value for the range, and moving the pointer across reads out the value at that time.

The readings come from Home Assistant’s history API. Those are irregular, because a sensor reports when it feels like it, so HassTray buckets them into fixed slots and averages each bucket. A bucket with no reading keeps the last known value, which is what a sensor that has not reported is still showing anyway. How far back you can go is whatever your recorder keeps, ten days by default.

Eight themes and a mixer

I started with one theme and could not leave it alone. There are eight now:

The HassTray panel in all eight themes: Liquid Glass, Midnight Mint, Neon Terminal, Sunset, Paper, Slate, Forest and Rose

The default is Liquid Glass. The window uses the macOS glass material, so the panel really is see-through, and it follows light and dark mode. Neon Terminal is black, lime and monospace. Paper is flat and warm with square corners. The rest sit between those.

If none of them fit, there is a mixer:

The theme mixer with an accent colour picker, a background choice, a corner slider and font buttons

Pick a theme to start from, then set the accent colour, the background, how round the corners are and the font. Changes apply while you drag, and the result is saved as your theme.

The part that took the most thought is contrast. A theme is a block of CSS variables, and the stylesheet asks for things like “text on top of the accent” and “the muted colour”. When you choose a pale yellow accent, white text on it becomes unreadable, so the app works out the brightness of what you picked and flips that text to near-black. The same check pushes a pale accent darker when it is used as text on a light background. You can pick an ugly theme, but not an unreadable one.

A HassTray panel in a custom theme with an orange accent on a warm dark background

How it’s built

Go, and Wails v3 for the window and the menu bar icon. My Aruba switch app SwitchDesk runs on Wails v2, but v2 has no system tray, so this one needed v3. A universal build for Apple Silicon and Intel comes out at about 21 MB.

The interface is plain HTML, CSS and JavaScript with no build step, same as my other apps. It asks the Go side for a snapshot roughly once a second and redraws only when a counter in the snapshot changed, which keeps an idle panel from repainting all day.

There is no network port involved. Wails serves the panel from an in-process handler, so the panel’s own API routes are registered on that same handler and the requests never leave the app.

main.go            window, menu bar icon and menu
app.go             live state, graphs, menu bar widgets
api.go             the routes the panel calls
internal/hass      Home Assistant client: REST, WebSocket, history, formatting
internal/config    settings file and Keychain

Most of the fiddly code is in internal/hass. Home Assistant hands you a string state and a bag of attributes, and turning that into one readable line per entity is all special cases. A light that is on has brightness from 0 to 255 and people want a percentage. A climate entity has a state, an action and a target temperature, and the action is the interesting one. A cover can be open, closed, or at 40 percent. A sensor reporting 21.437 should say 21.4, but one reporting 1250.4 watts should say 1250. That layer has tests, because it is the layer that makes the app feel finished or not.

It talks to your Home Assistant and nothing else

No account, no cloud relay, no telemetry. HassTray connects straight to your instance with a long-lived access token, which is stored in the macOS Keychain and never written to the settings file. The settings file holds your entity choices and your theme, and lives in ~/Library/Application Support/HassTray/.

The only other request it makes is one call a day to the GitHub releases API, to notice when a newer version exists.

Try it

The source is at github.com/jaba0x/HassTray. There is no packaged download yet, so you build it:

git clone https://github.com/jaba0x/HassTray.git
cd HassTray
scripts/build-mac.sh 0.2.0 --install

That runs the tests, builds a universal HassTray.app, copies it to /Applications and starts it. You need Go and the Xcode command line tools. Then create a long-lived access token in Home Assistant under your profile, on the Security tab, and paste it with your instance address on first launch.

This is version 0.2.0 and it is young. A click toggles an entity and that is all it does, so brightness, colour and temperature controls are not in yet. Those are what I want next, along with a notarized build so you do not have to compile it yourself.

If you run it, I would like to hear which entities you put in the menu bar, and what you expected to be there and was not. Issues and ideas go in GitHub issues.


Follow along. New posts show up on the RSS feed. I also share my projects on GitHub, MakerWorld and LinkedIn.