Use a Raspberry PI to trigger Azure Automation runbooks

Dear all !

We hear so much about IoT and the Cloud so I thought, a practical example of how to  combine one of the most popular IoT devices, the Raspberry PI, with Azure Automation is appreciated.

Whats the use case?

When building this, you will have a Raspberry PI with a push-button, and when this button is pressed, an Azure Automation runbook is triggered.

I actually used that for my wife´s recent birthday, so every time the button was pressed by a guest, she received an E-Mail with birthday wishes.

A more business oriented approach could be manual measurement or recurring events, or a help button in a meeting room, which raises an incident when, i.e. the coffee machine does not work, a feedback system with 2 buttons (like, dislike), where you could record time, date and store it in PowerBI and so on …

What do i need ?

You need:

  • A Raspberry PI 3B or 3B+ (must have Wifi, even if this could be done with LAN connection as well …)
  • A button, which closes the circuit when you press it (see picture above)
  • An Azure Automation Account and a runbook which gets triggered by a webhook
  • A wireless network where the Raspberry can connect to and send webhooks (HTTPS) to the internet.
  • Little Linux Know How
  • Little Azure and PowerShell know how
How does it work ?

The basic concept is pretty simple:

  1. A button is pressed on the Raspberry
  2. A Python script, running on the Raspberry, using the GPIO module catches this event and fires off the webhook.
  3. The webhook triggers the runbook !
Step by Step guide
Step 1: Prepare the Azure Automation Account and runbook

Before you start with the Raspberry, make sure the Azure Automation Account (AAA) is setup correctly and you have a runbook which has also a webkook it can be triggered.

In my case i have created a seperate AAA called „Buttonbuddy“.

This AAA has one runbook called „pressaction“.

The code of this runbook is not that relevant, but i thought if you want to build something for your birthday party, i´ll share it.

So when your runbook is finished, test it on the testing pane and if it works, publish it.

Now, create a webhook, so that you can trigger this runbook externally.

This works by:

  1. Clicking on the runbook, to see details in the Overview blade
  2. Click on „Webhook“
  3. Follow the blade config to create a new Webkhook, by giving it a name and a expiry date
  4. Save the webhook URL (this is important, because it will disappear. it must be something like this (

Thats it for the Azure Automation side, lets now take care of the Raspberry.

Step 2: Prepare the Raspberry PI Hardware

Before we bring an OS to the Raspberry, we need to wire and mount the button to the device. I simply followed the instructions of the below link (credits!) to make it work.

Mounting the button into the board, means you need to drill a hole into the case. Be cautious, i broke one during drilling…  but finally the result should look like this:

Step 3: Install OS and configure the Raspberry

For ease of use i decided to use Raspbian (Debian based Linux) which you can find here:

Then install the OS on a SD card and boot your Raspberry. Configure LAN or WLAN as you wish, there must be internet connectivity available, otherwise the webhook target may never get reached. All the infos how to do that can be found here:


STEP 4: prepare the python script to trigger the webhook

Create a Python script in the home directory (or any other of your choice) of the user you login to the Raspberry.

The script content is based on the link for the hardware, slightly modified to be able to trigger webhooks:

When you run this script with the command:

and you press the button, you should see „Button Pressed“ on the console. and the webhook gets triggered.

Step 5: Autostart the python script

There are a lot ways to autorun something on Linux, i decided to use crontab. Edit the crontab file by typing:

Add a line at the end of this file with this content:

Now reboot your Raspberry (shutdown -r) and press the button.

Webhook should get triggered and yoiu have a buttonbuddy like me !

Hope you find that useful and fun like me, have fun building!


If you have any questions, look into this link to contact me.




One thought on “Use a Raspberry PI to trigger Azure Automation runbooks

Comments are closed.