Pebble Smartwatch

Pebble Tricks

Article from Issue 175/2015

Using a couple of apps and a bit of coding, you can teach your Pebble smartwatch some clever tricks.

Although Pebble [1] isn't the most advanced and prettiest smartwatch out there, it has its advantages. Pebble is relatively inexpensive, and it has excellent battery life and a decent selection of apps (or watchapps in Pebble parlance). Of course, if you are proficient in C, you can write watchapps and watchfaces yourself. However, those without advanced coding skills are not precluded from devising clever Pebble-based solutions.

Sending Custom Push Notifications

Receiving and managing notifications from your wrist is probably the raison d'être of any smartwatch, including Pebble. The Pebble app for Android and iOS lets you receive notifications from practically any app installed on your Android phone or iPhone, but what if you want to send custom push notifications from other sources?

Suppose you build a web app, and you want to add the ability to send notifications to your Pebble smartwatch when a certain event occurs. One way to do that is to use a service like Pushover [2], which allows you to integrate notification functionality into your software projects. To use the service with your Pebble smartwatch, you need to create a Pushover account and install the Pushover app on your Android device. Next, open the Pebble app and switch to the Notifications section. Tap the All apps item and enable the Pushover app. Then open the Pushover app on your Android device and complete the setup.

Some applications and services provide support for Pushover, so you can enable notification functionality without writing a single line of code. GitHub, for example, allows you to enable Pushover notifications for any of your repositories (Figure 1). To do this, navigate to the repository's settings page, switch to the Webhooks & Services section, and add the Pushover service.

Figure 1: Adding the Pushover service to GitHub.

Pushover is also available as a channel on the popular IFTTT [3] service. This feature allows you to create so-called recipes that push notifications to your Pebble smartwatch when specific events occur.

When you create a Pushover account, the service automatically generates a unique user key. To use Pushover with your own software projects, you also need to obtain an API token. To do this, go to, click on the Create a New Application link, and fill out the required fields (Figure 2). Press the Create Application button to add the application and generate an API key.

Figure 2: Creating a new Pushover app.

Pushover provides a simple API that makes it possible to add notification functionality to your scripts and applications with a minimum of effort. To send notifications from shell scripts, you can use the curl tool. All you have to do is specify a few mandatory values, such as the API and user keys and some notification text using the --form-string option (it emulates a filled-in form in which a user has pressed the submit button):

curl -s --form-string "token=API_KEY" \
  --form-string "user=USER_KEY" \
  --form-string "message=Hello World! \

Using this simple command, you can instantly add notification capabilities to any shell script. If you run your own server and would like to be notified when it's down, you can whip up a simple shell script (don't forget to replace the target IP address as well as API_KEY and USER_KEY with actual values); see Listing 1.

Listing 1

Pushover Shell Script


The script pings the server and if the ping fails, the curl command sends a notification. Save the script, make it executable, create a cron job that runs the script at predefined intervals, and your quick-and-dirty server monitoring system is ready to go. Next time the server is down, a notification will be delivered straight to your wrist.

Because Pushover is supported by IFTTT, you can create all kinds of recipes that deliver notifications to your Pebble. With a bit of Python scripting magic, however, you can replace this web service with your own homegrown solution and learn a couple of useful techniques in the process. For example, suppose you want to be notified when the temperature outside reaches a specific threshold. The simple Python script in Listing 2 can help you with that.

Listing 2

Python Temperature Notification Script


The script uses the OpenWeatherMap service [4] to fetch current weather conditions in the JSON format. The temperature = data['main']['temp'] statement extracts the current temperature from the obtained data. The if condition then checks whether the current temperature exceeds the specified threshold, and if it does, the script sends a Pushover notification.

What else can you use notification functionality for? How about creating a simple web app that allows users to send short messages to your Pebble via a browser? You can use a Python script based on the Bottle framework (Listing 3) as a starting point. The script consists of a form containing a text field and a Submit button. When the user presses the button, the msg() function processes the contents of the field (i.e., extracts and truncates the text) and pushes the result as a notification.

Listing 3

Send Message Python Script


Pebble My Data Watchapp

Pushing and receiving notifications is not the only thing you can do with your Pebble. Using the Pebble My Data watchapp [5], you can turn your smartwatch into a hub of useful information.

This watchapp fetches and displays custom data in the JSON format stored on a remote server. Moreover, the watchapp can be controlled through the supported options in the JSON file. To get started with the Pebble My Data watchapp, first install it on your smartwatch and create a text file with the JSON-formatted content shown in Listing 4.

Listing 4

JSON Content


Save the file under the text.json name and move it to a web server. Then, point the Pebble My Data watchapp to the file, and you should see the Hello World! message. Besides the actual content, the JSON file has several options that control the watchapp's behavior. The refresh option, for example, defines the interval between updates in seconds, whereas the blink option forces the screen to blink the specified number of times. It's also possible to specify a font and a theme (light or dark) using the font and theme options. The watchapp supports options for controlling button behavior, too. You can specify the scroll offset using the scroll option and use the updown option to configure the Up and Down buttons for scrolling or polling the JSON file.

Using your favorite scripting language, you can pull data from different sources and generate a JSON file for use with the Pebble My Data watchapp. For example, because Python Bottle can output data directly in JSON format, you can use this lightweight framework to whip up a simple web app that fetches and processes weather data and serves it in the JSON format for use with the watchapp (Listing 5).

Listing 5

Python Script for the Pebble My Data Watchapp


Of course, you're not limited to weather data: With a bit of creative thinking and a few lines of code, you can make the script parse and serve practically any kind of data. For example, if you want to keep an eye on the server's uptime using your smartwatch, just add the following statements:

uptime = int(os.popen('cut -d. -f1 /proc/uptime').read())
days = uptime/60/60/24
hours = uptime/60/60%24
mins = uptime/60%60

This code obtains the uptime in seconds and then calculates the days, hours, and minutes values. Add

'Uptime: '.$days.' d '.$hours.' h '.$mins. ' min '

to the content variable to display the uptime in the watchapp.

Naturally, you are not limited to Python either. If you already have Apache (or another web server) and PHP running on the remote machine, you can write a similar script in PHP (Listing 6).

Listing 6

PHP Script for the Pebble My Data Watchapp


Final Word

Pebble is not the most advanced smartwatch out there, but you can transform it into a genuinely useful companion using apps like Pebble My Data and a dash of scripting magic. Additionally, you can use the examples in this article as a starting point for your own creations. The scripts in this article are available on GitHub [6], so you can dissect, study, and improve them to your heart's content.


  1. Pebble smartwatch:
  2. Pushover:
  3. IFTTT:
  4. OpenWeatherMap:
  5. Pebble My Data watchapp:
  6. Article scripts on GitHub:

The Author

Dmitri Popov has been writing exclusively about Linux and open source software for many years, and his articles have appeared in Danish, British, US, German, Spanish, and Russian magazines and websites. Dmitri is an amateur photographer, and he writes about open source photography tools on his Scribbles and Snaps blog at

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • A Python script warns of failed login attempts

    A number of sensors and cameras send author Mike Schilli a short message if someone tampers with his apartment door. He has now applied this security principle to the SSH entrance of his Linux computer.

  • JSON Deep Dive

    JSON data format is a standard feature of today's Internet – and a common option for mobile and desktop apps – but many users still regard it as something of a mystery. We'll take a close look at JSON format and some of the free tools you can use for reading and manipulating JSON data.

  • Gotify

    Replace proprietary cloud-based push notification services with a self-hosted open source notification solution.

  • Jasonette

    Jasonette makes it supremely easy to build simple and advanced Android apps with a minimum of coding.

comments powered by Disqus

Direct Download

Read full article as PDF:

Price $2.95