This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Fan-Light-as-a-Service (flaas) — a minimal ASP.NET Core Web API that controls a dimmable LED connected to a motherboard fan header via LibreHardwareMonitor. Designed to run as a Windows Service and integrate with Home Assistant via MQTT Discovery.
dotnet build
dotnet run # runs on http://localhost:5112
dotnet publish -c Release -o C:\flaas # deploy to service directoryRequires administrator privileges — LibreHardwareMonitor needs elevated access to control fan hardware.
Note: appsettings.json is excluded from publish output to avoid overwriting production config.
Target: .NET 10.0, win-x64 only.
# From the publish directory, run as admin:
.\install.ps1Defaults to LocalSystem (needs admin for LibreHardwareMonitor). Override with -Account if needed. Manage with sc start flaas / sc stop flaas.
Three source files, no layers:
- Program.cs — Minimal API setup with six endpoints (including
/health). Configures Windows Service hosting, AOT-compatible JSON serialization (AppJsonSerializerContext), and optional API key middleware. Listens on configurable URL (defaulthttp://*:5112). - FanLightController.cs — Stateful singleton that wraps a LibreHardwareMonitor
ISensor. Tracks_isOnand_brightnessin memory. FiresStateChangedevent on every mutation.CreateFanLightControllerscans motherboard sub-hardware for aSensorType.Controlsensor matching the configured name. - MqttBridge.cs —
BackgroundServicethat connects to an MQTT broker (with optional TLS) and publishes HA MQTT Discovery config (default schema with separate state/brightness topics). Subscribes to command topics for on/off and brightness. Listens tohomeassistant/statusbirth message to re-announce on HA restart. Publishes availability via LWT. ExposesMqttEnabled/MqttConnectedfor the/healthendpoint.
Key types: State (record: IsOn, Brightness), Health (record: MqttEnabled, MqttConnected), UpdateVisitor (LibreHardwareMonitor traversal helper).
| Method | Path | Body | Description |
|---|---|---|---|
| GET | /health |
— | Health check (200 OK) |
| GET | / |
— | Current state |
| POST | / |
{"isOn": bool, "brightness": N} |
Set full state |
| POST | /on |
— | Turn on |
| POST | /off |
— | Turn off |
| POST | /brightness |
{"brightness": N} |
Set brightness (0–100) |
See flaas.http for example requests.
appsettings.json contains:
SensorName— the LibreHardwareMonitor sensor name (e.g.,"AIO Pump"). Use--list-sensorsor Fan Control to discover the correct name.ListenUrl— bind address (defaulthttp://*:5112). Set tohttp://localhost:5112to restrict to loopback.ApiKey— when set, POST endpoints requireX-Api-Keyheader. GET endpoints remain open.Mqttsection — broker connection and HA discovery settings. LeaveHostempty to disable MQTT. SetTlstotruefor encrypted connections (port defaults to 8883).
The service runs from C:\flaas. The source repo is at D:\flaas. Always use pwsh for shell commands.