Controlling humidity with a MongoDB Stitch HTTP service and IFTTT

October 08, 2018 0 Comments

Controlling humidity with a MongoDB Stitch HTTP service and IFTTT

 

 

I've long been a fan of using IFTTT as a quick and easy way to automate my home/life by connecting cloud and IoT services. My IFTTT Applets are what make my study lights flash when my Amazon Alexa timer expires in the kitchen; they're what add my FourSquare check-ins to my Google calendar and MongoDB database.

I have a dumb dehumidifier in my study, and I wanted to make it a bit smarter using MongoDB Stitch. I use an ElectricImp IoT device to send periodic temperature and humidity sensor readings to my Stitch app. The Stitch app then fetches weather data from DarkSky.net and stores the combined data in a MongoDB collection. I have a dashboard that lets me view that data over time.

Based on the latest humidity and temperature, a Stitch function decides whether to turn the humidifier on or off. The function then uses a Stitch HTTP service I created to send a request to an IFTTT Maker service webhook with the desired state (on|off).

exports = function(temp, humidity){ var IFTTT = context.services.get("IFTTT"); // The humidifier is very inefficient if room is too cold, so only turn // it on if the humidity is too high and temperature is high enough var state = "dry"; if (temp > context.values.get("minTemp")) { if (humidity > context.values.get("maxHumidity")) { state = "damp"; } } IFTTT.get({"url": "https://maker.ifttt.com/trigger/" + state + "/with/key/" + context.values.get("MakerIFTTKey")}) .then(() => { console.log("Sent IFTTT request"); });
};

The webhook uses the TP-Link Kasa IFTTT service to send an on|off request to my smart plug:

IFTTT Webhook to turn plug on

You can recreate this Stitch app for yourself by downloading the app from GitHub and importing into Stitch. You'll need to set some of your own keys first (including the details of your IFTTT webhook address) – details are in the README. The repo also includes the ElectricImp device and agent code.

Creating your first Stitch app? Start with one of the Stitch tutorials.

Want to learn more about MongoDB Stitch? Read the white paper.


Tag cloud