LetsEncrypt stops

I’m getting the same log as described in: How to configure Let's Encrypt SSL Certificates for Home Assistant completely 100% free (Updated for 2022/2023) - #11 by typeonegative

In my scenario - it seems that my certificate was not renewed in time. I’ve followed @HoneypotLeopard 's post and configured LE with Cloudflare.
Despite LE success in fetching those certificates, my SSL access is still broken and LE addon stops.

  • Port forwarding works properly.
  • I reach HA when I’m visiting my domain but I get an Unable to connect to Home Assistant. error. There is no certificate error. (see image)
  • I can reach and login if I use my local network IP (using https://192.168.10.10). In this case I (obviously) get a certification error in my browser.

My LE config:

domains:
  - hass.mydomain.com
  - hass-local.mydomain.com
email: <an email I use for Letsencrypt>
keyfile: privkey.pem
certfile: fullchain.pem
challenge: dns
dns:
  provider: dns-cloudflare
  cloudflare_email: <my cloudflare account email>
  cloudflare_api_token: <my cloudflare token>

My configuration.yaml:

http:
#  server_port: 443 (commented since it feels redundant)
  ssl_certificate: /ssl/fullchain.pem
  ssl_key: /ssl/privkey.pem

My gut feeling tells me this is not a configuration error but some stubborn cache of some sort, but I can’t put my finger on it.
Any insights?

Start the LE addon again and then look at its log.
This will tell if a certificate was fetched or already there or if there were some errors.

The log doesn’t show any errors. In fact, it even makes me think the certificate is intact.
And then the addon stops again…

s6-rc: info: service s6rc-oneshot-runner: starting
s6-rc: info: service s6rc-oneshot-runner successfully started
s6-rc: info: service fix-attrs: starting
s6-rc: info: service fix-attrs successfully started
s6-rc: info: service legacy-cont-init: starting
cont-init: info: running /etc/cont-init.d/file-structure.sh
cont-init: info: /etc/cont-init.d/file-structure.sh exited 0
s6-rc: info: service legacy-cont-init successfully started
s6-rc: info: service legacy-services: starting
services-up: info: copying legacy longrun lets-encrypt (no readiness notification)
s6-rc: info: service legacy-services successfully started
[14:18:20] INFO: Selected DNS Provider: dns-cloudflare
[14:18:20] INFO: Use propagation seconds: 60
[14:18:20] INFO: Use CloudFlare token
[14:18:20] INFO: Detecting existing certificate type for hass.mydomain.com
Saving debug log to /var/log/letsencrypt/letsencrypt.log
[14:18:24] INFO: Existing certificate using 'ecdsa' key type.
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Certificate not yet due for renewal
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Certificate not yet due for renewal; no action taken.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
s6-rc: info: service legacy-services: stopping
s6-rc: info: service legacy-services successfully stopped
s6-rc: info: service legacy-cont-init: stopping
s6-rc: info: service legacy-cont-init successfully stopped
s6-rc: info: service fix-attrs: stopping
s6-rc: info: service fix-attrs successfully stopped
s6-rc: info: service s6rc-oneshot-runner: stopping
s6-rc: info: service s6rc-oneshot-runner successfully stopped

Just read your post again.
It sounds like you had a certificate up and running, but the renewal failed.

When using the certificate directly on HA, there will be two issues with the LE addon.

First the addon, per default, only runs at host boot it seems.
I have an automation to handle that part.

Secondly the certificate is only read on HA core boot, so when your script have updated the certificate, then you need to reboot the HA core.
I have set up a notification for this part, because I do not trust an automatic boot of HA core.

Here is the certificate renewal script.

alias: Renew certificate
description: >-
  Restart the Let's Encrypt Addon, when a certificates have less than 29 days
  left.
triggers:
  - trigger: time_pattern
    hours: "1"
conditions:
  - alias: cert lifetime below 30
    condition: template
    value_template: >-
      {{
      (((states('sensor.cert_expiry')|as_timestamp(0))-(now()|as_timestamp))/(24*60*60))|int(0)
      < 30 }}
actions:
  - action: hassio.addon_start
    data:
      addon: core_letsencrypt
mode: single

The sensor is the standard HA certificate sensor.

1 Like

@WallyR nice script but missing one important detail

Can you also supply how you’re setting up

sensor.cert_expiry

Cheers

Thanks @WallyR
I’ve tried several reboots but maybe not in the right order…
Do you think a host-reboot should work (as it normally reboots HA as well)?

I restarted HA as proposed (see image)
Now my local access (using the local IP) is not working, but behold - HA is now accessible at its configured domain behind SSL.

So - goal achieved (I also have my companion app working again).

However one thing remains a mistery - the LetsEncrypt add-on is… off. Is that possible?
(I’m almost afraid to turn it on again :smiley: )

The LE addon is made so it starts up, checks if the certificate is in need of being renewed and if it is then it renews the certificate and then shutdown.
That is the reason why I made the automation.
It will check the certificate and if it has less than 30 days of validity, then it will start the LE addon up again to make it renew the certificate.

1 Like
1 Like

Nice one thanks Wally,

Out of curiosity, why don’t you NOT also restart HA as part of your automation ?

I have not made it part of the renewal automation, because it will try to update the certificate each hour when it is below 30 days validity.
If the Let’s Encrypt servers or my internet connection is down, then it might be delayed to some random time where I might need the HA to work.

I could set a boolean helper and then make it in another automation that restart HA on a specific time, but I have found that issues with HA is generally occurring when restarting, so I prefer to be present and have time to correct the issues, if they do occur. It might just be some annoying thing, like the Matter integration not connecting correctly to the Matter server or similar. A reload of the integration usually fix it.
Once my HA is running then it is generally incredible stable.

Boom,

Full better solution is here

Add file sensor to configuration.yaml instead of using the Certificate expiry sensor

  - sensor:
      command: 'echo $((($(date +%s) - $(stat -c "%Y" /ssl/fullchain.pem))/86400))'
      name: ssl cert age
      scan_interval: 300

Automation to check once a day and restart HA if needed, you can also expand on this automation to also distribute the new cert to other devices

alias: "LetsEncrypt: Renew certificate"
description: >-
  Restart the Let's Encrypt Addon, when a certificates have less than 29 days
  left.
triggers:
  - trigger: time
    at: "05:01:01"
conditions:
  - condition: numeric_state
    entity_id: sensor.ssl_cert_age
    above: 60
actions:
  - action: hassio.addon_start
    data:
      addon: core_letsencrypt
  - alias: Wait 5 minutes
    delay:
      hours: 0
      minutes: 5
      seconds: 0
  - alias: Check if cert has renewed
    condition: numeric_state
    entity_id: sensor.ssl_cert_age
    below: 60
  - action: homeassistant.restart
    metadata: {}
    data: {}
mode: single