Wiznet makers

nabia3400

Published August 21, 2023 © 3-Clause BSD License(BSD-3-Clause)

0 UCC

0 VAR

1 Contests

0 Followers

0 Following

Smart AC Recomender System ChatGPT+VoiceRecognition+Telegram

"[AIoT] Smart AC Recomendation System with ChatGPT+ Voice Recognition + TTS +Telegram Notification"

COMPONENTS Hardware components

WIZnet - W5300-TOE-Shield

x 1


DFRobot - Gravity: DHT11 Temperature Humidity Sensor For Arduino

x 1


ST - NUCLEO-F429ZI

x 1

Software Apps and online services

Eclipse - Paho MQTT

x 1


PyCharm - Pycharm

x 1


Arduino - Arduino IDE

x 1


InfluxData - InfluxDB

x 1


PROJECT DESCRIPTION

SMART AC RECOMMENDATION SYSTEM WITH CHATGPT +VOICE RECONIGTION +TTS +TELEGRAM NOTIFICATION 

 

INTRODUCTION :

Imagine having an intelligent assistant that not only keeps you comfortable but also helps you save energy. Our AIoT project brings this vision to life by creating a seamless connection between the outside world, your home, and smart decision-making.

We gather real-time weather data like temperature and humidity from the world outside, and at the same time, we keep track of the indoor climate using specialized sensors. We're even attentive to whether your AC is running or not, because every little detail matters.

All of this valuable information gets stored in a digital vault called a time series database. It's like a giant digital journal that captures how things change over time. But the real magic happens when we use advanced AI techniques to analyze all this data. It's like teaching our system to understand patterns and predict the future, but for home comfort!

When you have questions or need advice, our friendly AI assistant, powered by ChatGPT, is here to help. Wondering when to turn on the AC to avoid heat or humidity? Just ask! Our AI assistant dives into the treasure trove of data, looks at how the weather has been behaving, how comfy your home is right now, and even what your AC has been up to. Then, it cleverly suggests the best times to switch on the AC for maximum comfort and energy savings.But that's not all – we make sure you receive the advice in a way that suits you. Our AI can talk! You'll get to hear its recommendations spoken aloud, just like having a conversation. And if you prefer, you'll also receive the advice through your Telegram app.

What's truly exciting is that this system learns and evolves. The more people use it, the smarter it gets at predicting the best AC times. So, it's not just about making you feel cozy – it's about making homes smarter, saving energy, and contributing to a happier planet. Welcome to the future of intelligent home comfort!

 

HARDWARE USED:

  1. WIZnet-W5300 TOE SHIELD + STM32-F429ZI board
  2. DHT11
  3. Jumperwires
  4. Bread Board
  5. Microphone
  6. Capaciter(100uF)
  7. Resistor(22K ) x 2
  8. SCT013-  Current Sensor Clam

SOFTWARE USED:

  • MQTT SERVICE
  • PYCHARM
  • ARDUINO IDE
  • INFLUXDB

PROGRAMMING LANGUAGES:

  • C++
  • PYTHON

APPS AND ONLINE SERVICES USED:

  • MQTT BROKER
  • OPENAI
  • INFLUXDB
  • TELEGRAM API

 

MQTT Broker: An MQTT (Message Queuing Telemetry Transport) broker acts as a communication hub for IoT (Internet of Things) devices and applications. It facilitates the exchange of messages through the publish-subscribe pattern, where devices publish messages to specific topics, and interested parties subscribe to those topics to receive the messages. The MQTT broker ensures efficient and scalable communication between devices and applications, making it a crucial component in IoT ecosystems. It enables real-time data exchange, remote control, and coordination among devices.

OpenAI: OpenAI offers advanced language models that can comprehend and generate human-like text. These models, like GPT-3.5, can analyze data and generate insightful responses based on input prompts. By interfacing with OpenAI's API, developers can leverage the power of natural language processing for tasks such as data analysis, content generation, and more. OpenAI models have the ability to understand context, generate creative text, 

Setting up with OpenAi :

  1. https://openai.com/   Go to this link
  2. Go to menu and then Sign up (Create a new account) or otherwise just Log in 
  3. Then you can see above three options go to API for generating the API Key.
  4. Then go to à Personal  à view API Keys 
  5. From Create new secret key option you can create a new API , It will
  6. generate once and have take a copy of that.

 

and provide recommendations, enhancing applications with human-like language understanding and generation capabilities.

InfluxDB: InfluxDB is a specialized database designed for storing and querying time-series data. It's optimized for managing data with timestamps, making it ideal for scenarios where data points are associated with specific time intervals. InfluxDB allows you to efficiently store large volumes of data generated by IoT devices, sensors, and monitoring systems. It provides features for data retention, querying, and aggregation over time intervals. InfluxDB's time-series capabilities make it a reliable choice for tracking and analyzing data trends, anomalies, and historical patterns.

This below image shows the data I have stored in this Database

Telegram API: The Telegram API enables developers to integrate Telegram messaging capabilities into their applications. Telegram is a popular messaging platform known for its security and feature-rich environment. With the Telegram API, developers can create bots that can send and receive messages, multimedia, and interact with users. This integration allows applications to deliver notifications, updates, or responses directly to Telegram chats. Telegram bots can enhance communication, facilitate data sharing, and enable automation in various domains, including IoT, analytics, and user interactions.

 

WORKFLOW:

1. User Voice Command:

   - The user interacts with the system by giving a voice command through a device, such as a smartphone or a smart speaker. For instance, they might say, "When should I turn on the AC today?"

2. Speech-to-Text Conversion:

   - The voice command is captured and converted into text using a speech-to-text technology. This transforms the spoken words into a format that can be processed by the AI system.

 

3. Query Sent to Data Retrieval Module:

   - The converted text query is passed to a data retrieval module, which contains Python code and queries specifically designed to fetch historical time series data from the InfluxDB database. This data includes details about external weather conditions, indoor climate measurements, AC status, and other relevant variables recorded over time.

 

4. Data Sent to OpenAI Model:

   - Once the relevant data is fetched from the InfluxDB database, it's sent to the OpenAI model as input. The data provides context for the user's query and allows the AI model to understand and analyze the user's question accurately.

 

5. Data Analysis by OpenAI:

   - Using the received historical time series data, the OpenAI model processes the information to identify patterns, correlations, and trends. It considers factors like past AC usage, weather trends, and comfort levels to formulate a suitable response.

 

6. Text-to-Speech Conversion:

   - After analyzing the data, the OpenAI model generates a response text suggesting the optimal time to turn on the AC. This response text is converted into speech using a text-to-speech synthesis tool.

 

7. Voice Response to User:

   - The synthesized voice response is played back to the user through a speaker or audio output device. The user hears the AI's recommendation spoken aloud, providing a natural and convenient interaction.

 

8. Telegram Bot Notification:

   - Simultaneously, the response generated by the OpenAI model is sent to the Telegram bot. The bot then forwards the recommendation as a text message to the user's Telegram account.

 

SETTING UP USING PYTHON:

Setting up with MQTT:

import paho.mqtt.client as mqtt

paho.mqtt.client: This library provides a client implementation for MQTT (Message Queuing Telemetry Transport), a lightweight messaging protocol widely used in the Internet of Things (IoT) domain for communication between devices. It allows you to connect to an MQTT broker and publish messages to topics or subscribe to topics to receive messages. It's commonly used for real-time data transmission in IoT applications.

Installation: To install the paho-mqtt library, you can use pip, the Python package manager. Open your terminal or command prompt and run the following command:

 pip install paho-mqtt

 

Setting up with OPENAI:

import openai

openai: This library provides a Python interface for the OpenAI API, allowing you to interact with various natural language processing models and services provided by OpenAI. With this library, you can access powerful language models like GPT-3 to perform tasks such as text generation, language translation, question-answering, and more.

Installation: To install the openai library, you can use pip as well. Run the following command in your terminal or command prompt:

pip install openai

         

Setting Up with Recogniser:

import speech_recognition as sr

This library provides an easy-to-use interface to work with various speech recognition APIs. It allows you to convert spoken language into text and supports multiple speech recognition engines, such as Google Web Speech API, Microsoft Bing Voice Recognition, and more.

Installation: To install the speech_recognition library, you can use pip:

pip install SpeechRecognition

Setting up with InfluxDB:

import influxdb_client
from influxdb_client import InfluxDBClient, Point, WritePrecision
from influxdb_client.client.write_api import SYNCHRONOUS

influxdb_client:

This library allows you to interact with InfluxDB, a time series database, using Python. It provides functionalities to read and write data to the database, perform queries, and manage database operations.

InfluxDBClient, Point, WritePrecision:

  • InfluxDBClient is a class that provides the necessary methods to establish a connection to an InfluxDB server. It allows you to configure connection settings such as the server's URL and authentication credentials.
  • Point represents a data point in InfluxDB. It lets you define measurements, tags, fields, and a timestamp for the data you want to write.
  • WritePrecision is an enumeration that specifies the precision of the timestamp when writing data points to InfluxDB.

Setting up with Datetime and timedelta:

from datetime import timedelta, datetime

  • datetime is a module that supplies classes for manipulating dates and times. It's used to work with timestamps and time-related calculations.
  • timedelta is a class within the datetime module that represents the difference between two dates or times. It's useful for adding or subtracting time intervals.

 

Setting up with TTS:

import pyttsx3

This library is a text-to-speech (TTS) engine that allows you to convert text into speech. It's useful for applications where you want your computer or device to speak out information to the user.

Installation: To install the pyttsx3 library, you can use pip:

pip install pyttsx3

Setting up with Telegram:

 import telebot 

Telebot is a Python library that interacts with the Telegram Bot API. It simplifies the process of creating and managing Telegram bots. You can use it to send and receive messages, multimedia, and other content through Telegram bot interactions.

 

Configuration with Hardwares:

SCT 013-030 sensor is adept at detecting current flow on the AC power line. However, it's worth noting that the system's effectiveness lies in its ability to determine when to power down based on actual consumption, even though the program primarily relies on current measurements. There are occasional instances where this setup might not fulfill its task due to specific conditions. Nonetheless, within the realm of a limited number of household electrical devices, where the system is calibrated, it has proven to be operational and dependable. The following circuit diagram is easy for connecting the SCT013 to the board 

Reference: http://myelectronichome.altervista.org/blog/en/too-much-current-detector-absorbed-from-the-house-made-with-arduino-and-sct-013-020-or-013-030-sct/?doing_wp_cron=1692532913.0866019725799560546875 

 

CIRCUIT DIAGRAM:

The DHT11 (Humidity – temperature Sensor) has 3 pins GND , VCC , Signal 

  • VCC is connected with 3.3v 
  • GND is connected with Gnd
  • Signal is connected with D15

The SCTO13 (current sensor clam) that whole connection as we can see has 3 pins GND , Output , VCC 

  • VCC is connected with 5v
  • GND is connected with same Gnd 
  • Output pin is connected with D14

CONNECTION DIAGRAM :

 

 

SAMPLE UTTERANCES:

          I have tested the below given utterances for opening and closing and it was working fine. More phrases can be possible:

Recommendation:

  • System What is the right time to turn on the AC today 
  • System What is the best time to turn on the AC today
  • System What is the recommended time to turn on the Ac 
  • System Suggest a Suitable table to turn on the AC
  • System Recommend best time to turn on the AC today

OUTPUT: 

Its giving voice responses and also giving responses in telegram 

Video :

Code Explanation:

Check Out the documentation in github

Documents
  • Source Code

    Python Source code and Arduino Source code

  • Circuit And Connection Diagram

    Both circuit and connection diagram

  • Code Explanation

    Documetation has full source code explanation

Comments Write