No description
Find a file
2026-05-16 08:59:23 +00:00
.env.example Add sci-fi blog design and RSS feed 2026-05-16 08:59:23 +00:00
.gitignore Initial Home Assistant observer 2026-05-16 08:02:01 +00:00
ha_observer.py Add sci-fi blog design and RSS feed 2026-05-16 08:59:23 +00:00
install_cron.sh Initial Home Assistant observer 2026-05-16 08:02:01 +00:00
llm_instructions.md Add sci-fi blog design and RSS feed 2026-05-16 08:59:23 +00:00
README.md Add sci-fi blog design and RSS feed 2026-05-16 08:59:23 +00:00
requirements.txt Initial Home Assistant observer 2026-05-16 08:02:01 +00:00
run_ha_observer.sh Initial Home Assistant observer 2026-05-16 08:02:01 +00:00

Home Assistant Observer

Cron-friendly Home Assistant observer:

  • every 30 minutes: collect compact Home Assistant snapshots into ./data
  • every day at 05:00: send the last day of snapshots to AI
  • publish a funny local blog with daily article archive links
  • save Markdown AI reports in ./reports

Setup

cd /home/hbrain/ha
python3 -m venv .venv
. .venv/bin/activate
pip install -r requirements.txt
cp .env.example .env
chmod 600 .env
chmod +x run_ha_observer.sh ha_observer.py install_cron.sh

Edit .env and set:

HA_URL="http://homeassistant.local:8123"
HA_TOKEN="your_long_lived_home_assistant_token"

Create the token in Home Assistant:

Profile → Security → Long-lived access tokens

AI mode for the 05:00 report

Use your logged-in pi subscription:

pi
/login

Then set:

LLM_MODE="pi"
PI_BIN="/usr/local/bin/pi"
PI_MODEL=""

PI_MODEL is optional; leave it empty to use pi's current/default model.

Local Ollama is recommended for privacy:

LLM_MODE="ollama"
OLLAMA_MODEL="llama3.1"

OpenAI cloud API:

LLM_MODE="openai"
OPENAI_API_KEY="..."
OPENAI_MODEL="gpt-4o-mini"

No AI, but still publish a placeholder page:

LLM_MODE="none"

Extra LLM instructions

Edit this file to change how the 05:00 AI analysis behaves:

/home/hbrain/ha/llm_instructions.md

For example, add specific questions, preferred tone, things to ignore, or extra privacy/security concerns. The file is automatically appended to the AI prompt during analyze.

You can change the path in .env:

PROMPT_FILE="./llm_instructions.md"

Test manually

Collect one snapshot:

./run_ha_observer.sh collect

Run the 05:00-style analysis/publishing step:

./run_ha_observer.sh analyze

Open the blog served by nginx:

http://localhost/

This instance publishes to the web root with:

WEB_DIR="/var/www/html"
SITE_BASE_PATH="/"
SITE_URL="http://piagent"

For a subdirectory install, use for example:

WEB_DIR="/var/www/html/haobserver"
SITE_BASE_PATH="/haobserver"
SITE_URL="http://piagent"

Daily articles are written under articles/YYYY-MM-DD.html inside WEB_DIR, and index.html links to the archive. An RSS feed is published at rss.xml, and a sci-fi favicon is published at favicon.svg. New articles include context from previous reports from the last ARTICLE_CONTEXT_DAYS days.

Install cron jobs

This installs exactly these jobs:

  • */30 * * * * collect snapshots every 30 minutes
  • 0 5 * * * analyze with AI and publish the funny local webpage
./install_cron.sh

Manual crontab equivalent:

*/30 * * * * /home/hbrain/haobserver/run_ha_observer.sh collect >> /home/hbrain/haobserver/cron.log 2>&1
0 5 * * * /home/hbrain/haobserver/run_ha_observer.sh analyze >> /home/hbrain/haobserver/cron.log 2>&1

Output locations

/home/hbrain/haobserver/data/       30-minute JSON snapshots
/home/hbrain/haobserver/reports/    daily Markdown AI reports
/var/www/html/                     local funny blog, index.html, rss.xml, favicon.svg, and articles/*.html
/home/hbrain/haobserver/cron.log    cron logs

Privacy notes

Home Assistant data can reveal sleep schedule, occupancy, work patterns, visitors, location habits, and security weaknesses. Prefer LLM_MODE=ollama to keep analysis local. Use EXCLUDED_ENTITIES in .env to omit sensitive/noisy entities.