The Amazon Echo and the Alexa assistant are amazing innovations that enable many daily life interactions. Already incorporated in my morning routine, one of the first things I do when I wake up is ask Alexa about the current weather. Now that winter is coming, I usually do it from under my blankets. Before getting out of bed I also want to know what is the temperature in my apartment so I know how to face it.
I live in an older apartment building where smart thermostats are out of the question. My main baseboard heaters are controlled by old-school thermostats but I have an additional radiator connected to a smart plug (TP-Link) that I can turn on and off using Alexa. I still needed to know how cold is it before deciding whether I want to turn it on and stay a little longer in bed.
The solution to my problem was to plug a USB thermometer (TEMPer) to an extra Raspberry Pi I had lying around and have it talk to Alexa. I couldn’t find any general purpose projects so I decided to attempt mine. The idea is quite simple, an API receives messages (such as current temperature as recorded by the Raspberry Pi) and stores them. Then Alexa can access the stored messages and read them aloud. When I first heard about the daily briefing API I was really excited about being able to incorporate these as part of the daily briefing but currently that is not yet possible.
The API is already publicly available and I plan on extending it soon. Here is a demo console that can be used to interact with the API or to send yourself reminders and other personal messages:
You can enable the skill here:
To replicate my setup:
- Enable the skill and navigate to the Alexa app at http://alexa.amazon.com to get your user identifier and secret. Setup your Raspberry Pi and get your USB thermometer working. In my case I am using this library: https://github.com/padelt/temper-python
- Check the code repository for two examples in Python and Bash for scripts that poll the current temperature and post it to the API (both tested in the current Raspbian).
- Replace the user identifier and secret in either script and add your scripts to crontab.
Slack Slash Commands
Someone asked me if it would be possible to integrate this with Slack. There are definitely multiple ways of doing so. I opted for an easy approach, all server side. To integrate with Slack, I choose to allow users in a team to add their Alexa accounts to the team (it could be in a per-channel basis as well, just not there yet). Then, anybody can post to all the registered message boards using a slack command from any channel in a team. To enable Slack integration:
- First create two slash commands in Slack (this is needed only once per team). Click in the dropdown next to your team name and select “Apps & integrations”, then the “Manage” tab in the top, then “Custom Integrations” tab in the left, then “Slash Commands”.
- Click “Add Configuration”. In the configuration screen, set the Command to
/postmb, set the URL to
https://l7kjk6dx49.execute-api.us-east-1.amazonaws.com/prod/postedmessage/slackand set the Method to
POST. The rest of the settings are optional. Click “Save Integration”.
- Click “Add Configuration” again. Use the same URL and Method but change the command to
/setupmb. Click “Save Integration”.
Read More: Alexa Message Board (now with Slack!)