Hi, found an curl command, but it doesnt work for me, probably cause the date setting, it should display the remaining days… since the “cert expiry” integration for some reason doesnt work for me anymore
here is the command:
curl -vI --insecure https://xxx.com:8123 2>&1 | grep "expire date" | sed 's/^* expire date: //' | xargs -I{} date -d "{}" +%s | awk -v now="$(date +%s)" '{print int(($1 - now) / 86400)}'
but i get as ouput error:
date: invalid date '* expire date: Mar 15 14:29:49 2025 GMT'
The sed
command’s regular expression wasn’t correctly matching the beginning of the line with the date. This version corrects it:
curl -vI --insecure https://google.com 2>&1 | grep "expire date" | sed 's/^.*expire date: //' | xargs -I{} date -d "{}" +%s | awk -v now="$(date +%s)" '{print int(($1 - now) / 86400)}'
hi, thnx for looking into it, but i still receive the same error?
if i do a grep on date only, i have this output:
maybe you see it different?
Oh, sorry, I tested on the wrong terminal and didn’t realize that the second problem is that the version of date
used in Home Assistant OS doesn’t support that time format.
What you can do is have your sensor just output the time stamp, like this:
curl -vI --insecure https://google.com 2>&1 | grep "expire date" | sed 's/^.*expire date: //'
Then have a template sensor convert that in to the “days until” format you are looking for:
{{ ((strptime(states("sensor.YOUR_CURL_SENSOR"),"%b %d %H:%M:%S %Y %Z") | as_timestamp - now() | as_timestamp) / 3600 / 24) | round(0,"floor")}}
thats working, thnx for the help!