Skip to content

Instantly share code, notes, and snippets.

@MXMLN-sec
Created February 6, 2025 13:08
Show Gist options
  • Save MXMLN-sec/541b6bb48c032976b47cd401664238af to your computer and use it in GitHub Desktop.
Save MXMLN-sec/541b6bb48c032976b47cd401664238af to your computer and use it in GitHub Desktop.
Home Assistant certificate expiry notification
upcoming_cert_expiry:
name: "TLS Zertifikat läuft bald ab"
entity_id: binary_sensor.<cert-name>_cert_renew_required
state: "on"
repeat:
- 1440
can_acknowledge: true
skip_first: false
title: >
{% set state = (states('binary_sensor.<cert-name>_cert_renew_required')) %}
{% if state == 'on' %}
⚠️ TLS Zertifikat läuft bald ab
{% else %}
✅ TLS Zertifikat wurde erneuert
{% endif %}
message: >
Das Zertifikat <cert-name> läuft in {{ states('sensor.<cert-name>_cert_valid_days') }} Tagen am {{ as_timestamp(states('sensor.<cert-name>_cert_expiration_date')) | timestamp_custom('%d.%m.%y') }} ab!
done_message: >
Das Zertifikat <cert-name> wurde erneuert und ist noch {{ states('sensor.<cert-name>_cert_valid_days') }} Tage bis zum {{ as_timestamp(states('sensor.<cert-name>_cert_expiration_date')) | timestamp_custom('%d.%m.%y') }} gültig.
notifiers:
- grp_notify
data:
tag: upcoming-cert-expiry
{% if int(states('sensor.<cert-name>_cert_valid_days')) is number %}
{% set valid_days = states('sensor.<cert-name>_cert_valid_days') %}
{{ iif(int(valid_days) <= 14, true, false) }}
{% endif %}
{% if states('sensor.<cert-name>_cert_expiration_date') is not in ["unknown", "unavailable", ""] %}
{% set expiration_date = states('sensor.<cert-name>_cert_expiration_date') %}
{{ (as_datetime(expiration_date) | as_local - today_at()).days }}
{% endif %}
@MXMLN-sec
Copy link
Author

This Home Assistant config notifies you 14 days before an TLS certificates expires. It requires
the Certificate Expiry
integration which monitors the expiration date of an certificate.
The monitored certificate in the integration has an ID like this:
sensor.<cert-name>_cert_expiration_date
Replace <cert-name> in all the configurations with your preferred name.

  • The template sensor calculate the amount of days the certificate will be valid
  • The template binary sensor will return true if the certificate is valid for 14 days or less
  • The alert will send an alert to your notification group once every day when the binary sensor is true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment