davorin
(Richard Klingler)
1
Good morning
Have a command_line sensor configured in configuration.yaml to check an IMAP server certificate expiry:
command_line:
- sensor:
name: Mail Server Zertifikat
unique_id: imap_server_cert_expiry
command: "echo | openssl s_client -4 -connect imap.example.com:993 -servername imap.example.com 2>/dev/null | openssl x509 -noout -enddate | cut -d= -f2"
scan_interval: 43200
unit_of_measurement: days
value_template: >-
{{ (( as_timestamp(strptime(value, '%b %d %H:%M:%S %Y %Z')) - as_timestamp(now()) ) / 86400 ) | round(0) }}
Running this command from the web shell is fine:
âžś ~ echo | openssl s_client -4 -connect imap.example.com:993 -servername imap.example.com 2>/dev/null | openssl x509 -noout -enddate | cut -d= -f2
Oct 8 12:23:31 2026 GMT
But when reloading YAML or do a complete restart protocol tells me that no value was returned.
Any hints?
Maybe like all bash scripting the pipeing goes wrong, so you may try to invoke the shell first.
Something like this:
command: "/bin/sh -c 'echo | openssl s_client -4 -connect imap.example.com:993 -servername imap.example.com 2>/dev/null | openssl x509 -noout -enddate | cut -d= -f2'"
davorin
(Richard Klingler)
3
No luck…
Command failed (with return code 127): "/bin/sh -c 'echo | openssl s_client -4 -connect imap.example.com:993 -servername imap.example.com 2>/dev/null | openssl x509 -noout -enddate | cut -d= -f2'"
Seems I need just to put up an apache2 webservice for this to use cert_expiry…
WallyR
(Wally)
4
You are probably running the two commands from two different environments.
HA will run the command in the HA container.
Your SSH will likely run in a totally different container.
davorin
(Richard Klingler)
5
Beats me (o;
Even ChatGPT and Jean Claude Van Damme were clueless today (o;
Going with the Apache2 approach then…should then certbot also automatically the certificate…
WallyR
(Wally)
6
Can I ask why you do not use the cert_expire in HA?
No idea if it works on IMAP too though.
WallyR
(Wally)
7
When you run the command what does the logs say?
davorin
(Richard Klingler)
8
cert_expiry fails sadly on IMAPS…
Or add openssl into the homeassistent (core) container
command: "apk add --quiet --no-cache openssl && echo | openssl s_client -4 -connect imap.example.com:993 -servername imap.example.com 2>/dev/null | openssl x509 -noout -enddate | cut -d= -f2"