I migrated my NAS setup from an off-the-shelf UGREEN NAS to a custom-built NAS. Check the specs on the about page.
I don’t know if this was already an issue on my previous NAS, but as soon as I started using the new machine and monitoring its power consumption, I noticed that from time to time, the power consumption would spike and remain there for a while. For me, for no obvious reason.
So what did I do? At the end of every day, I would open my HomeAssistant dashboard and check the power consumption of my NAS. If I noticed a spike, I would check the logs of my NAS to see if there was any activity that could explain the spike. Often I just handed over the logs to Gemini and let it analyze them for me, but I still had to do this manually. Because I am lazy and all about automating things that can be automated, I decided to automate this process.
Table of contents
Open Table of contents
Setup
This is not a tutorial or a step-by-step guide, but rather a description of how I set everything up.
Overview
- NAS connected to a smart power plug (Eve Energy)
- Smart power plug sends power consumption data to HomeAssistant via Thread
- HomeAssistant collects power consumption data and has an automation that triggers when the NAS power consumption exceeds a certain threshold for a certain amount of time
- HomeAssistant connects to the NAS to collect journal logs and Docker logs of the running containers
- HomeAssistant sends the logs and a system prompt to Gemini using the Gemini-HomeAssistant integration
- Gemini analyzes the logs and returns a summary of what happened during the power spike, including any relevant information about the running containers and processes
- HomeAssistant receives the summary from Gemini and sends a push notification to my phone with the summary of what happened
The Steps in Detail
Connecting HomeAssistant to the NAS
Assuming you have a working HomeAssistant setup and the power plug is already integrated, the first step is to figure out how to connect HomeAssistant to your NAS to collect the logs. In my case, this happens via SSH.
So on my HomeAssistant instance, I created a SSH key pair and added the public key to a fresh user on my NAS with only the necessary permissions to read the logs I am interested in (groups: _ssh, docker, systemd-journal).
The SSH files have to be placed in a persistent storage location on HomeAssistant, so that they are not lost when the HomeAssistant instance is restarted.
I placed them in /config/ssh_keys/ and added the following to my configuration.yaml:
SSH key setup and fetch command
shell_command:
fetch_nas_logs: >
ssh -i /config/ssh_keys/nas_key -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null [email protected] '
echo "=== HOST SYSTEM LOGS ===";
journalctl --since "15 minutes ago" --no-pager -n 450;
echo "=== PLANNED OMV TASKS (CRON) ===";
journalctl --since "15 minutes ago" _COMM=cron --no-pager;
echo "=== DOCKER CONTAINER LOGS ===";
docker ps --format "{% raw %}{{.Names}}{% endraw %}" | xargs -I {} sh -c "echo [Container: {}]; docker logs --since 15m {} 2>&1 | tail -n 150"
'
This shell command connects to the NAS via SSH and collects logs from the last 15 minutes. It retrieves three types of logs: the general system journal (limited to the last 450 lines), cron jobs that ran via the system scheduler, and logs from all running Docker containers (last 150 lines each). All logs are combined into a single output that can be sent to Gemini for analysis.
Gemini integration setup
Then I had to setup the Gemini integration in HomeAssistant.
I signed into the Google AI Studio, created a project, made sure to not connect a billing account (because I don’t want to pay for this and the free tier is sufficient for my needs), and created an API key.
I then added the Gemini integration to HomeAssistant and configured it with the API key I just created: Add Integration -> Google -> Google Gemini.
I mostly left the default settings, but I did change the model to gemini-2.5-flash.
Gemini 2.5 flash may not be the most recent model, but it is powerful enough and when I tested Gemini 3.5 flash I ran into issues because the demand for the model was too high and the API would return errors.
Automation: trigger and actions
Next thing I did was to create an automation in HomeAssistant that triggers when the power consumption of the NAS exceeds 21 watts for more than 10 minutes.
This is the automation I created. I will go over some of the interesting parts of it below:
Automation YAML
alias: "NAS: Anomalous Power Consumption Investigation"
description: >-
Collects NAS logs, analyzes the spike with Gemini, and sends the result to my phone.
triggers:
- trigger: numeric_state
entity_id:
- sensor.eve_energy_20ebo8301_power
for:
hours: 0
minutes: 10
seconds: 0
above: 21
conditions: []
actions:
- action: shell_command.fetch_nas_logs
metadata: {}
data: {}
response_variable: nas_logs
- repeat:
until:
- condition: or
conditions:
- condition: template
value_template: >-
{{ gemini_response is defined and gemini_response.data is defined }}
- condition: template
value_template: "{{ repeat.index >= 3 }}"
sequence:
- action: ai_task.generate_data
continue_on_error: true
metadata: {}
data:
entity_id: ai_task.gemini_2_5_flash
task_name: NAS System & Docker Analyse
instructions: >-
The smart plug on my NAS reported an unusual load spike.
I am providing both the host system logs (under "HOST SYSTEM LOGS") and the logs of each Docker container (under "DOCKER CONTAINER LOGS") from the last 5 minutes.
Analyze impartially whether a system process (e.g., CPU governor, IO‑wait, ZFS/Btrfs scrubbing, cron jobs) or a specific Docker container is responsible for the load spike. Summarize the cause briefly and concisely.
Logs: {{ nas_logs['stdout'] }}
response_variable: gemini_response
- condition: template
value_template: >-
{{ gemini_response is not defined or gemini_response.data is not defined }}
- delay:
hours: 0
minutes: 0
seconds: 15
milliseconds: 0
- condition: template
value_template: "{{ gemini_response is defined and gemini_response.data is defined }}"
- action: notify.notify
metadata: {}
data:
title: NAS Power Consumption Analysis
message: "{{ gemini_response.data }}"
mode: single
The automation starts with a simple numeric state trigger. If the NAS stays above 21 watts for at least 10 minutes, HomeAssistant assumes that something is worth investigating and begins gathering context.
First, it runs the SSH shell command that collects the most recent host journal entries, cron activity, and Docker logs. That gives Gemini enough context to check whether the spike came from the host itself or from one of the containers.
After the logs are collected, HomeAssistant sends them to Gemini through the AI task integration. I wrapped that call in a small retry loop because I wanted the automation to be resilient if the first attempt fails or the model temporarily does not return a usable response. Once Gemini produces a summary, HomeAssistant forwards it to my phone as a push notification so I can review the likely cause without having to log in manually.
Final Thoughts
I turned a tedious manual process into a fully automated one that runs in the background and only notifies me when something is worth investigating. I am very happy with the result and I am looking forward to seeing how this automation will help me in the future to quickly identify the cause of any power consumption spikes on my NAS.
Logs of any kind may contain sensitive information, so I would like to emphasize that you should be fine with the fact that you are handing them over to Gemini and Google.