home-ha-mock

Home Assistant Helper/Mocker (HAMock)

A Python utility for interacting with Home Assistant, primarily focused on state monitoring, logging, event replay capabilities, and security risk assessment through AI integration.

Features

Installation

Install dependencies:

pip install -r requirements.txt

Usage

Most updated documentation is probably in the help description of the utility:

./hamock.py -h

Commands

Listen for state changes:

./hamock.py listen [--output OUTPUT_FILE] [--max-retries RETRIES] [--retry-delay DELAY] [--append]

The --append flag allows adding new events to an existing output file instead of overwriting it.

Get current states:

./hamock.py states [--output OUTPUT_FILE] [--timeout TIMEOUT]

Replay events:

./hamock.py replay --input INPUT_FILE [--replay-speed SPEED] 

Replay events with AI analysis:

./hamock.py replay --input INPUT_FILE --infer true [--replay-speed SPEED] \
                   [--openai-url URL] [--openai-model MODEL] \
                   [--model-seed SEED] [--stats] \
                   [--system-prompt PROMPT] 

The --stats flag enables displaying detailed inference statistics for each event processed. In inference mode (--infer), the default system prompt attempts to emulate a rudimentary home security system, and is defined as:

You are a home security system that monitors changes in the state of various sensors and entities. 
Your task is to assess each change for potential security risks and respond ONLY using a JSON structure 
in the format: { "security_risk": "LOW", "MEDIUM", or "HIGH" }. When assessing security risk, 
follow these guidelines:
- If the change involves an entity related to regular system operations or minor fluctuations 
(e.g., load changes, memory usage), mark it as "LOW".
- If the change involves an unexpected or unusual sensor state that might require attention but is not 
directly indicative of a critical problem, mark it as "MEDIUM".
- If the change indicates a potentially dangerous or highly unusual event that could indicate a security 
threat (e.g., unauthorized access attempts, sudden large fluctuations, loss of sensor communication), 
mark it as "HIGH".
Your goal is to provide a reasonable evaluation based on these guidelines. Always keep your output strictly 
in the format: { "security_risk": "LOW", "MEDIUM", or "HIGH" }.

If the model is not available but the inference endpoint is, the application will wait 30s in a loop in an attempt to allow the orchestrator to download/load the model.

Environment variables and Global options

By default, the following environment variables are used:

These can be overridden by passing corresponding command-line arguments.

Development Status

Completed

In Progress

License

This project’s source code is confidential with restricted distribution.