Skip to content

Instantly share code, notes, and snippets.

@gouthamravee
Created November 15, 2024 04:50
Show Gist options
  • Save gouthamravee/b4b2ff3ac51b223f8502fbd7e8aa9576 to your computer and use it in GitHub Desktop.
Save gouthamravee/b4b2ff3ac51b223f8502fbd7e8aa9576 to your computer and use it in GitHub Desktop.
Home Assistant + Shelly Restart Server Automation
alias: PMX 1 Down
description: >-
Sends a notification if PMX 1 is down.
triggers:
- trigger: state
entity_id:
- binary_sensor.node_pmx_status
from: "on"
to: unavailable
for:
hours: 0
minutes: 0
seconds: 0
- trigger: state
entity_id:
- binary_sensor.node_pmx_status
from: "on"
to: unknown
for:
hours: 0
minutes: 0
seconds: 0
- trigger: state
entity_id:
- binary_sensor.node_pmx_status
from: "on"
to: "off"
for:
hours: 0
minutes: 0
seconds: 0
conditions:
- condition: state
entity_id: input_boolean.network_closet_maintenance_mode
state: "off"
actions:
- sequence:
- variables:
PMX_NODE1_RESTART: "{{ 'PMX_NODE1_RESTART_' ~ context.id }}"
PMX_NODE1_MAINTENANCE: "{{ 'PMX_NODE1_MAINTENANCE_' ~ context.id }}"
- action: notify.user
metadata: {}
data:
title: Proxmox Node 1
message: Proxmox Node 1 is down!
data:
car_ui: true
notification_icon: mdi:alert-octagram
channel: Homelab
importance: high
ttl: 0
priority: high
color: "#FF3131"
actions:
- action: "{{ PMX_NODE1_RESTART }}"
title: Restart
- action: "{{ PMX_NODE1_MAINTENANCE }}"
title: Do Not Restart
push:
interruption-level: critical
clickAction: /dashboard/network-closet #click to go to lovelace page
url: /dashboard/network-closet #click to go to lovelace page
- wait_for_trigger: # wait for a response from the mobile notification
- event_type: mobile_app_notification_action
event_data:
action: "{{ PMX_NODE1_RESTART }}"
trigger: event
context:
user_id:
- <<user_id>>
id: PMX_NODE1_RESTART
- event_type: mobile_app_notification_action
event_data:
action: "{{ PMX_NODE1_MAINTENANCE }}"
trigger: event
context:
user_id:
- <<user_id>>
id: PMX_NODE1_MAINTENANCE
timeout:
hours: 0
minutes: 30
seconds: 0
milliseconds: 0
continue_on_timeout: true
- choose:
- conditions:
- condition: template
value_template: "{{ wait.trigger.event.data.action == PMX_NODE1_RESTART }}"
sequence:
- action: script.restart_pmx_1 ## script.yaml file
metadata: {}
data: {}
- conditions:
- condition: template
value_template: "{{ wait.trigger.event.data.action == PMX_NODE1_MAINTENANCE }}"
sequence:
- action: input_boolean.turn_on
metadata: {}
data: {}
target:
entity_id: input_boolean.network_closet_maintenance_mode
- action: script.restart_pmx_1
metadata: {}
data: {}
mode: single
alias: Restart PMX 1
sequence:
- condition: state
entity_id: input_boolean.network_closet_maintenance_mode
state: "off"
- choose:
- conditions:
- condition: or
conditions:
- condition: state
entity_id: binary_sensor.node_pmx_status
state: "off"
- condition: state
entity_id: binary_sensor.node_pmx_status
state: unavailable
- condition: state
entity_id: binary_sensor.node_pmx_status
state: unknown
sequence:
- type: turn_off
device_id: <<device_id>>
entity_id: <<entity_id>>
domain: switch
- delay:
hours: 0
minutes: 0
seconds: 30
milliseconds: 0
- type: turn_on
device_id: <<device_id>>
entity_id: <<entity_id>>
domain: switch
- action: notify.gouthaman
metadata: {}
data:
message: Proxmox Node 1 restarted.
title: Proxmox Node 1
data:
car_ui: true
notification_icon: mdi:check-circle
channel: Homelab
importance: high
ttl: 0
priority: high
color: "#00FF00"
push:
interruption-level: critical
clickAction: /dashboard/network-closet #click to go to lovelace page
url: /dashboard/network-closet #click to go to lovelace page
- delay:
hours: 0
minutes: 10
seconds: 0
milliseconds: 0
- action: notify.user
data:
message: Proxmox Node 1 is {{ states('binary_sensor.node_pmx_status') }}.
title: Proxmox Node 1
data:
car_ui: true
notification_icon: >-
{% if is_state('binary_sensor.node_pmx_status', 'on') %}
mdi:check-circle {% else %} mdi:alert-octagram {% endif %}
channel: Homelab
importance: >-
{% if is_state('binary_sensor.node_pmx_status', 'on') %} low {% else
%} high {% endif %}
ttl: 0
clickAction: /dashboard/network-closet #click to go to lovelace page
url: /dashboard/network-closet #click to go to lovelace page
description: ""
icon: mdi:restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment