Creating a custom Date-Time skill in Alexa using Python

by Jul 18, 2022IoT Connectivity

Introduction

In this tutorial, we will look at how to create a simple date-time skill in Alexa using Python. For this skill, the only prerequisites required are an Alexa developer account and some basic understanding of Python. Also, we have created a post on how to create a custom multiplication skill in Alexa. You can view the post by clicking here.

Creating the Date-Time Skill

The first step is to log in to your Alexa developer account. Following this, click on the Create Skill option.

Next, you’ll have to configure some basic settings of your skill as follows:

Settings for the date-time skill

Step 1: Give the skill a name. For eg. date time skill

Step 2: Select the language in which you want to build the skill. In our case, we choose English (US).

Step 3 : Choose the Custom model for our skill.

Step 4 : Select Alexa-hosted (Python) as the backend resource for our skill.

Step 5: Click on Create Skill.

In doing so, your custom skill will be created.

Skill Invocation Name

First, click the Skill Invocation Name option. There, you would be able to modify the skill invocation name.

Intents for the Date-Time skill

For our skill, we need two custom intents – PresentTime and PresentDay. In order to add the custom intent, click on the Add Intent option.

Now, we need to add sample utterances to each intent.

The intent for showing present time

The PresentTime intent is created in order to display the current time. We need to add some sample utterances which would map to this intent. For eg. “tell me the current time”, “give me the present time”, “what is the time now” etc.

The intent for showing present date

The PresentDay intent is created in order to display the present date. We need to add some sample utterances. For eg. “what is the date today”, “give me today’s date” etc.

Now that we have created our intents, we need to build our model. Click the Build Model option at the top.

Building the Model

Coding the Date-Time Skill

So, we have successfully completed building the model. Now, let’s start coding our model. For this, click on the Code option at the top. Next, open the lambda_function.py file which is the main code file.

First, let’s start by modifying Alexa’s response when a skill is launched. This can be done in the LaunchRequestHandler class

Alexa’s response when the skill is invoked

Next, we need to add two classes for our two custom intents, namely PresentTimeIntentHandler() and PresentDayIntentHandler(). The code for the two classes is as follows

from datetime import datetime

class PresentTimeIntentHandler(AbstractRequestHandler):
    """Handler for Present Time Intent."""
    def can_handle(self, handler_input):
        # type: (HandlerInput) -> bool
        return ask_utils.is_intent_name("PresentTime")(handler_input)

    def handle(self, handler_input):
        # type: (HandlerInput) -> Response
        now = datetime.now()
        present_time = now.strftime("%H:%M:%S")
        speak_output = "The present time is " + present_time

        return (
            handler_input.response_builder
                .speak(speak_output)
                # .ask("add a reprompt if you want to keep the session open for the user to respond")
                .response
        )
class PresentDayIntentHandler(AbstractRequestHandler):
    """Handler for Present Day Intent."""
    def can_handle(self, handler_input):
        # type: (HandlerInput) -> bool
        return ask_utils.is_intent_name("PresentDay")(handler_input)

    def handle(self, handler_input):
        # type: (HandlerInput) -> Response
        now = datetime.now()
        present_day = now.strftime("%B %d, %Y")
        speak_output = "Today's date is " + present_day

        return (
            handler_input.response_builder
                .speak(speak_output)
                # .ask("add a reprompt if you want to keep the session open for the user to respond")
                .response
        )

Here, we use the datetime class in Python to get the present time and date.

Also, we created a post explaining some of the basic methods used in the code. Click here to give it a quick read.

Subsequently, using the skill builder object, we need to add request handlers for our custom intents. The code for it is as follows

sb.add_request_handler(PresentTimeIntentHandler())
sb.add_request_handler(PresentDayIntentHandler())

As a result, the coding part is complete. Therefore, let’s deploy our model. So, click on the Deploy option.

Deploying the model

Testing the Model

Now that we have deployed the model, let’s test it out. Click on the Test option at the top. Enable skill testing to Development mode.

Testing

Conclusion

We have successfully built and deployed our custom model. On testing it, we have found that our custom intents are working properly. Hope that this tutorial was informative and worth your time.

Happy Learning!

Creating a multiplication Skill in Alexa using python

Written By Monisha Macharla

Hi, I'm Monisha. I am a tech blogger and a hobbyist. I am eager to learn and explore tech related stuff! also, I wanted to deliver you the same as much as the simpler way with more informative content. I generally appreciate learning by doing, rather than only learning. Thank you for reading my blog! Happy learning!

RELATED POSTS

What is Edge Intelligence: Architecture and Use Cases

What is Edge Intelligence: Architecture and Use Cases

Introduction With the latest advancements in AI technologies, we have noticed a significant increase in the deployment of AI-based applications and services in recent years. More recently, with the booming IoT industry in particular, billions of mobiles and IoT...

Apache Kafka vs Apache Spark : All you need to know

Apache Kafka vs Apache Spark : All you need to know

Introduction Due to the increase in the volume of data, the demand for Stream processing is on the rise. Just processing the data wouldn't be enough, it should be done quickly too so that organizations can react to changing market conditions on a real-time basis. This...

Creating a Multiplication Skill in Alexa using Python

Creating a Multiplication Skill in Alexa using Python

Introduction In this tutorial, we will be focusing on how to create a custom multiplication skill in Alexa using Python. If you're completely new to Alexa skills, you can get a brief idea about it by clicking here. Subsequently, we have posted regarding account...

Creating a Hello World Skill in Alexa using Python

Creating a Hello World Skill in Alexa using Python

Introduction In this tutorial, we will be focusing on how to create a Hello World Skill in Alexa Developer Console. This is the most basic skill, and it would give us an idea about Skill-building using Alexa's developer console. If you're completely new to Alexa, you...

All you need to know about Amazon Alexa Skills

All you need to know about Amazon Alexa Skills

Introduction In this tutorial, we will be taking a quick look at Amazon Alexa Skills. So, let us get started with the most common question - What Is Amazon Alexa? Alexa is nothing but a cloud-based voice service provided by the tech giant Amazon. In today's world,...

Wi-Fi HaLow: IEEE 802.11ah Wireless Networking Protocol

Wi-Fi HaLow (pronounced "HEY-Low") is an IEEE 802.11ah wireless networking protocol. It was released in 2017 as an update to the IEEE 802.11-2007 wireless networking standard. It uses 900 MHz, license-exempt bands, to provide extended range Wi-Fi networks, as opposed...

What is IoT Cisco Virtualized Packet Core (VPC)?

What is IoT Cisco Virtualized Packet Core (VPC)?

In this article, we will discuss about what is Cisco Virtualized Packet Core (VPC), How it supports IOT. Finally, we discus about its use cases. What is Virtualized Packet Core (VPC)? Virtualized Packet Core (VPC) is a technology providing all services for 4G, 3G, 2G,...

10 Best FTP clients for Windows and MAC users

10 Best FTP clients for Windows and MAC users

FTP is the abbreviation for File Transfer Protocol. Its a commonly used protocol to exchange files over any network. FTP clients are specifically designed software to transfer files between PC and servers over the internet. When a file is being transferred from one...

What is DNS and How does it work?

What is DNS and How does it work?

The Internet is just a network of 'n' computers that can communicate over various communication channels. Now, anything you do on the Internet is only an exchange of information(through files, scripts, etc.) So for the exchange to happen, you need to locate the other...

What is an Application Programming Interface (API)?

What is an Application Programming Interface (API)?

Introduction- What is an API? An application programming interface (API) is a computing interface that defines interactions between multiple software in an IoT environment. It defines the kinds of calls or requests that can be made and how to make them. An API is a...

VIDEOS – FOLLOW US ON YOUTUBE

EXPLORE OUR IOT PROJECTS

IoT Smart Gardening System – ESP8266, MQTT, Adafruit IO

Gardening is always a very calming pastime. However, our gardens' plants may not always receive the care they require due to our active lifestyles. What if we could remotely keep an eye on their health and provide them with the attention they require? In this article,...

How to Simulate IoT projects using Cisco Packet Tracer

In this tutorial, let's learn how to simulate the IoT project using the Cisco packet tracer. As an example, we shall build a simple Home Automation project to control and monitor devices. Introduction Firstly, let's quickly look at the overview of the software. Packet...

All you need to know about integrating NodeMCU with Ubidots over MQTT

In this tutorial, let's discuss Integrating NodeMCU and Ubidots IoT platform. As an illustration, we shall interface the DHT11 sensor to monitor temperature and Humidity. Additionally, an led bulb is controlled using the dashboard. Besides, the implementation will be...

All you need to know about integrating NodeMCU with Ubidots over Https

In this tutorial, let's discuss Integrating NodeMCU and Ubidots IoT platform. As an illustration, we shall interface the DHT11 sensor to monitor temperature and Humidity. Additionally, an led bulb is controlled using the dashboard. Besides, the implementation will be...

How to design a Wireless Blind Stick using nRF24L01 Module?

Introduction Let's learn to design a low-cost wireless blind stick using the nRF24L01 transceiver module. So the complete project is divided into the transmitter part and receiver part. Thus, the Transmitter part consists of an Arduino Nano microcontroller, ultrasonic...

Sending Temperature data to ThingSpeak Cloud and Visualize

In this article, we are going to learn “How to send temperature data to ThingSpeak Cloud?”. We can then visualize the temperature data uploaded to ThingSpeak Cloud anywhere in the world. But "What is ThingSpeak?” ThingSpeak is an open-source IoT platform that allows...

Amaze your friend with latest tricks of Raspberry Pi and Firebase

Introduction to our Raspberry Pi and Firebase trick Let me introduce you to the latest trick of Raspberry Pi and Firebase we'll be using to fool them. It begins with a small circuit to connect a temperature sensor and an Infrared sensor with Raspberry Pi. The circuit...

How to implement Machine Learning on IoT based Data?

Introduction The industrial scope for the convergence of the Internet of Things(IoT) and Machine learning(ML) is wide and informative. IoT renders an enormous amount of data from various sensors. On the other hand, ML opens up insight hidden in the acquired data....

Smart Display Board based on IoT and Google Firebase

Introduction In this tutorial, we are going to build a Smart Display Board based on IoT and Google Firebase by using NodeMCU8266 (or you can even use NodeMCU32) and LCD. Generally, in shops, hotels, offices, railway stations, notice/ display boards are used. They are...

Smart Gardening System – GO GREEN Project

Automation of farm activities can transform agricultural domain from being manual into a dynamic field to yield higher production with less human intervention. The project Green is developed to manage farms using modern information and communication technologies....