Bake Mate - Pi Chef Blog #13 - Mobile notifications using IFTTT
With the first stretch goal complete (Bake Mate - Pi Chef Blog #12 - Stretch goal 1: A visual indicator using Sense HAT's RGB LED Matrix - Part 2 ), I decided to add mobile notifications.
I had proposed a system that lets Bake Mate generate an alert when the bake timer runs down to zero, but after Bake Mate - Pi Chef Blog #6 - Measuring Oven Temperature , I realised that the thermostat in my oven isn't very accurate. Hence, Bake Mate will send periodic 'timer' notifications which reminds the user how much time remains, and 'temperature' notifications when the temperature in the oven fluctuates too far from the temperature required by the recipe..
Configuring IFTTT:
The notification service I'm using is the IFTTT (https://ifttt.com/ ) Webhooks (https://ifttt.com/maker_webhooks ). IFTTT (If This Then That) is a service that lets you connect different web services together to perform actions that are performed based on configurable logic. The Webhooks service is great for maker projects: as long as you've got a device that can make (in the case of Bake Mate) or receive a web request, you can use IFTTT to 'chain' it up to perform some action.
IFTTT supports many services: have a look at the list over here: https://ifttt.com/search/services. I could make it tweet something, send an email, turn off a fancy WiFi enabled oven or display a message on the dashboard of a Tesla (if I had one). In this case, I'll be using IFTTT simply to generate a notification on my phone when Bake Mate makes a request.
To get started, create an account and go to the Webhooks page to generate an API key.
The page lets you test it out too: enter the {event} - think of this a 'channel', and the values you want to pass as payloads.
But hold on, you first need something that will 'monitor' the webhooks channel and do something when the event is trigger.
These screenshots (L to R) show how I set up IFTTT to generate a notification when an event is triggered (though it looks like I've mixed up the screenshots - some show BakeMateTimer, and some show BakeMateOvenTemp.
The last screenshot shows how IFTTT lets you format the data received as a String that is displayed in the notification. I passed the Recipe name, actual temperature and required temperature as payloads (values 1,2,3) and typed out the message I wanted to be displayed. IFTTT inserts the values as configured.
I tested it out using the IFTTT page, and then integrated it with the Bake Mate Python application.
import requests IFTTT_WEBHOOKS_URL = 'https://maker.ifttt.com/trigger/{}/with/key/ def post_ifttt_webhook(event, value): data = {'value1': value} # The payload ifttt_event_url = IFTTT_WEBHOOKS_URL.format(event) # Inserts event requests.post(ifttt_event_url, json=data) # Sends a HTTP POST request to the webhook URL post_ifttt_webhook('BakeMateTimer',75)
To make the web request, use Python's 'requests' to post the payload (formatted as json) to the URL provided.
Bake Mate will periodically generate a notification as the timer counts down, and when it nears zero. A function in 'BakePage' also generates a notification when the temperature deviates more than 20C from the temperature required by the recipe.
Here's what the notification looks like for BakeMateTimer and BakeMate OvenTemp:
One issue I noticed was that the notifications get delayed from time to time, though I'm not sure whether IFTTT was enforcing a rate limit because I was sending too many while testing it out. Another potential problem is that this won't work if you suddenly lose internet connectivity. A local MQTT service is an alternative, or even using the NFC board and Tasker: BakeMate sends the bake time to the phone, and Tasker sets an alarm!
Next time on 'Bake Mate':
- Watch Bake Mate in action in the kitchen, with a real recipe!
Top Comments