This Week's Sponsor:

Winterfest 2024

The Festival of Artisanal Software


Using Shortcuts to Display the Temperature from My Outdoor Sensor in the Menu Bar

I have always enjoyed having the current temperature in the menu bar on my Mac. Even though macOS Sonoma now supports adding a Weather widget of your choice directly to the desktop, I still prefer how a menu bar item is always glanceable and visible regardless of how crowded the desktop is.

For the past few months, I have tried many weather apps to achieve this, including the great Mercury Weather. While most of them worked great, I wanted to take advantage of the fact that we now own an outdoor HomeKit sensor — the Eve Weather — and display the data coming directly from that weather station in the menu bar. I ended up with a neat little solution, using a combination of Shortcuts, SF Symbols, and a couple of useful utilities.

The Eve Weather sensor outside our bedroom window.

The Eve Weather sensor outside our bedroom window.

For a few weeks, I used Homie, a great little menu bar app for macOS that allows you to control your HomeKit devices from the menu bar. Homie was useful to me for one feature in particular: the ability to pin any accessory to the menu bar. This meant I could pin the temperature from the Eve Weather and always have it visible in the corner of the screen. Unfortunately, Homie’s functionality does not go much further than that. There is no way to customize how the temperature is displayed, nor to choose how often it should update. In fact, I frequently had to launch Apple’s Home app to manually refresh the temperature Homie was showing in the menu bar.

Looking for an alternative solution, I stumbled upon this article by Joe Rosensteel on Six Colors, in which he describes how he’s been able to display the temperature from his Eve Weather in the menu bar, using Shortcuts and Sindre Sorhus’ One Thing. One Thing is a great little app with one single purpose, which is to display any string of text you pass to it in the menu bar. His solution is very neat. It would allow me to both take advantage of my HomeKit device data, and to customize how it would look.

My first version of this shortcut, inspired by Joe Rosensteel’s attempt, started simple and could be summed up in three steps:

  1. Fetch the temperature from the Eve Weather using the action ‘Get the state of my Home’;
  2. Round the measurement to the nearest whole number to avoid having to read an unnecessarily specific value, like “12.52 °C”;
  3. Add One Thing’s ‘Set menu bar’ action to display the temperature in the menu bar.

This worked great. But I didn’t want to stop there:

  • I wanted to display a weather condition icon next to the temperature value to reflect what the sky is actually looking like outside my window. Is it sunny, cloudy, or rainy right now?
  • I also wanted to display a trend: an arrow pointing up if the temperature has been rising for the past hour, an arrow pointing down if it’s getting cooler, and an equal sign if it’s currently stable.

The Eve Weather only surfaces two data points in HomeKit: temperature and humidity. So I only needed to add the ‘Get current weather’ action to the shortcut to fetch the current condition via Apple Weather. This outputs a short string of text — like “Mostly Sunny”, “Partly Cloudy”, or “Heavy Rain” — that I could then match to an icon.

While I could have gone with emojis for the icons, I wanted something that looked cleaner and right at home in the macOS menu bar. I also realized that One Thing could perfectly display SF Symbols. So I decided to go that route instead, and to catalog all the possible weather conditions in a Dictionary block, so I could match each to a corresponding SF Symbol. This may sound like a gigantic task, but I was fortunate to discover that there is an Apple Support page that already provided me with both all the possible weather conditions in Apple Weather, and all their corresponding SF Symbols.

Referencing all the SF Symbols needed to reflect the current weather condition as an icon, in a Dictionary block.

Referencing all the SF Symbols needed to reflect the current weather condition as an icon, in a Dictionary block.

Apple's SF Symbols app has a Weather category containing all the icons usually found in the Weather app. Right-clicking a symbol lets you copy then paste it in Shortcuts.

Apple’s SF Symbols app has a Weather category containing all the icons usually found in the Weather app. Right-clicking a symbol lets you copy then paste it in Shortcuts.

In order to display an arrow indicating a temperature trend, I would need to store recent temperature measurements in a persistent location. My shortcut could then use these values to do some math to deduce a trend, and display an arrow accordingly.

This is where Simon Støvring’s Data Jar comes in. Data Jar is a neat little utility, designed to work with Shortcuts. The app lets you store values, lists, and dictionaries in a persistent location, and update them using shortcut actions. Now, every time the shortcut is executed, it appends the most recent temperature value to a list in Data Jar and removes the oldest value, which is the fifth one. As a result, the shortcut can always access a history of the four most recent measurements to calculate the temperature trend.

The last step to this was then to display the appropriate SF Symbol, which I added to the dictionary block I mentioned above: an arrow pointing up if the temperature has been increasing, an arrow pointing down if it has been decreasing, and an equal sign if the temperature is stable.

My shortcut stores the last four temperature measurements in a list called 'OutdoorTempHistory' in Data Jar.

My shortcut stores the last four temperature measurements in a list called ‘OutdoorTempHistory’ in Data Jar.

'Temp1' through 'Temp4' are stored in Data Jar. The formula I'm using outputs a negative number if the temperature is decreasing, a positive number if it's increasing, or 0 if it's stable.

‘Temp1’ through ‘Temp4’ are stored in Data Jar. The formula I’m using outputs a negative number if the temperature is decreasing, a positive number if it’s increasing, or 0 if it’s stable.

Feeling happy with this result, I repeated the steps to display the humidity in the menu bar alongside the temperature. Although the Eve Weather also has a pressure sensor, that data cannot be surfaced to HomeKit or Shortcuts. Air pressure changes are quite significant to measure and predict weather conditions, so I will gladly add this data point to the shortcut if it ever becomes possible.

The last block to add to the shortcut was, of course, to pass everything to One Thing to display the result in the menu bar.

The last block to add to the shortcut was, of course, to pass everything to One Thing to display the result in the menu bar.

One final step was to find a way to regularly run the shortcut in the background. Shortcuts’s ‘Automation’ tab, on iOS and iPadOS, can do exactly that. Oddly, it is not present on macOS. However, Joe Rosensteel’s article also had a great little recommendation to address this limitation, which is to use Lingon 3, a macOS utility that lets you run a command in the background, on a schedule of your choosing.

Because we’re storing the four most recent values, setting a 15-minute interval for the trend calculation ensures that the trend indicator reflects the temperature and humidity changes of the past hour. So I went ahead and set Lingon 3 to run the shortcut every 15 minutes.

Using Lingon 3 to run the shortcut in the background every 15 minutes, and every time I log in.

Using Lingon 3 to run the shortcut in the background every 15 minutes, and every time I log in.

Writing my own little shortcut to take advantage of my HomeKit outdoor sensor has been a fun experiment. For years, I’ve had an almost accurate temperature displayed in my menu bar. Now, it feels great to be able to glance up and read the actual temperature outside our window, along with an indicator telling me whether it’s getting colder or warmer. It is also quite satisfying to fulfill that itch that I often feel as an aspiring weather nerd.

If you want to use my shortcut to display data from your own HomeKit weather station in your menu bar:

  1. Download the shortcut;
    • If you prefer Fahrenheit over Celsius, download the shortcut using this link instead;
  2. Make sure you set your home address at setup;
  3. Make sure you select your temperature and humidity sensors at setup;
  4. Install Data Jar, open the app, then add 2 empty lists: one named ‘OutdoorTempHistory’, the other ‘OutdoorHumidHistory’;
  5. Install One Thing for macOS;
  6. Use a scheduler utility, like Lingon, to automatically run the shortcut at a regular interval.

Data Jar and One Thing are both available for free on the App Store.

The simpler version of Lingon that I used — Lingon 3 — is $4.99 on the Mac App Store. But you can also purchase the fully-featured Lingon X, priced at $16.99 if you buy it directly from Peter Borg Apps.

Access Extra Content and Perks

Founded in 2015, Club MacStories has delivered exclusive content every week for nearly a decade.

What started with weekly and monthly email newsletters has blossomed into a family of memberships designed every MacStories fan.

Learn more here and from our Club FAQs.

Club MacStories: Weekly and monthly newsletters via email and the web that are brimming with apps, tips, automation workflows, longform writing, early access to the MacStories Unwind podcast, periodic giveaways, and more;

Club MacStories+: Everything that Club MacStories offers, plus an active Discord community, advanced search and custom RSS features for exploring the Club’s entire back catalog, bonus columns, and dozens of app discounts;

Club Premier: All of the above and AppStories+, an extended version of our flagship podcast that’s delivered early, ad-free, and in high-bitrate audio.