This is an OLD post and should only really be used these days for non-standard installations. Instead you should use an addon that automatically keeps your certs up to date, or use the ssl sensor that is integrated into homeassistant
If, like me, you’ve followed the guides and installed a Letsencrypt SSL certificate, it is only valid for 90 days.
This code will allow you to represent the number of days remaining on the certificate as a sensor reading, so when you have only a week or so left you can renew it. You could use the sensor to trigger an alarm, or maybe even an auto-renew command, I haven’t got that far yet myself, but thought I’d share anyway…
Prerequisite - You will need to install ssl-cert-check if it is not already present on your system:
$ apt-get install ssl-cert-check
Configuration.yaml
sensor:
- platform: command_line
name: SSL cert expiry
unit_of_measurement: days
scan_interval: 86400
command: "ssl-cert-check -b -c /etc/letsencrypt/live/YOUR-URL.duckdns.org/cert.pem | awk '{ print $NF }' "
(Scan interval, 86400 seconds, is 24 hours)
Represented as a badge…
or in a card…
… and available to use in your scripts/automations as sensor.ssl_cert_expiry (or something very similar).
Hope this helps.