Setup Home Assistant with Letsencrypt on Synology

Setup Lets Encrypt on Synology

How to install Let’s Encrypt SSL Certificate on Synology NAS with DSM 6


Rember that it validate on port 80 so forward port 80 to your Synology (remember Firewall)

Find Certificate : find / -name
Normal : /usr/syno/etc/certificate/system/default
Set rights:

sudo chmod 755 /usr/syno/etc/certificate/system/default
sudo chmod 755 /usr/syno/etc/certificate/system/default/privkey.pem
sudo chmod 755 /usr/syno/etc/certificate/system/default/fullchain.pem

Manual renew certificate : /usr/syno/sbin/syno-letsencrypt renew-all

Setup HA:
Create folders:

mkdir -p /volume1/docker/HA

Install Docker

sudo docker run -d –restart=always –name=”home-assistant” -v /volume1/docker/HA:/config -v /usr/syno/etc/certificate/system/default:/ssl -e “TZ=Europe/Copenhagen” –net=host homeassistant/home-assistant

Configuration.yaml

#####################################
### HTTP
#####################################
http:
base_url: https://%homeassistantdnsname%:8123
ssl_certificate: /ssl/fullchain.pem
ssl_key: /ssl/privkey.pem

Sensor.yaml

#####################################
### Cert Check
#####################################
– platform: command_line
name: SSL cert expiry
unit_of_measurement: days
command: “/config/custom_components/check_cert.sh”

create: check_cert.sh
Set rights:

sudo chmod +s /volume1/docker/HA/custom_components/check_cert.sh

check_cert.sh:

# Website to check
website=”homeassistantdnsname”

# temporary file to store certificate
certificate_file=$(mktemp)

# delete temporary file on exit
trap “unlink $certificate_file” EXIT
echo -n | openssl s_client -servername “$website” -connect “$website”:8123 2>/dev/null | sed -ne ‘/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p’ > $certificate_file
certificate_size=$(stat -c “%s” $certificate_file)
if [ “$certificate_size” -gt “1” ]; then
date=$(openssl x509 -in $certificate_file -enddate -noout | sed “s/.*=\(.*\)/\1/”)
date_s=$(date -d “${date}” +%s)
now_s=$(date -d now +%s)
date_diff=$(( (date_s – now_s) / 86400 ))
echo “$date_diff”
if [ “$date_s” -gt “$now_s” ]; then
exit 0 # ok
else
exit 1 # not ok
fi
else
exit 254
fi
else
exit 255

Leave a Reply