How to Communicate Temperature and Humidity Data with AI
This example shows how to build an AI voice agent that communicates temperature and humidity data to callers using an ESP8266 microcontroller, a DHT11 sensor, and SignalWire’s AI Agent. The walkthrough explains how to gather environmental data via an external API, process sensor output, and use the AI Agent to respond to caller queries and optionally send temperature or humidity information by SMS.
SignalWire's AI Agent for voice allows you to build and deploy your own digital employee with intelligent, personalized interactions that redefine customer experiences. Powered by advanced natural language processing (NLP), these digital employees understand caller intent, retain context, and generally behave like a human.
If you’re interested in using AI to gather and communicate environmental data, this code walkthrough will show you how to integrate an ESP8266, a popular microcontroller, with a DHT11 sensor to gather temperature and humidity data. You can then leverage the power of SignalWire's AI Agent to process and respond to user queries regarding this data.
In this post, we'll explore how to leverage ESP8266, thingspeak.com, and the DHT11 sensor data to interact seamlessly with SignalWire's AI technology. For a more straightforward demo that uses public APIs and has no hardware requirements, check out the Weather Bot example.
This example shows you how to create an AI voice agent that a caller can contact to ask for data on the temperature and humidity of a specified location. Then, if the caller asks, it can send a text message reiterating that information.
In the GitHub repository, you'll find all the necessary files and resources to kickstart your own sensor bot project.
sensor_data Function
Perl modules:
LWP::Simple for fetching data from the web,
JSON for parsing JSON data,
Plack for creating a simple web application, and
SignalWire::ML for constructing responses (assuming this is part of your application's architecture).
Setting up the Perl script
To begin, ensure you have Perl installed on your system along with the required modules. You can easily install missing modules using CPAN.
Import the required modules at the beginning of your script to lay the foundation for seamless integration:
Fetching JSON data
Now, define the URL for the JSON data containing environmental information from a specified channel using ThingSpeak's API.
We'll use LWP::Simple's get function to retrieve the data securely:
Processing the JSON data
Once we have the JSON data in hand, it's time to decode it into a Perl data structure using the JSON module.
From there, we'll extract the temperature and humidity values from the latest feed entry:
Constructing the HTTP response
With the sensor data, craft a response using Plack::Response. Set the content type to application/json:
Include the temperature and humidity information in the response body:
Finalizing the response
Our response is primed and ready to go. We'll finalize it and return it from our application, completing the interaction loop:
The prompt
The prompt is the backbone of your AI agent, used to define its personality, functions, and parameters. You can easily customize it with plain language instructions.
With ESP8266, the DHT11 sensor, and SignalWire's AI agent, we've created a sophisticated sensor bot capable of providing real-time environmental insights. You can use this to monitor the climate of an attic or basement or just explore new IoT horizons!
Have any questions as you’re building an AI agent? Bring them to our community Discord!
Frequently asked questions
What hardware is used in the temperature and humidity bot example?
This example uses an ESP8266 microcontroller and a DHT11 temperature and humidity sensor to collect environmental data and make it available to the SignalWire AI Agent.
How does the bot fetch and process sensor data?
The tutorial shows using a Perl script to fetch JSON data containing temperature and humidity values from an external API (such as ThingSpeak) or from microcontroller output, decode it, and extract the readings for use in responses.
How does the AI Agent deliver temperature/humidity responses to callers?
Once the environmental data is available, the AI Agent uses conversational prompts to answer caller requests about temperature or humidity and can also send follow-up text messages with the same information.
Do I need SignalWire AI Agent to build this bot?
Yes. The AI Agent is used to handle conversational voice interactions, interpret user intent, format responses, and manage the workflow that delivers sensor data to users calling the agent.