/
renew_ssl_cert.yaml
99 lines (99 loc) · 3.15 KB
/
renew_ssl_cert.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
blueprint:
name: Renew Let's Encrypt Certificate
description: Renew Certificate when due date is below given value
domain: automation
input:
cert_expiry_sensor:
name: Certificate Expiry Sensor
description: Sensor from the Certificate Expiry Integration (https://www.home-assistant.io/integrations/cert_expiry)
selector:
entity:
integration: cert_expiry
renew_date:
name: Certificate renewal date
description: Date when the SSL-Certificate will be renewed
selector:
number:
min: 1
max: 29
mode: slider
unit_of_measurement: "days"
default: 5
time_to_check_cert:
name: Certificate check time
description: Time when the certificate date will be checked.
selector:
time:
restart_after_renewal:
name: Restart Home Assistant
description: Restarts the Home Assistant when the certificate is renewed. (if enabled)
selector:
boolean:
default: true
minuts_till_restart:
name: Minutes until restart
description: Minutes until restart of Home Assistant if restart is enabled
selector:
number:
min: 1
max: 60
mode: slider
unit_of_measurement: "minutes"
default: 5
send_notification:
name: Send notification
description: Sends a notification if enabled
selector:
boolean:
default: false
notification_title:
name: Notification title
description: Notification title for notification that is sent when the certificate has been renewed.
notification_message:
name: Notification message
description: Notification that is sent when the certificate has been renewed.
alias: Renew SSL Cert
description: ''
trigger:
- platform: time
at: !input time_to_check_cert
condition:
- condition: template
value_template: '{{ expire_days_var < var_check }}'
action:
- service: hassio.addon_start
data:
addon: core_letsencrypt
- choose:
- conditions:
- condition: template
value_template: '{{ send_notification_var }}'
sequence:
- service: notify.notify
data:
message: '{{ message_var }}'
title: '{{ message_title_var }}'
default: []
- choose:
- conditions:
- condition: template
value_template: '{{ restart_after_renewal_var }}'
sequence:
- delay:
hours: 0
minutes: !input minuts_till_restart
seconds: 0
milliseconds: 0
- service: hassio.host_reboot
default: []
mode: single
variables:
certificate_var: !input cert_expiry_sensor
var_check: !input renew_date
message_var: !input notification_message
message_title_var: !input notification_title
restart_after_renewal_var: !input restart_after_renewal
send_notification_var: !input send_notification
expire_days_var: >-
{{ ((as_timestamp(states(certificate_var), 0) - as_timestamp(now())) / 60 / 60 /
24 ) | int }}