Category Archives: Home Assistant

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

Setup TasmoAdmin on Synology DOCKER

create dirs for Docker Volumes(data)

mkdir -p /volume1/docker/Portainer/data
mkdir -p /volume1/docker/TasmoAdmin/data

install Portainer

sudo docker run -d -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock -v /volume1/docker/Portainer/data:/data –name=Portainer –restart=always portainer/portainer


#install tasmoadmin

sudo docker run -d -p 5555:80 -v /volume1/docker/TasmoAdmin/data:/data –name=TasmoAdmin –restart=always raymondmm/tasmoadmin

#check if containers r running

sudo docker ps

Setup MQTT on Synology DOCKER

Create folders:

mkdir -p /volume1/docker/mqtt/log
mkdir -p /volume1/docker/mqtt/data
mkdir -p /volume1/docker/mqtt/config
chmod 0777 /volume1/docker/mqtt/log

Cerate conf file: (/volume1/docker/mqtt/config/mosquitto.conf)

pid_file /var/run/mosquitto.pid
persistence true
persistence_location /mqtt/data/
password_file /mqtt/config/passwd_file
allow_anonymous false
user mosquitto
# Port to use for the default listener.
port 1883
log_dest file /mqtt/log/mosquitto.log
log_dest stdout

Setup Passws_file:

cd /volume1/docker/mqtt/data
mosquitto_passwd -c passwd_file %username%
password: %password%

Start Docker

sudo docker run –name mqtt –restart=always –net=host -tid -v /volume1/docker/mqtt/config:/mqtt/config:ro -v /volume1/docker/mqtt/log:/mqtt/log -v /volume1/docker/mqtt/data/:/mqtt/data/ toke/mosquitto