I have this automation set up to renew my SSL cert when its below 29 days remaining to renew. However the automation does not work until I renew manually with the command:
That automation looks like it’s trying to use the same port as Home Assistant, which would require Home Assistant to be shut down first - at which point how’s the automation going to run?
Try forwarding a different port just for certificate renewal, and not shutting HA down, but restart it instead.
Running it once a minute, for a certificate that will be automatically renewed weeks in advance, that’s just a pointless load on the system. It’s like having kids in the back of your car on a long journey with them continually asking Are we nearly there yet?
When you run it from an automation it runs as homeassistant. When you run it manually it runs as the user you’re logged in as (probably pi).
You can simply run it as pi and schedule it with crontab -e. Alternatively, you’ll have to change the ownership of all the relevant files to homeassistant. That probably means the files in /etc/letsencrypt:
sudo find /etc/letsencrypt -user pi -exec chown homeassistant:homeassistant {} \;
That will change the owner of all files currently owned by pi under /etc/letsencrypt. At that point you’ll no longer be able to run the certbot-auto command as pi.
Hi!
in case someone else stumbles upon this problem: I experienced it as well and the reason is that letsencrypt/certbot-auto really wants to have sudo permissions and requires to have an input device present (tty). You can figure this out when changing the logger level for the shell_command:
2019-12-31 11:25:29 INFO (MainThread) [homeassistant.helpers.script] Script Auto Renew SSL Cert: Executing step call service
2019-12-31 11:25:30 DEBUG (MainThread) [homeassistant.components.shell_command] Stdout of command: '/home/homeassistant/certbot/certbot-auto -h', return code: 1:
b'Requesting to rerun /home/homeassistant/certbot/certbot-auto with root privileges...\n'
2019-12-31 11:25:30 DEBUG (MainThread) [homeassistant.components.shell_command] Stderr of command: '/home/homeassistant/certbot/certbot-auto -h', return code: 1:
b'**sudo: no tty present and no askpass program specified**\n'
2019-12-31 11:25:30 ERROR (MainThread) [homeassistant.components.shell_command] Error running command: '/home/homeassistant/certbot/certbot-auto -h', return code: 1
NoneType: None
The input device is not present when running from home assistant automation - hence the shell_script returns with code 1.
You could now allow the home assistant user to run “sudo” without password input which I did not try because I really don’t like the idea that the home assistant user has root permissions - a bit of a security concern. Hence, I chose to go for the cronjob solution as well.