跳到正文
DEV Community· Laura Norwood·· 2 小時前AI 評分37

Ghost in the House:以本機開源權重模型把智能家居感應器事件寫成鬼故事

👻 Ghost in the House 🎃

AI 導讀

Ghost in the House 以 TypeScript 的六條可解釋規則從一夜智能家居感應器事件中挑選異常時刻,再交由本機運行的開源權重模型寫成短篇鬼故事。預設模型為 llama3.1:8b,透過 Ollama 串流生成,毋須雲端 AI 呼叫;頁面會把故事時刻連到平面圖、圖表及原始感應器記錄。姑且不把感應器未記錄到的活動説成「沒有人移動」,並明確區分感應器記錄、規則假設與模型解讀。

正文

This is a submission for the Hacktoberfest Open-Source AI Challenge Week 4: Ghost in the Machine

What I Built

Ghost in the House takes a night of smart home sensor events, picks the strangest with plain code, and asks an open-weight model running on your own machine to explain them as a short ghost story.

The page is a surveyor's plan of a quiet house. A floor plan and a chart of the whole night sit beside the story. Every time the story names a moment ("01:58"), the plan and chart jump to it and show the house as the sensors recorded it: lamps, open doors, movement, the spare room turning cold. The raw record sits underneath, so you can check the story against the evidence line by line. A guided walkthrough takes first-time visitors through the four events, and a panel beside the plan says what changed, what the sensors recorded beforehand, and what remains unknown, all derived from the data.

The night is fictional sample data shaped like Home Assistant history: 205 sensor readings, with four events nothing explains. A spare room light comes on with no motion recorded in the room. The hallway sensor fires while every tracked phone is home. The spare room drops 6 degrees in ten minutes. The back door opens with no motion recorded before it.

I tried to keep three kinds of claim apart, and the page labels them: what the sensors recorded, what my six rules assume, and what the model interpreted. A phone being at home does not prove anyone is asleep, and no recorded motion does not prove nobody moved, so the page says "no motion recorded" and nothing stronger.

Demo

Live page: https://lanthanum89.github.io/Ghost-in-the-Machine/

It opens with a recorded story that plays straight away, so nothing needs installing. The Live mode asks your own Ollama model for a fresh story and checks that Ollama is running before you press anything.

Code

Ghost in the House

A night of smart home sensor events goes in. A short ghost story comes out, written by an open-weight model running on your own machine.

Built for the Hacktoberfest Open-Source AI Challenge, Week 4: Ghost in the Machine.

The page is a surveyor's plan of the house. The story streams in beside a floor plan and a chart of the whole night, and every time the story names a moment ("01:58") the plan and chart move to it, showing the lamps, doors, movement and temperatures as they were. The four marked events are numbered and linked in time order (the link shows sequence, not a tracked route), and the raw sensor record sits underneath.

The page opens on the quiet house just after lights out. A guided walkthrough takes you through the four marked events one at a time. A panel beside the plan says what…

How I Built It

The rule I started with: the model never sees raw logs and never decides what is spooky.

Plain TypeScript filters the night's events, scores them with six explainable rules (night-time, no motion recorded before it, phones at home, rarity, sudden change, routine chatter) and picks about 20. Each point has a stated reason, and the page lists the rules. The model only narrates that short, pre-selected timeline, written as plain English with no scores or rule names. Choosing those events still shapes the story, and the page says so.

  • Model: a small open-weight instruct model through Ollama, llama3.1:8b by default and one setting to change. Low-ish temperature, capped length, and a system prompt fixing a dry, understated British voice that tells it to say "no motion was recorded" rather than claim nobody was there.
  • Inference: Ollama's streaming /api/chat, called straight from the browser. No cloud AI calls anywhere.
  • The plan and chart: a replay of the sensor history, computed in code. A small parser finds times like 01:58 in the story as it streams and moves the chart to the matching moment. The model decides nothing visual.
  • App: TypeScript, React, Vite, Tailwind and Vitest, as an installable PWA that opens offline. The type is IM Fell Double Pica for titles, Atkinson Hyperlegible for reading and IBM Plex Mono for data, all bundled open-licensed files, so nothing loads from a CDN.
  • Home Assistant: src/data/ha-client.ts is a stub for the real history API. It has never been run against a real Home Assistant, and the README and code both say so.

Why Does Open Innovation Matter?

Sensor data shows when a house is empty and when people are likely asleep. That should not go to someone else's server.

An open-weight model on your own network means the data never leaves the house, the tool works with the internet off, and it keeps working if a hosted service changes or disappears. The model is a setting you can swap. And because the selection step is ordinary code, you can read why each event was chosen, which makes it easier to see where the story comes from and where it does not.

來源:DEV Community · dev.to