-
-
Notifications
You must be signed in to change notification settings - Fork 5
Automation Examples
MrD3y5eL edited this page Jan 12, 2025
·
2 revisions
This guide provides practical automation examples for the Home Assistant Unraid integration. These examples demonstrate how to automate various tasks and monitoring scenarios.
alias: "Unraid Array Space Warning"
description: "Notify when array space is running low"
trigger:
- platform: numeric_state
entity_id: sensor.unraid_array_usage
above: 85
condition: []
action:
- service: notify.notify
data:
title: "Unraid Array Space Warning"
message: >
Array usage is at {{ states('sensor.unraid_array_usage') }}%
Free space: {{ state_attr('sensor.unraid_array_usage', 'free_space') }}
alias: "Unraid Cache Drive Management"
description: "Move data from cache to array when cache is nearly full"
trigger:
- platform: numeric_state
entity_id: sensor.unraid_cache_usage
above: 90
condition:
- condition: time
after: "02:00:00"
before: "04:00:00"
action:
- service: unraid.execute_command
data:
entry_id: "1234abcd5678efgh"
command: "/usr/local/sbin/move_to_array.sh"
- service: notify.notify
data:
title: "Unraid Cache Management"
message: "Started moving data from cache to array"
alias: "Unraid Temperature Warning"
description: "Alert when CPU temperature is too high"
trigger:
- platform: numeric_state
entity_id: sensor.unraid_cpu_temperature
above: 75
for:
minutes: 5
condition: []
action:
- service: notify.notify
data:
title: "⚠️ Unraid Temperature Alert"
message: >
CPU Temperature is {{ states('sensor.unraid_cpu_temperature') }}°C!
Please check system cooling.
- service: unraid.execute_command
data:
entry_id: "1234abcd5678efgh"
command: "echo 'High temperature warning' >> /var/log/temperature_alerts.log"
alias: "Restart Plex on Issues"
description: "Restart Plex container if streams are failing"
trigger:
- platform: state
entity_id: binary_sensor.plex_streams_working
to: "off"
for:
minutes: 2
condition:
- condition: state
entity_id: switch.unraid_docker_plex
state: "on"
action:
- service: switch.turn_off
target:
entity_id: switch.unraid_docker_plex
- delay:
seconds: 30
- service: switch.turn_on
target:
entity_id: switch.unraid_docker_plex
- service: notify.notify
data:
title: "Plex Container Restarted"
message: "Plex container was automatically restarted due to streaming issues"
alias: "Unraid Docker Updates"
description: "Update Docker containers during night"
trigger:
- platform: time
at: "03:00:00"
condition:
- condition: time
weekday:
- mon
action:
- service: unraid.execute_command
data:
entry_id: "1234abcd5678efgh"
command: "docker container ls -q | xargs -r docker update"
- service: notify.notify
data:
title: "Docker Updates"
message: "Weekly Docker container updates completed"
alias: "Weekly Unraid Backup"
description: "Perform weekly backup of appdata"
trigger:
- platform: time
at: "01:00:00"
condition:
- condition: time
weekday:
- sun
action:
- service: unraid.execute_user_script
data:
entry_id: "1234abcd5678efgh"
script_name: "backup_appdata.sh"
background: true
- service: notify.notify
data:
title: "Unraid Backup Started"
message: "Weekly appdata backup has been initiated"
alias: "Monthly Unraid Maintenance"
description: "Run monthly maintenance tasks"
trigger:
- platform: time_pattern
day: "1"
hours: "4"
minutes: "0"
condition: []
action:
- service: unraid.execute_user_script
data:
entry_id: "1234abcd5678efgh"
script_name: "monthly_maintenance.sh"
background: true
- service: notify.notify
data:
title: "Unraid Maintenance"
message: "Monthly maintenance tasks started"
alias: "Start Unraid Array After Power Loss"
description: "Start array when power is restored"
trigger:
- platform: state
entity_id: binary_sensor.unraid
from: "off"
to: "on"
condition:
- condition: template
value_template: "{{ states('sensor.unraid_array_state') != 'STARTED' }}"
action:
- delay:
minutes: 5
- service: unraid.execute_command
data:
entry_id: "1234abcd5678efgh"
command: "/usr/local/sbin/start_array.sh"
alias: "Unraid UPS Protection"
description: "Safely shutdown when UPS battery is low"
trigger:
- platform: numeric_state
entity_id: sensor.unraid_ups_battery_charge
below: 20
condition:
- condition: state
entity_id: binary_sensor.power_outage
state: "on"
for:
minutes: 10
action:
- service: notify.notify
data:
title: "⚡ UPS Battery Critical"
message: "Initiating safe shutdown of Unraid server"
- service: unraid.execute_command
data:
entry_id: "1234abcd5678efgh"
command: "shutdown -h now"
-
Test Commands First
- Always test commands manually before adding them to automations
- Use appropriate delays when needed
- Consider potential failure scenarios
-
Error Handling
- Add notifications for failures
- Log important events
- Use conditions to prevent unwanted triggers
-
Performance Considerations
- Use appropriate trigger intervals
- Run resource-intensive tasks during off-peak hours
- Consider using the
background: true
option for long-running scripts
-
Security
- Don't include sensitive information in commands
- Use appropriate permissions in scripts
- Log security-relevant events
-
Maintenance
- Keep scripts updated
- Monitor automation logs
- Review and adjust trigger conditions as needed
These examples can be customized based on your specific needs and server configuration. Remember to replace 192.168.1.10
with your Unraid server's IP address or hostname.