Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save peyanski/ccb20f9f8a893f5523f4f309930b300d to your computer and use it in GitHub Desktop.

Select an option

Save peyanski/ccb20f9f8a893f5523f4f309930b300d to your computer and use it in GitHub Desktop.
alias: AI System Monitor - Resource Pressure Decoder
description: >-
When sustained memory pressure, IO pressure, memory use, or CPU use crosses a
starter threshold, send a small System Monitor snapshot to an Ollama-backed AI
Task and create one plain-language persistent notification. Tune the
thresholds, CPU-core count, and entity IDs for your own Home Assistant host.
triggers:
- trigger: numeric_state
entity_id:
- sensor.system_monitor_memory_pressure_full_60s_average
above: 5
for:
hours: 0
minutes: 1
seconds: 0
id: memory_pressure_full
- trigger: numeric_state
entity_id:
- sensor.system_monitor_io_pressure_full_60s_average
above: 5
for:
hours: 0
minutes: 1
seconds: 0
id: io_pressure_full
- trigger: numeric_state
entity_id:
- sensor.system_monitor_memory_usage
above: 90
for:
hours: 0
minutes: 1
seconds: 0
id: memory_high
- trigger: numeric_state
entity_id:
- sensor.system_monitor_processor_use
above: 90
for:
hours: 0
minutes: 1
seconds: 0
id: cpu_high
conditions: []
actions:
- variables:
cpu_core_count: 4
memory_entity: sensor.system_monitor_memory_usage
cpu_entity: sensor.system_monitor_processor_use
cpu_temperature: sensor.system_monitor_processor_temperature
load_1_entity: sensor.system_monitor_load_1_min
load_5_entity: sensor.system_monitor_load_5_min
load_15_entity: sensor.system_monitor_load_15_min
uptime_entity: sensor.system_monitor_uptime
memory_pressure_some_entity: sensor.system_monitor_memory_pressure_some_60s_average
memory_pressure_full_entity: sensor.system_monitor_memory_pressure_full_60s_average
io_pressure_some_entity: sensor.system_monitor_io_pressure_some_60s_average
io_pressure_full_entity: sensor.system_monitor_io_pressure_full_60s_average
cpu_pressure_some_entity: sensor.system_monitor_cpu_pressure_some_60s_average
trigger_reason: |-
{{ trigger.id if trigger is defined and trigger.id is defined
else 'manual_test' }}
fallback_report: >-
Home Assistant detected or manually tested a system-health condition,
but the AI report was not available. Check History and Traces for
processor use, memory use, load, and pressure. Do not restart services
or delete anything until you know what caused the sustained reading.
- alias: Create an immediate deterministic warning before calling AI
action: persistent_notification.create
data:
notification_id: ai_system_monitor_resource_pressure
title: |-
{% set labels = {
'memory_pressure_full': 'Memory pressure stayed high',
'io_pressure_full': 'IO pressure stayed high',
'memory_high': 'Memory use stayed high',
'cpu_high': 'Processor use stayed high',
'manual_test': 'Manual system-health test'
} %} {{ labels.get(trigger_reason, 'System-health report') }}
message: >-
Home Assistant fired the deterministic {{ trigger_reason }} check. The
AI Task is translating the current PSI, CPU, memory, load, and uptime
values now. No restart, cleanup, settings change, or control action has
run.
- alias: Ask Ollama AI Task to translate the System Monitor snapshot
continue_on_error: true
action: ai_task.generate_data
data:
entity_id: ai_task.ollama_ai_task_gpt_oss_120b_cloud
task_name: AI System Monitor Resource Pressure Report
instructions: >-
You are translating a small Home Assistant System Monitor snapshot into
normal language. A deterministic Home Assistant trigger fired; you did
not choose the trigger. The trigger ID is {{ trigger_reason }}.
CPU cores configured by the user: {{ cpu_core_count }} Processor use: {{
states(cpu_entity) }}% Memory use: {{ states(memory_entity) }}% Load
average, 1 minute: {{ states(load_1_entity) }} Load average, 5 minutes:
{{ states(load_5_entity) }} Load average, 15 minutes: {{
states(load_15_entity) }} Last boot time: {{ states(uptime_entity) }}
Memory pressure some, 60-second average: {{
states(memory_pressure_some_entity) }}% Memory pressure full, 60-second
average: {{ states(memory_pressure_full_entity) }}% IO pressure some,
60-second average: {{ states(io_pressure_some_entity) }}% IO pressure
full, 60-second average: {{ states(io_pressure_full_entity) }}% CPU
pressure some, 60-second average: {{ states(cpu_pressure_some_entity)
}}%
Ignore unknown, unavailable, or missing readings. In no more than 140
words, do all of the following: 1. Start with one plain verdict: normal,
busy, or struggling. 2. Explain the trigger and the useful PSI readings
in normal language. 3. Compare the 1, 5, and 15 minute load trend with
the configured CPU-core
count, but do not call a load value dangerous from one snapshot alone.
4. Give three safe checks in order.
Do not claim a root cause that these readings cannot prove. Do not tell
the user to delete files, restart Home Assistant, stop add-ons, or
change settings automatically. Do not use emojis.
5. Include in the report the CPU temperature {{ states(cpu_temperature)
}}% and if the levels are too high for a regular x86 or ARM cpu say
that.
6. Translate the last boot time into simple uptime context when
available and list it only if it is above 20 days recommending to plan a
restart just
7. Format the text to be easily readable (or playable from speakers)
with bullets or something
response_variable: ai_response
- alias: Create or update one plain-language system-health notification
action: persistent_notification.create
data:
notification_id: ai_system_monitor_resource_pressure
title: |-
{% set labels = {
'memory_pressure_full': 'Memory pressure stayed high',
'io_pressure_full': 'IO pressure stayed high',
'memory_high': 'Memory use stayed high',
'cpu_high': 'Processor use stayed high',
'manual_test': 'Manual system-health test'
} %} {{ labels.get(trigger_reason, 'System-health report') }}
message: |-
{{ ai_response.data
if ai_response is defined and ai_response.data is defined
else fallback_report }}
mode: single
max_exceeded: silent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment