~/wellseasoned.dev

Shade Engine

· 8 min read

All of our main windows face west, so automated shades matter here: sun tracking in the afternoon, open for the view when it’s dim, closed at night (partially — wind, cats). I ran this on the Adaptive Cover integration for Home Assistant, and I spent most of a month fighting it.

The core problem is that Adaptive Cover internalizes the policy decision: sun tracking, climate modes, weather checks, presence, manual overrides — one opaque pipeline, configured partly in a settings dialog and partly through loose toggle entities whose state silently changes behavior. When it did something surprising, the only way to answer “why did the blinds just move” was to read the integration’s source and replay recorder history. Some of the failures from a single week:

  • I raised the shades three times in the half hour before sunset and each raise was reverted within minutes. The manual-override window I’d configured was dead config — detection was gated behind a separate, differently named switch that was off.
  • Blinds pinned fully closed at 9 PM on a summer night because the kitchen was 25.4°C and the climate branch checks temperature before it ever looks at whether the sun is still up.
  • A cover that “moved recently” gets its next command silently dropped, never retried. The kitchen shade spent a night stuck at 30% because its open command landed four seconds inside that window.
  • One full-sun day the shades never moved at all. Lux peaked around 70,000, but the daily forecast said “cloudy,” and the forecast vetoes glare tracking entirely.
  • The north window froze at 30% overnight because its update missed the end-of-control cutoff by nine seconds.

I compensated with more automations to tweak the state of Adative Covers. Morning raise pulled out of the integration so the shades still rise if it’s disabled. A pair of automations that turn climate mode off at sunset and back on at sunrise, just to make the summer branch unreachable after dark. A five-automation lux state machine driven by an outdoor illuminance sensor. Wrapper covers so HomeKit’s “closed” means our partial stop points. A dashboard widget just to see the true override state. Plus two bugs patched directly in the installed source, which any HACS update would revert. Four config entries, surrounded by roughly nine automations of band aids.

config-flow formgeometry · thresholdstoggle switchessix per zonehard-coded in sourcefound by reading the codesun positionweather forecastlight sensorindoor temperaturepresenceforecast vetoswitch-gatedONE COORDINATORcalculate · decide · actuate — fusedwinter ⇄ summer ⇄ intermediatepresence branch · transparent-blind casesummer branch skips the sun checkmanual overridestimer in memory · no timestamp✕moved <10 min ago →dropped, no retrycoversmanual moves start heremanual move vanishes inside
The before picture. Configuration arrives from three places, toggle switches silently gate the inputs, a daily forecast of “cloudy” vetoes everything, and commands to a recently-moved cover are dropped without retry. The amber parts are the ones you can’t see from the outside.

The project’s own README has a flow chart of the decision tree. Even at thumbnail size, the shape makes the point:

Adaptive Cover decision flow chart: a sun update passes through about a dozen branching checks before a position is applied

Adaptive Cover's decision tree, redrawn in monochrome from the flow chart in the project's README (MIT licensed). Every diamond is a branch. Some can be flipped from the toggle switches, but nothing shows which path the last update took or why. Click through for the legible version.

While I was creating all the scaffolding to try to nudge and influence the internal decision tree I realized that the scaffolding I created was the policy… it just had no clean way in. So I built Shade Engine, a small HACS integration that does two things and refuses to do a third:

  • Calculate. Pure geometry: window azimuth, field of view, sun position → the highest shade position that keeps direct sun off the first few meters of room, published as a sensor.
  • Decide — not it. Policy lives in ordinary automations. Each zone exposes one mode select (open, glare, night, whatever you define); anything that can write a select can be a policy source, and every decision is a readable automation trace.
  • Actuate. Mode → target → position, with a deadband, rate limiting that defers moves instead of dropping them, and manual moves honored as a visible hold with a timestamp instead of an in-memory timer.
sun positionazimuth · elevationsensorslux · temperature · time1 · CALCULATEpure geometry, statelessglare position sensorsun-in-window sensor2 · DECIDEyour automations, visible traceswrites the zone’s mode selectopen · glare · night3 · ACTUATEmode → target → commanddeadband · deferred, never droppedmanual move → visible holddeclined moves state a reasoncoversmanual moves detected hereposition ≠ commanded → visible hold
Data flows left to right. Calculate and decide are independent; actuate combines them: the mode picks the target, and only the glare mode reads the calculated position. The dashed line is the only feedback path: a cover position that doesn’t match the last command means a human moved it, which starts a visible hold.

The lux state machine I’d built as a workaround came along unchanged — it’s just the policy layer now, writing modes instead of fighting an integration for control. When the engine declines to move a cover, a sensor attribute says why. No tracing the source or the logs to try to figure out why.

vfilby/shade-engine Sun-tracking shade control for Home Assistant with externalized policy