A custom Home Assistant integration that automatically analyzes error logs using Google Gemini AI and provides actionable fixes. This integration tracks issues, allows you to mark them as complete, and intelligently reopens them if they occur again.
- π€ AI-Powered Analysis: Uses the Home Assistant Google Generative AI Conversation integration with Gemini to analyze errors
- π Issue Tracking: Automatically tracks unique issues with deduplication
- β Completion Tracking: Mark issues as completed and track resolution
- π Smart Reopening: Automatically reopens completed issues if they recur
- π Statistics: Track error counts, warnings, and issue occurrences
- π Detailed Action Plans: Get step-by-step instructions to fix each error
- πΎ Persistent Storage: Issues are stored and survive Home Assistant restarts
Before installing this integration, you must have:
- Home Assistant (version 2024.1 or newer)
- Google Generative AI Conversation integration configured in Home Assistant
- Go to Settings β Devices & Services β Add Integration
- Search for "Google Generative AI Conversation"
- Configure with your Google API key
- Create a conversation agent
- Open HACS in Home Assistant
- Click on "Integrations"
- Click the three dots in the top right corner
- Select "Custom repositories"
- Add this repository URL:
https://github.com/ncecowboy/Home-Assistant-Log-Analysis - Select category: "Integration"
- Click "Add"
- Click "Install" on the Home Assistant Log Analysis card
- Restart Home Assistant
- Copy the
custom_components/ha_log_analysisfolder to your Home Assistantcustom_componentsdirectory - Restart Home Assistant
- Go to Settings β Devices & Services
- Click Add Integration
- Search for "Home Assistant Log Analysis"
- Fill in the configuration:
- Google Generative AI Conversation Agent: Select your configured Gemini conversation agent
- Scan Interval: How often to scan logs in seconds (default: 300 seconds / 5 minutes)
Note: This integration reads logs from the systemd journal using either the systemd-python library or the journalctl command. If systemd-python is not available, it will automatically fall back to using the journalctl command.
Once configured, the integration will:
- Automatically scan your Home Assistant logs from systemd journal at the configured interval
- Extract errors and warnings
- Use Google Gemini AI to analyze each unique error
- Generate actionable fix plans
- Track all issues with persistence
The integration creates a sensor: sensor.home_assistant_log_analysis
State: Number of open issues
Attributes:
issues: List of all tracked issues with detailserror_count: Number of errors found in last scanwarning_count: Number of warnings found in last scanlast_analysis: Timestamp of last log analysis
Trigger an immediate full log analysis.
service: ha_log_analysis.analyze_logsMark a tracked issue as completed.
service: ha_log_analysis.mark_issue_complete
data:
issue_id: "a1b2c3d4e5f6"Get all tracked issues (returns data in response).
service: ha_log_analysis.get_issuesEach tracked issue contains:
issue_id: Unique identifier for the issueerror_message: The error message from the logcomponent: The Home Assistant component that generated the errorseverity: ERROR, WARNING, or CRITICALaction_plan: AI-generated steps to fix the issuetraceback: Stack trace if availablestatus: "open" or "completed"created_at: When the issue was first seenlast_seen: When the issue was last seenoccurrences: Number of times this issue has occurredreopened_count: Number of times a completed issue was reopened
automation:
- alias: "Daily Error Report"
trigger:
- platform: time
at: "09:00:00"
action:
- service: ha_log_analysis.analyze_logs
- delay: "00:00:30"
- service: notify.mobile_app
data:
title: "Daily Log Analysis"
message: >
Open Issues: {{ states('sensor.home_assistant_log_analysis') }}
Errors: {{ state_attr('sensor.home_assistant_log_analysis', 'error_count') }}
Warnings: {{ state_attr('sensor.home_assistant_log_analysis', 'warning_count') }}automation:
- alias: "Alert on Critical Issues"
trigger:
- platform: state
entity_id: sensor.home_assistant_log_analysis
condition:
- condition: template
value_template: >
{{ state_attr('sensor.home_assistant_log_analysis', 'issues')
| selectattr('severity', 'equalto', 'CRITICAL')
| selectattr('status', 'equalto', 'open')
| list | length > 0 }}
action:
- service: notify.persistent_notification
data:
title: "Critical Error Detected"
message: "Check sensor.home_assistant_log_analysis for details"- Log Scanning: The integration periodically reads your Home Assistant logs from systemd journal
- Error Extraction: Parses logs to extract errors, warnings, and critical messages
- Deduplication: Generates unique IDs for each error based on the message and component
- AI Analysis: Sends errors to Google Gemini AI via the HA conversation integration
- Issue Tracking: Stores issues with their AI-generated action plans
- Smart Updates:
- New errors create new issues
- Recurring errors increment occurrence counter
- Completed issues that recur are automatically reopened
- Ensure you have the Google Generative AI Conversation integration installed and configured
- Check Home Assistant logs for errors
- The integration will work with or without systemd journal access
- Make sure you've set up the Google Generative AI Conversation integration
- Go to Settings β Voice Assistants and verify your Gemini agent is configured
- Verify errors exist in your logs (check with
journalctl -u home-assistant@homeassistant.service -fon the host system) - Check that the Gemini conversation agent is responding
- Look for errors in the Home Assistant logs related to
ha_log_analysis
- The systemd-python library is now optional
- If systemd-python fails to install, the integration will automatically fall back to using the
journalctlcommand - The
journalctlcommand must be available on your system for log reading to work - You can view logs manually using
journalctl -u home-assistant@homeassistant.serviceon the host system
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
For issues, questions, or contributions, please visit the GitHub repository.