Skip to main content
Skip to main content

Home automation programming

Integrating Digital Technologies
Years 5-6

Investigate home automation systems, including those powered by artificial intelligence (AI) with speech recognition capability.

These suggested activities provide a level of differentiation to cater for students’ range of programming skills. Developed in collaboration with Digital Technologies Institute.

This set of lesson ideas is related to Home automation with AI, which explores how AI works within the context of home automation and raises topics including risks and also how these systems might assist people living with disability.



Decorative image

Image credit: Mike MacKenzie/ Flickr, CC BY 2.0


Preliminary notes

Text to speech blocks enable a user to include speech into their Scratch projects. It recognises text input into the program and speaks the words.

To program using Text to Speech blocks, access the additional blocks available in Scratch 3.0 project editor.

Note: It is advised that students use the desktop version of Scratch. This version of Scratch does not require a log in or any functionality to comment on or share projects.

Before using any new technology tools undertake a risk assessment using the eSafety Commission’s New Technology: Risk assessment.


Image: Screen capture of Machine Learning for Kids Scratch 3.0 program editor showing Speech to Text blocks

Test Text to Speech set-up

Create this simple script to test the Text to Speech to Text functionality. Add the Text to Speech blocks by selecting the blue Add extension at the very bottom of the code blocks (see it in the screen capture above):


Suggested steps

Unplugged activity

Discuss home automation. Ask, ‘How might voice commands be used in home automation?’ Consider aspects of home automation such as:

  • security and access
  • climate control
  • lighting
  • entertainment.

Discuss the role of AI in performing the automation. This may prompt students to mention the use of personal assistants.

Ask students to consider how home automation can or might assist those living with disability.

With new technologies there are often risks to consider. Ask what could go wrong. Discuss risks such as privacy breaches from a system being hacked or times when the system might be down due to a power outage (including one caused by a natural disaster such as fire or flood).


Plugged activity

Use these suggested activities to explore implementing a digital solution that demonstrates how to control appliances, and to further investigate home automation.


Use binary numbers 0 and 1 to switch a light on and off (skill level: easy)


Use Scratch 3.0 or a similar visual programming language (without any form of AI) to create a program that switches appliances on and off using an input: 0 or 1. This task demonstrates the use of binary digits to change state; for example, ‘On to off’ or ‘Off to on’. As this program does not use any form of AI, use it to demonstrate how conventional coding is used to hard-code a particular action.

Depending on students’ familiarity with and understanding of binary numbers, review the use of 0 and 1 and explain that binary means ‘two states’. The two states can be represented in different ways, such as by the numbers 1 and 0, or by text (‘true’ and ‘false’, or ‘on’ and ‘off’). The main point here is that a binary device can be in just one of two possible states. A binary bit is a single on/off value.

Suggested steps

  1. Students consider a home appliance they want to include in their program, for example a light or fan, then create the appliance as a sprite. Free versions of icons can be found online, saved to a folder and uploaded, or students can draw their own.
  2. Initiate each sprite using the block ‘when (green flag) clicked’.
  3. Use an ‘ask’ block to enable the user to input a 0 or 1.
  4. Use an if/then block to instruct what happens if ‘0’ is input.
  5. Use a second if/then block to instruct what happens if ‘1’ is input.

In the two-part example below, the sprite (light) changes costume (has a yellow fill) to show an illuminated light.

Image: Screen capture of Scratch 3.0 program giving user instructions for using either 0 or 1 as input

Image: Screen capture of Scratch 3.0 program showing if/then blocks based on user input answer (1), to turn light on

For sample code, see Binary switch light on/off.


Ideas for remix:

Students:

  1. create their own sprites for other appliances
  2. add a block of program code that turns each appliance on and off
  3. add a block of program code that controls multiple appliances
  4. change backgrounds.

Use text to speech recognition in your program to switch appliances on and off (skill level: medium)

Text to speech blocks enable a user to include speech into their Scratch projects. It recognises text input into the program and speaks the words.

To program using Text to Speech blocks, access the additional blocks available in Scratch 3.0 project editor. Present the challenge of creating a program that recognises a text input and speaks the words entered to perform an action such as turning home appliances on or off.

Discuss the types of voice commands that might typically be used, for example:

  • Turn on/turn off
  • Lights on/Lights off
  • Turn fan on/Turn fan off.

Emphasise short commands that are easy to understand.


Suggested steps

  1. Students consider a home appliance they want to include in their program, for example a light or a fan, and create it as a sprite. Free versions of icons can be found online, saved to a folder and uploaded, or students can draw their own.
  2. One way to program the Virtual Assistant to control the appliances is to have a sprite say the instructions and the virtual assistant follows the commands.

    Select a character (sprite) to ask what you want to turn on or off. The use of an ask block enables text input by the user. The answer can be shown on screen and using a speak block, said by the sprite.

    Screen capture of Scratch 3 program, showing sprite (Abby) asking what she should tell the virtual assistant to add.

  3. Code the light (sprite) to turn on and off. Use an if/then block and the operator block (apple contains a) which recognises a key word in a string of text. Add the 'answer' block in green block and type in ‘on’. So if the answer (text entered) contains ‘on’ then the sprite will switch costume (to the animated costume). Students can duplicate blocks and change contains off and change costume to off costume.

    Image: Screen capture use of Scratch 3 program, showing the use of if then blocks, operator blocks and a forever block

  4. Image: Screen capture use of Scratch 3 program, showing joining two operator blocks

    Provide this sample code for students to remix

Ideas for remix:

Students:

  1. create their own sprites for other appliances
  2. add a block of program code that turns the appliance on and off based on the light example
  3. change backgrounds.


Discussion

Share what you have learned about AI and how ‘smart’ a computer can be. Think about the program you created:

  • What were some of the challenges?
  • Where the program used AI to recognise the text and speak the words, what things affected how well it worked?
  • How might you improve the program if you did the task again?

Why is this relevant

Algorithms and programming are essential to developing machines powered by artificial intelligence (AI). AI is the ability of machines to mimic human capabilities in a way that we would consider 'smart'.

In conventional programming the computer is provided with a set of instructions for a defined set of scenarios. In the binary program, the students hard-coded the program with specific inputs of 0 or 1 to turn the appliance off/on. To include a trained AI models to recognise text and speak the commands as ‘turn on’ or ‘turn off’ for each appliance.

Machine learning (ML) is an application of AI. With machine learning, we give the machine lots of examples of data, demonstrating what we would like it to do so that it can figure out how to achieve a goal on its own. The machine learns and adapts its strategy to achieve this goal.

This lesson focuses on:

  • binary numbers (1, 0)
  • speech recognition
  • training an AI with suitable data.