[DEPRECIATED] BitBar: Display & Control SmartThings from the macOS Menubar


Overview:

I was looking for something lightweight and an out-of-the-way solution to monitor sensors which didn’t require having a browser window open. I ended up finding BitBar which is an open source application that takes formatted output and displays it in the menubar. I then wrote the SmartApp and Python script to output and handle the rest of the logic.

Monitor SmartThings sensors from the Apple OSX Menu Bar. Currently it works for displaying temperature, contact, presence and motion sensors, and controlling switch/dimmer level devices, locks and also thermostat control. If there’s interest I can add more devices and features, or anyone in the community is welcome to modifying it.

Installation:

For the most up-to-date instructions, visit the GitHub page here

Section 1: Making the SmartApp available via the IDE

  1. Setup the SmartApp: Find your SmartThings IDE link (Note: USA Site URL).
  2. Click My SmartApps > then New SmartApp (top-right green button)
  3. Click the From Code tab and paste the SmartApp code from GitHub then click Create.
  4. Enable OAuth: Back at the My SmartApps page, click the little edit icon for the BitBar Output App, then click OAuth section, then click Enable OAuth in SmartApp.

Section 2: Installing the SmartApp

  1. Now for actually installing the SmartApp: On your mobile device in the SmartThings app > tap Automation > SmartApps > + Add a SmartApp (at the bottom). Go down to My Apps > select BitBar Output App.
  2. Before continuing to the next step, open the IDE Live Logging in a separate browser tab on the PC.
  3. On the BitBar app, tap Enable the API then tap Done. You should have a URL and secret displayed in the Live Logging screen tab.
  4. Copy/Save these two lines to input in the ST_Python_Logic.cfg in the step ahead.
  5. Back on your mobile device, tap Select Devices and choose the devices you want to display/control then tap Done.

Section 3: Setting up BitBar and ST Plugin

  1. Download and install the BitBar app here
  2. IMPORTANT: When selecting a plugin directory, make sure you create one that does not contain spaces. There were issues in an older release of BitBar if the path contained spaces, but supposedly it’s fixed, but I still had issues in some cases. If there were no spaces, it always worked.
  3. Download the ST plugin from GitHub. Copy ONLY the ST.5m.sh file to the plugin directory you specified along with the ST subfolder containing the Python script and the ST_Python_Logic.cfg (make sure these two files stay in the folder named ST). These files shoud be the only files in the plugins directory and the ST subfolder.
  4. Add your URL and secret to the ST_Python_Logic.cfg file: Open the ST_Python_Logic.cfg with a text editor of your choice. put the URL that was displayed in step 5 in the smartAppURL variable and Secret in the secret variable. Change any other variables for customization of the App.
  5. Save the ST_Python_Logic.cfg file in the ST subfolder.
  6. Start the BitBar app and you should see your status’ in the menubar!

Issues / Limitations:

  • Calling cURL via Python is not the best thing to do, but I wanted to make it as simple as possible using the built-in Python available in macOS/OSX. It would be better to use the requests library, but this requires setting up a new Python installation.
  • BitBar is capable of cycling through multiple status bar items, but all I really needed was to display one temperature sensor at the top with the rest in the dropdown. So the app only allows a selection of one temp sensor and a custom title (I didn’t want to use the full sensor name since menubar real estate is top dollar)
  • There is no alignment supported by BitBar so it’s all done by character spacing, which means using monospace fonts. Which also means a limited selection of pretty looking fonts. Menlo works good enough for me, but feel free to change it.

Misc Features / Tips

  • Hold Alt while menu is open to display battery information
  • Max items per sensor category can be set in configuration file (if you want to save space but still have access to the sensors)

I’m open to any feedback or suggestions/features! Let me know what you think!

Edit 2017-02-10: Updated instructions

15 Likes

@mattw This is a great application and I followed your install instructions!

I updated the following section in your BitBar Output App so that users can use the SmartThings IDE Logs page to easily copy/paste the required two lines of code into the Python script:

def updated() {
	log.debug "Bitbar Outout App updated with the following settings:\n${settings}"
    log.debug "##########################################################################################"
    log.debug "secret = \"${state.endpointSecret}\""
    log.debug "smartAppURL = \"${state.endpointURL}\""
    log.debug "The API has been setup. Please enter the following two lines into the ST BitBar Python script in your plugins directory."
    log.debug "##########################################################################################"

	unsubscribe()
	initialize()
} 

In running the Mac APP, I am getting a “Couldn’t possix_spawn: error 8” on the menu bar next to the Bitbar. I am trying to look through the python code to determine why. Your thoughts would be appreciated.

3 Likes

Really interested in this project, have got this to work but getting same spawn errors. Have 4 spawn error 8 icons on mine?

2 Likes

That’s a great idea, thanks for adding that in!

As for the extra icons in the menubar, any file that’s in the plugin directory BitBar tries to execute and create a new menubar item. So the only file that should be the top level is the ST.5m.sh (unless you have additional plugins), with the python script in the ST subfolder.

Also, another thing I forgot to mention, you can change the refresh interval by changing the 5m (meaning 5 minutes) in the filename of the ST.5m.sh file. 5 minutes worked well enough for me but you can always refresh it manually, too.

2 Likes

I assume you will update the GitHub so that others using will get that feature!

Erasing every non essential file in the bitbar designated plug-ins folder was the solution!

Yep, I just committed the change with your additional logging. I also changed the structure so it’s more clear which files are used for the plugin. I’ll probably add another page to the SmartApp before enabling the API saying to open Live Logging before continuing to be able to copy the data directly.

Glad that fixed it!

I added just a change to the python script to use images for switch status’ instead of emojis. There’s a variable to change back to emojis if needed.

1 Like

Getting error “Launch path not accessible”

In the menu, can you click “Run in Terminal …” and take a screenshot or copy/paste the output? Need to figure out if it cannot access the plugin directory or python script directory.

-bash: /Users/xxxxx/Documents/BitBar/ST.5m.sh: Permission denied

If I try to use sudo:

sudo: /Users/xxxxx/Documents/BitBar/ST.5m.sh: command not found

The first error looks like your user account doesn’t have access to the file. Are you using multiple user accounts? Can you paste the output from the following:

cd /Users/xxxxx/Documents/BitBar/
ls -l

The second error looks like the file is not set as executable. You can either do:

sudo sh /Users/xxxxx/Documents/BitBar/ST.5m.sh

Or make the file executable:

sudo chmod +x ST.5m.sh
sudo /Users/xxxxx/Documents/BitBar/ST.5m.sh

This shouldn’t affect how BitBar executes the script though. It still works if it’s not set with the executable attribute.

We just need to figure out why your user account doesn’t have permission to the file.

total 96
drwxr-xr-x 3 xxxxx XXXXX\Domain Users 102 Feb 6 09:22 ST
-rw-r–r–@ 1 xxxxx XXXXX\Domain Users 47611 Feb 6 09:11 ST.5m.sh

chmod: ST.5m.sh: No such file or directory

sudo: /Users/xxxxx/Documents/BitBar/ST.5m.sh: command not found

Finally worked through some formatting issues that were in the file when I downloaded but getting the following:

Traceback (most recent call last):
File “/Users/xxxxx/Documents/BitBar/ST/ST_Python_Logic.py”, line 45, in
temps = j[‘Temp Sensors’]
KeyError: ‘Temp Sensors’

Glad to hear you made some progress. That error is shown when there was an issue communicating with the API, most likely the SmartApp URL or secret is incorrect. I haven’t added extra error handling for parsing the return errors yet.

Can you verify the URL and secret are correct in the python script?

I just added some additional error handling when errors are returned from the API (committed the change to GitHub). This is only a change to the python script. So if double checking the SmartApp URL and Secret doesn’t fix the issue, updating the python script should give some additional information on the error.

That worked, I did set up a display sensor, but this is great. I love being able to do this on my mac instead of having to use my phone… Are you planning other functions such as door locks?

1 Like

Great to hear it’s working for you now.

@kurtsanders made some awesome changes a few days ago and I finally got around to merging them in. He moved the user input parameters into a new ST_Python_Logic.cfg file which helps keep the input separated. I expanded on the idea of formatting the temperature values by adding in a rounding parameter and also a parameter to match the decimal places of all values so they look more consistent in the menu. I didn’t really have much of an issue with this since all my sensors only report integers.

An example of the formatting in the configuration file:

  Original Values (after rounding)
    67.22
    65
    70.2
  Example 1 Output: True
    67.22
    65.00
    70.20
  Example 1 Output: False
    67.22
    65
    70.2

I also added in lock support display as well as toggling from locked to unlocked. If the toggle command is called and the device is in ‘unknown’ or ‘unlocked with timeout’ status, no action will happen.

The changes have been updated on the GitHub page in the first post. You’ll need to update the python script as well as copy the new ST_Python_Logic.cfg file into the same directory. Then copy your smartAppURL and secret to the cfg file.
The SmartApp code has been updated as well (to output and respond to lock requests).

Let me know if there are any issues!

1 Like

Looks good, only issue I run into is when I copy the text (Raw) from GitHub into my file I always run into formatting issues.

Can we make Presence sensors next, that would round out a great overview…

@mattw I have modified the smart app, python, and config files to show Presence data. Let me know if you would like the code updates.