A Node.js/TypeScript service controlling a home battery and two EV wallboxes through MQTT. It allocates charging power, schedules battery SOC targets in Europe/Lisbon time, fetches solar forecasts and electricity prices, and exposes a dashboard and Prometheus metrics.
The stack uses npm for dependency management, TypeScript's compiler for strict checking and ESM builds, Node's test runner, and Biome for linting and formatting. MQTT uses mqtt; HTTP uses Node's HTTP server with @hono/node-server; scheduling uses node-cron; monitoring uses prom-client. See development for the build workflow and architecture for service interactions.
- Automation rules: charging modes, priority, battery targets, and grid protection.
- Architecture: components, scheduling, and application lifecycle.
- Development: commands, tests, and Temporal conventions.
- Operations: configuration, BMW CarData setup, monitoring, and device assumptions.
Install Node.js 26.13 or newer in the 26.x LTS line (see .nvmrc), clone this repository, and run npm ci. Run commands from the repository root so the application can find .env and static/.
-
Create the local configuration if you do not already have one:
cp .env.example .env chmod 600 .env
-
Edit
.envfor your installation. Set the MQTT connection, API credentials, persistence settings, and both required Victron identifiers:VICTRON_PORTAL_ID: the portal ID used in MQTT topics.VICTRON_INSTALLATION_ID: the numeric VRM installation ID used for forecasts.
Neither identifier has a default; missing or invalid values prevent startup. Keep actual identifiers and credentials in the ignored
.envfile. See configuration for the complete reference. Leave the optional Logflare credentials unset if you only want console logs.The example enables
POWER_CONTROL_ENABLED. Setting it tofalselogs automatic wallbox and battery-power commands instead of publishing them. Scheduled minimum-SOC updates still publish, so this is not a complete simulation mode. -
Start development mode with automatic reload:
npm run dev
For operation without file watching:
npm start
To show BMW i3 SOC, complete the optional BMW CarData setup on the host running the service before starting it.
npm run check # Type-check and run tests
npm run lint # Lint source and scripts with Biome
npm run fmt # Format source, scripts, and root configuration
npm run fmt:check # Verify formatting without rewriting
npm test # Compile and run testsTests cover power allocation, command reservations, telemetry freshness, forecast lookup, Lisbon scheduling and DST, configuration, and API parsing. The test task supplies synthetic Victron identifiers; a private .env is not required.
Power-control tests live in src/power-controller/, including dynamic-power-calculator.test.ts. See development for direct test invocation and date/time conventions.
The supplied service and deployment scripts target carlos@bee.local, with the repository at /home/carlos/homeautomation. The systemd unit runs as user/group carlos and expects Node.js at /usr/bin/node. Adjust those paths and the deployment scripts for another host.
Before installing the service, make sure the repository, Node.js, and the server's own .env are in place. The configuration file should be owned by carlos with mode 0600; configure both Victron identifiers before starting the service.
See the deployment and rollback instructions for runtime requirements, service setup, and recovery. Deployment scripts require the supplied Node.js systemd unit to be installed.
On the server:
cd /home/carlos/homeautomation
npm ci
npm run build
sudo cp homeautomation.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable --now homeautomationManage the service with:
sudo systemctl status homeautomation
sudo journalctl -u homeautomation -f
sudo systemctl stop homeautomation
sudo systemctl start homeautomation
sudo systemctl restart homeautomationTo disable automatic startup and stop the running service:
sudo systemctl disable --now homeautomationLogs go to the console and, under systemd, the journal. Set LOGLAYER_SOURCE_ID and LOGLAYER_API_KEY to also send logs to your configured Logflare source; HOST_ID identifies the host in those logs.
Run deployment commands from the local repository root. They require Node.js 26 and npm on both machines, SSH access to carlos@bee.local, and noninteractive sudo permission for the service commands. Git deployment requires Git and a checkout on the server; local deployment requires rsync on both machines.
First validate the changes:
npm run analyze
npm run buildFor Git deployment, commit and push to main, then run:
bash deploy-git.shThis validates locally, checks the remote Node runtime and systemd unit, stops the service, pulls origin/main with fast-forward only, installs locked dependencies, builds, writes a build timestamp, and starts the service.
To copy the local working tree, including uncommitted changes:
bash deploy-local.shThis validates locally, checks the remote runtime and unit, stops the service, copies source with rsync, installs locked dependencies, builds, and starts the service. It excludes Git data, private environment/token files, logs, dependencies, generated output, temporary plans, and deployment scripts. It does not refresh the build timestamp.
Both scripts run checks, linting, formatting verification, and a production build locally before deployment. A remote install/build failure leaves the service stopped for operator recovery. Neither transfers your local .env or BMW CarData token file. To enable BMW SOC on the server, follow BMW CarData setup on bee.local after the code is deployed. Update /home/carlos/homeautomation/.env separately before deploying changes that require new configuration. After deployment, check the service status and journal; a script's completion message alone does not establish application health.
With the default HTTP_PORT=1881:
| Endpoint | Local | Server |
|---|---|---|
| Dashboard | http://localhost:1881/ |
http://bee.local:1881/ |
| Health | http://localhost:1881/health |
http://bee.local:1881/health |
| Prometheus metrics | http://localhost:1881/metrics |
http://bee.local:1881/metrics |
The dashboard lists scheduled tasks, lets you trigger them, and lets you change each wallbox's charging mode. Task buttons report the result of manual triggers; they do not provide continuous execution monitoring. Triggering the SOC schedule runs its current-time checks rather than forcing an evening or morning adjustment.
The health endpoint returns OK when HTTP is responding. It does not check MQTT connectivity or external services. See operations for metrics and telemetry behavior.
On SIGINT or SIGTERM, the service stops cron and interval scheduling, disconnects MQTT, shuts down HTTP, drains pending persistence writes, and exits. Pending SOC retries are held in memory and are discarded on restart.