How to connect a Electric Imp to Altair SmartCore and build an Alert System.

0. Introduction

This easy tutorial helps you to build an Alert System for your home or office.
To do this, we use a Electric Imp able to detect light and Altair SmartCore Engine to send alerts by email.
In this project you will learn how to:

  • Connect a Electric Imp to Altair SmartCore to send data streams using Altair SmartCore HTTP REST API
  • Build an Alert App on Altair SmartCore by programming a Listener to send an email using the SDK



  • 1 x April Electric Imp board.
  • 1 x electric imp device
  • 1 x Tiny Breadboard
  • 1 x Resitance. Range between 200KΩ and 10KΩ
  • 1 x Foto Sensor. Try to improve the project with a motion detection sensor
  • 1 x 1uF capacitor. An alternative is to use an Analog-to-Digital Converter chip (ADC)
  • Several breadboard wires. Just for make the connections
  • Optional. Not needed during experiment
    • 1x led

Music to listen: Cosmosoul - Powerfull


1. Project Schema

This project is a quick way to create an alarm app and understand the basics of combining Electric Imp and Altair SmartCore.

Here is overall diagram of the project:

  • Schema

Electric Imp is programmed to send a data stream to Altair SmartCore stating whether or not receiving light

All the data streams sent by Electric Imp are collected and stored in Altair SmartCore. Altair SmartCore is a huge database that collects all the information that your sensors send.

In addition to storing data, the true power of Altair SmartCore is to let you build Apps very quickly with few lines of Groovy code. In this scenario we are going to build a very simple Alert App that sends an email to you in case that Electric Imp detects light.

With Altair SmartCore you can build very complex Apps to support all the logic of your product on the cloud and integrate it with other devices and IT systems. But for now let’s keep it simple.

Although this Alert App is very simplistic, you can use to detect someone enters in a dark room and turns on the lights. In fact this project is quite useful in our data-center, where light are always turned off.


2. Electric Imp. Connections description

To read the values ​​of an analog sensor we have followed the "Getting Started" tutorial in: At the end of the tutorial you'll find more examples that will help you.

The connections in Electric Imp are extremely simple and very similar to the others tutorials that we have. You can see in the diagram below.

  • Diagram


3. Altair SmartCore Project and Device Registration


If youre registered in Altair SmartCore, you have a default device already created for you.
Check your control panel and see what it looks like.
Basically you need the device id_developer that might be something like defaultDevice@myusername.
But if you want, you can create a new device and use it in this example.


Now, go to your control panel “My account menu” and check your Apikey.
Its a big alphanumeric token like:
You need this number to complete the example.


4. Data Transferred from Electric Imp to Altair SmartCore

From Electric Imp you have to build a HTTP request and send the data.

  • HTTP request
    POST /streams HTTP/1.1
    Accept: application/json
    User-Agent: ElectricImp-SmartCore
    Content-Type: application/json
    Connection: close
  • Data
    "data":{"light":"YOUR DATA HERE"}


5. Code implemented on Electric Imp

You should change some values with your own, like constants API_KEY or Device



You can check this code in github at


6. Checking Data is collected in Altair SmartCore

If you get here, your device must be sending streams when you turn on and turn off the lights.

Its time to test our control panel and check if we have new streams.
Go to “Data management” → “Data streams” and you will see your data.

  • menu option
  • new data


7. Creating an Alert with Altair SmartCore Listeners

A listener in Altair SmartCore can be associated to any hierarchy entity, from Project to Device. If you associate a listener to a project, all devices below the services of that project will be affected. If you associate a listener to service, all devices below the groups of that services will be affected. And so on.

In this example, we create a listener associated with our device. This listener waits for an event to occur in the context of the device and then evaluate the content.

To create a listener go to the control panel, then to “Rules” → “Listeners” and click on the new button. Select "Device" as "entity type" and select your device on the "Id" field.

Fill the fields with the following values and save the new listener

  • Name: The name that you prefer
  • Description: The description that you prefer
  • Entity type: Device
  • Entity id: Your id device
  • Event to listen: data_persisted
  • If expression:"ON"
  • Then expression:
    def email = new Email ();"YOUR EMAIL HERE";
    email.subject="ALARM CHANGE"
    email.message="Alarm ON";
  • Then rule: leave empty
  • Else expression:
    def email = new Email ();"YOUR EMAIL HERE";
    email.subject="ALARM CHANGE"
    email.message="Alarm OFF";
  • Else rule: leave empty
  • Be sure to have your listener enabled if you want it to be executed

Its time to test our listener. Send a data stream to this device, check your control panel and your inbox!!!


8. From here on: Enhancing the project

Now you know how to connect a Electric Imp device to send data to Altair SmartCore and how to create a simple App with a single Listener and some SDK programing in Groovy. But you can enhance this project in many ways:

  • Try to add a temperature sensor to the Electric Imp and send at least two values: light and temperature
  • Create your own control panel to check the status of the Electric Imp, by building an HTML page with a request to our API to ask for the status value of your device
  • Create another device that you can interact with (like a sound alarm) and build an app combining actions between the two devices through Altair SmartCore