Skip to content

Stewart

Write your Home Assistant automations as plain PHP classes. Test them like any other code, and run them in Docker next to Home Assistant.

Stewart connects to your Home Assistant and runs automations you write in PHP. Each automation is a small PHP class, which Stewart calls an app: it watches entities, reacts to events and schedules, and calls Home Assistant services. You keep the automations in your own Git repository, check them with PHPStan, and test them with PHPUnit, without a running Home Assistant.

This is a complete automation. It turns the porch light on at sunset and off at 23:00:

apps/PorchLight.php
<?php
declare(strict_types=1);
namespace App;
use Psr\Log\LoggerInterface;
use Stewart\Contracts\App;
use Stewart\Contracts\Automation;
use Stewart\Contracts\HaContext;
use Stewart\Contracts\Schedule\Scheduler;
use Stewart\Contracts\Service\ServiceTarget;
use Stewart\Contracts\Sun\SunEvent;
#[Automation(id: 'porch-light')]
final readonly class PorchLight implements App
{
public function __construct(
private HaContext $ha,
private Scheduler $scheduler,
private LoggerInterface $logger,
private string $light = 'light.porch',
private string $offAt = '23:00',
) {}
public function initialize(): void
{
$this->scheduler->runAtSunEvent(SunEvent::Sunset, function (): void {
$this->logger->info('Sunset, turning the porch light on');
$this->ha->callService('light', 'turn_on', target: ServiceTarget::forEntities($this->light));
});
$this->scheduler->runDailyAt($this->offAt, function (): void {
$this->logger->info('Bedtime, turning the porch light off');
$this->ha->callService('light', 'turn_off', target: ServiceTarget::forEntities($this->light));
});
}
public function dispose(): void {}
}
Home Assistant
│ one connection
▼
Stewart ── keeps a copy of every entity's state
│
├── worker ── your apps
└── worker ── your apps

Stewart keeps one connection to Home Assistant. Your apps run in separate worker processes, so an app that crashes or hangs cannot take the others down. How it works explains what that means for you.

Install Stewart Create a project, connect it to Home Assistant, and run it. About 15 minutes.
Your first app Build, test and run the porch light above, step by step.
Project tour What each file in your project is for.
Recipes Complete automations to copy: motion light, heating by presence, door reminders and more.
Guides State changes, events, schedules, service calls, storage and more.
Deploying Running Stewart on a server, from Git, from an image, or on Kubernetes.
Troubleshooting Something does not work? Find it by its symptom.

Curious how Stewart is built? The developer documentation covers its internals.