Gravio Blog
November 15, 2022

Tutorial: How to use Sensors to Trigger Photos and Send them via E-Mail

We take a picture from a camera triggered by a sensor and send it to an e-mail address. This can be done with Gravio.
Tutorial: How to use Sensors to Trigger Photos and Send them via E-Mail


Gravio is an easy-to-use platform that enables anyone to create mini programs (called “Actions”) that can be built in a logic based manner which can be triggered from sensor data. In this tutorial, we learn how to trigger a camera taking a picture and sending it to an e-mail address.


We use a button sensor that triggers a camera to take a snapshot. The picture is then attached to an E-Mail and sent out to the recipient.



  • Gravio must be setup (any edition is fine, including free). If you need to set up Gravio, please follow these instructions
  • You need either a network camera or a USB camera. Note that the free version of Gravio only supports USB cameras. In this example we use a ONVIF Profile S network camera
  • You need a computer on which Gravio runs and the USB camera is plugged in (the network camera is accessible from)
  • For this particular example you will need at least the basic subscription and a button sensor


Step 1: Setting Up the Camera

Our camera is mounted on a balcony and pointing towards a harbour. It is connected wirelessly to the same network as the Gravio HubKit is running. In our case the HubKit is running on macOS. Gravio HubKit has the ability to detect local network cameras, which is why the network camera will show up in this menu:

Once you click on it, you can enter your credentials and your camera is ready to be used.

Give it a unique name and remember its physical Device ID.


Step 2: Setting Up the Sensor Data Layer

In our case here, the sensor is a simple Aqara button that can be pressed. First we pair the sensor with the Zigbee Dongle.

Plug the dongle into your computer

Restart your Gravio HubKit

Your Zigbee dongle will now show up under devices

Click the “Start Pairing” button and bring your sensor near the dongle. Press the “Pairing” button on the sensor for 5seconds until it appears in the log window

Next we add the area and data layer, and bind the new sensor device to it

Enable the sensor by checking the checkbox

Your sensor is now ready to receive data. You can check if the data comes in by opening the Data tab, activating the “Live” button at the top right and triggering the sensor

Once confirmed that data comes in, you’re ready to use the sensor data.

Step 3: Creating the Action

The next step is to create the action that will be triggered by the sensor. In our case our action will take a picture from the camera and attach the image to an e-mail that will be sent to a pre-defined e-mail address. 

Actions are created in the Action Editor

The action editor will open. Click the + signat the top right to add a new action. Give it a meaningful name and description

The action editor consists of components that are executed in sequence. You can add new components (or steps) by clicking the+ symbol in the square.

Enter the Device ID you remembered from Step 1 in the Device ID

If you add a path to “save to” the picture will be saved there

The filename will consist of the timestamp followed by the Device ID.

You can now trigger camera images to your location using play button on the top right.

Step 4: Setting up E-Mail

In this step we want to show how to use the pictures. For example to send them via an e-mail attachment to a predefined e-mail address.

First you need to add the “split” component in order to turn the array coming from the image capture component into a single item to be processed.

Then you add the E-Mail component and fill all the fields

Note, you can “hard code” the smtp server settings here, or you can create a “base profile” in the HubKit settings andre-use that.

Note, in order to use a gmail smtp, you need to change the security setting to “allow reduced security apps” to access the smtp server.

Then you fill out the pre-mappings by adding the attachment and the HTML code of the e-mail

Try it by pressing the Play button. If you receive the e-mail with the attached picture, you’ve done it!  

Now you’re now ready to trigger this action from the sensor data.

Step 4: Setting up the Trigger

The trigger is used to trigger an action. The action will receive the data from the sensor, however in this application here, we do not need any sensor data. The button just acts as trigger.

Open the Trigger tab and click on the lightning on the top right. Give the trigger a meaningful name, ideally describing what should have happened if it gets triggered, and pick the condition under which it should trigger the action

Switch to the Action tab and pick the Action you would like to trigger

That’s it. Press the button and you should see a picture in your saved file path and receive an e-mail with the picture attached.

This concludes the tutorial. If you have any questions, suggestions or ideas, feel free to join our slack under

Latest Posts
Coming Thursday, 25th April Learning Session: Learn about VQA with Hands-On Demos
Learn about VQA this April - an emerging technology concept out of AI
Friday, May 10, 2024
Read More
Unlocking Real-Time Efficiency: Understanding Webhooks
Webhooks are automated messages sent between apps in real-time when an event occurs, using HTTP POST requests. They deliver data instantly, reducing the need for regular API polling and bandwidth. Useful in factory automation, content management, and IoT, webhooks support efficient, real-time inter-app communication. Gravio's latest version supports both internet-based and local webhooks, enhancing data handling and responsiveness without constant polling.
Friday, May 10, 2024
Read More