Here is a quick and easy way to get your Intel Edison connected to the Internet !! using the simple python program below to connect to IFTTT.
If you have been living under a rock and not heard about IFTTT, here is a quick intro from Wikipedia - IFTTT (If This Than That)is a free web-based service that people use to create chains of simple conditional statements, called applets. An applet is triggered by changes that occur within other web services such as Gmail, Facebook, Instagram, or Pinterest. An applet may send an e-mail message if the user tweets using a hashtag or to copy a photo on Facebook to a user's archive if someone tags a user in a photo.
In my scenario, the applet is triggered by the python code below and data is posted to the IFTTT maker channel, this basically is the IF side of things.And, as part of the data send you can send sensor values as part of the payload , which in case of the program below is Temperature, Light value and the potentiometer value. And as part of THEN side of things you can basically trigger various things like -
- Send an email to your self with the sensor values.
- Send your self a text message if the temperature in your home is to high
- Turn on the lights in your house when it gets dark, in my case the idea is to turn on the Phillips Hue Lights.
- And, in addition I have also setup another recipe to cycle through various colors of the Hue bulb, which I am calling party mode
<i will post a short video of the setup over the weekend>
To create a new recipe to send sensor values from the the Edison via an email when the python program below is triggered, click the new applet button and follow the steps as shown in the screenshots below
{gallery} IFTTT recipe to send email |
---|
Once you click the New Applet button , click the + this link |
As part of the service on the IF side select the Maker Webhooks channel |
Type in the event name - from_edision and hit Create trigger, this will be refrenced in the python code |
Now select the +that section |
As part of the That action seach for Gmail |
Fill in the details for email, here the Value1, Value2 and Value3 are part of the payload section in the python code. |
Once done hit the review and finish button. |
Here is the python program to trigger the IF side of things aka the Maker webhooks,
#!/usr/bin/python # Create by Carmelito to send sensor data to IFTTT so that you work your magic,this is based on # Grove Light sensor https://github.com/intel-iot-devkit/upm/blob/master/examples/python/grovelight.py # Grove Temp https://github.com/intel-iot-devkit/upm/blob/master/examples/python/grovetemp.py # Grove Pot https://github.com/intel-iot-devkit/upm/blob/master/examples/python/groverotary.py import requests from time import sleep from upm import pyupm_grove as grove #get the api key from Maker Webhooks channel https://ifttt.com/services/maker_webhooks/settings #example URL https://maker.ifttt.com/use/xxxxxxxxxxxxxxxxxxxxx api_key = 'xxxxxxxxxxxxxxxxxxxxx' event = 'from_edison' #Grove Pot connected to connected A0 on the Grove shield potSensor= grove.GroveRotary(0) #Grove Temperature sensor connected A1 tempSensor = grove.GroveTemp(1) #Grove Light sensor connected A2 lightSensor = grove.GroveLight(2) def send_IFTTT_event(api_key, event, temp=None, lightValue=None, potValue= None): #posting data to IFTTT url = "https://maker.ifttt.com/trigger/{e}/with/key/{k}/".format(e=event,k=api_key) payload = {'value1': temp, 'value2': lightValue, 'value3': potValue} try: requests.post(url, data=payload) except requests.exceptions.RequestException as resp: print("Error from IFTTT: {e}".format(e=resp)) def main(): temp = '0' lightValue = '00' #Getting Pot value potValue = potSensor.abs_value() print("Pot value: " + str(abs)) sleep(1) #Getting grove temperature value print(tempSensor.name()) for i in range(0, 10): celsius = tempSensor.value() fahrenheit = celsius * 9.0/5.0 + 32.0; print("%d degrees Celsius, or %d degrees Fahrenheit" \ % (celsius, fahrenheit)) temp = fahrenheit #Getting light sensor value print(lightSensor.name() + " raw value is %d" % lightSensor.raw_value() + \ ", which is roughly %d" % lightSensor.value() + " lux"); lightValue = lightSensor.raw_value() sleep(1) send_IFTTT_event(api_key, event, temp, lightValue, potValue) if __name__ == "__main__": main()
As part of the code replace the api_key with your key, which you will find at https://ifttt.com/services/maker_webhooks/settings
Here is the sample email recived once the program run
On the similar lines, you can setup more recipes on IFTTT to trigger as shown in the screenshot below. For the Hue setup you will have to register your Hue bridge online or via the Phillips hue app on your phone.
{gallery} More IFTTT recipies |
---|
Recipe setup to send text messages |
Sample Text message recived with temperature and light reading from Edsion |
Recipe to turn on your Hue lamp, for this you will have to select Hue on the Then side of the recipe |
Recipe for the Hue Color bulb to change the color of the bulb slowly, setting up party mode, for this you will need a Hue Color bulb. |
Lamp on top of the side table has the Color Hue bulb which cycles through the colors. And the lamp on the floor has the white bulb. |
Top Comments