Power ON When Detected

Contents

1

Introduction

This program turns ON the power of home appliances when AI detection is triggered, and automatically turns it OFF after a specified time.

GitHub Available on GitHub

The AI detection logic itself is the same as the standard built-in detection program, but this version uses a SwitchBot Mini Plug to control power ON/OFF.

When controlling appliance power with a Raspberry Pi, GPIO-based control is commonly used. However, operating 100V AC appliances requires relay circuits. Considering the risks of electric shock and fire, building your own relay circuit is not recommended unless you have sufficient expertise.

In this program, the SwitchBot Mini Plug is used as a simple and safe device to control appliance power directly from software.

The program connects to the SwitchBot Mini Plug via Bluetooth and turns the appliance power ON when an object is detected.

Note that when using this program, the official SwitchBot app is not required at all. Just take the device out of the box and plug it into a power outlet—setup is complete!

2

Bluetooth-Enabled Docker Image

AIBOX OS comes with Docker images that can run YOLO11 with NCNN by default.

docker images
REPOSITORY TAG aicap/arm64/ultralytics 1.0.250923 aicap/arm64/ultralytics 1.0.250923-audio-bt

These images are based on the official YOLO11 images published by Ultralytics. They include all required modules for NCNN conversion and execution, as well as the environment needed to run the aicap command. Therefore, basic YOLO11-based detection programs running on AIBOX OS can be executed inside containers launched from these images.

The image tagged only with the version number (1.0.250923) is the base image with no additional features.

The image with the -audio-bt suffix (1.0.250923-audio-bt) includes additional modules for audio playback and Bluetooth device access on top of the base image.

Since this program requires Bluetooth control of the SwitchBot Mini Plug in addition to YOLO-based object detection, we will use the 1.0.250923-audio-bt image.

GitHub View the Dockerfile
3

How to Replace the Program

The basic AI detection logic is the same as the built-in detection program.
However, the docker-compose.yml file includes additional settings that allow the Docker image to access the host’s Bluetooth functionality.
The aicap command execution and SwitchBot access are also defined in separate files.
The files that differ from or extend the standard detection program are listed below.

File NameDescription
extmod.pyPython program for object detection
aicap.pyDefines functions for executing the aicap command
switchbot.pyDefines a class that handles Bluetooth device access
docker-compose.ymlDocker container configuration file

A script is provided to update all of these files at once.

Log in to AIBOX and run the following command to download update.zip from GitHub. After extracting it, run update.sh to update all required files.

$ wget https://github.com/daddyYukio/AICAPTURE/raw/refs/heads/main/programs/power_on_appliance/update.zip

After updating, plug in the SwitchBot Mini Plug and reboot the system.

By default, the detected object is set to person.
When a person is detected, a clicking sound is played and the SwitchBot Mini Plug turns ON. If left untouched, the power will automatically turn OFF after 10 seconds.

If another detection occurs before the power turns OFF, the timer is extended so that the power will turn OFF 10 seconds after the most recent detection.

4

Real-Time Detection Preview

To check detection results in real time, enable the detection preview feature.

This allows you to view detection results live in a web browser.

5

Detection Program Explanation

A detailed explanation of the detection program is available as an article on Zenn. Please refer to it for more information.

Zenn 【AI CAPTURE】SwitchBotで家電をON/OFF
6

Changing Detected Objects and Power-On Duration

The method for changing the detected object and adjusting detection accuracy is the same as in the standard built-in AI detection program.

The duration for which the power remains ON is defined by the following external variable in the extmod.py file.


# SwitchBot power ON duration (seconds)
POWER_ON_TIME_SEC = 10