Script Structure
Homescript scripts are organized in a clear directory structure. Each script is a Lua file that defines functions and logic to control devices or respond to events. The main directories include:events/device: Scripts that respond to device events.events/time: Scripts that run at specific times.lib: Helpers, your custom libraries and modules.
Writing Your First Script
Let’s create a simple script that turns on a light when motion is detected. Here we assume you have a motion sensor and a smart bulb.- Create a new file in the
events/device/motion_sensor/detectdirectory, e.g.,handler.lua.
- Save the file. Homescript will automatically load and execute this script when the motion sensor detects motion.
Using Built-in Functions
Homescript provides several built-in functions to interact with devices and manage state:Device Management
Persistent Storage
Logging
Event Object
When a script is triggered by an event, it receives anevent object containing relevant information: