Shelly Forge
Shelly Forge is a TypeScript framework and CLI tool for developing, testing, and deploying scripts to Shelly smart home devices. It provides a modern development experience with type safety, live reloading, and real-time debugging capabilities.
Overview
Shelly Forge simplifies the development of Shelly Scripts by providing:
- Full TypeScript support with type definitions for Shelly's API
- CLI tools for project scaffolding and deployment
- Live development server with automatic compilation
- Real-time device logs and debugging
- Project templates and examples
Quick Start
- Create a new project:
npx shelly-forge init my-project
cd my-project
npm install
- Create your first script:
npm run create my-script 192.168.1.100
- Start development:
SCRIPT_NAME=my-script npm run dev
Project Structure
my-project/
├── build-cache/ # Build cache directory
├── dist/ # Compiled output
├── node_modules/ # Dependencies
├── src/ # Source code directory
├── .editorconfig # Editor configuration
├── .gitignore # Git ignore rules
├── package-lock.json # Lock file for dependencies
├── package.json # Project configuration
└── tsconfig.json # TypeScript configuration
Writing Scripts
Basic Script
The script is defined as a function that returns a ShellyScript instance. The builder is used to configure the script. For example, to subscribe to temperature updates, you can use the following code:
import { ShellyBuilder } from 'shelly-forge';
export const temperatureMonitor = new ShellyBuilder().hostname('192.168.1.100').script(() => {
Shelly.addEventHandler(async (event) => {
if (event.component === 'temperature') {
this.log(`Temperature: ${event.data.tC}°C`);
}
});
});
Then the script needs to be exported from the main entry file:
export * from './scripts/temperatureMonitor';
CLI Commands
Project Management
shelly-forge init [name]
- Create new projectshelly-forge deploy
- Deploy scripts to deviceshelly-forge debug <on|off>
- Toggle debug modeshelly-forge create <name> <hostname>
- Create a new script
Development
npm run dev
- Start development servernpm run build
- Build for productionnpm run deploy
- Deploy to device
API Reference
ShellyBuilder Class
class ShellyBuilder {
hostname(ip: string): ShellyBuilder;
enableOnBoot(enable: boolean): ShellyBuilder;
script(code: () => void): ShellyScript;
}
ShellyScript Class
class ShellyScript {
constructor(ip: string, code: () => void, enableOnBoot: boolean);
setDebug(enable: boolean): Promise<void>;
deploy(name: string): Promise<boolean>;
}
Device APIs
Shelly Forge provides TypeScript definitions for all device APIs. Please refer to the Shelly API documentation for more details.
Shelly.call('Switch.Set', { id: 0, on: true });
TODO
Contributing
Contributions are welcome! Please see our Contributing Guide for details.
License
MIT License - see LICENSE for details.
Support