core: Certificate Expiry sensor comes up as 'Unavailable' on every restart

The problem

I am still having the Cert Expiry sensor come up in an unavailable state on every restart. If I leave it alone it resets itself with the correct value in 24 hours or so. I thought this was fixed and I don’t see any open issue for it currently, so not sure what I’m doing differently.

Environment

  • Home Assistant release with the issue: 0.105.5
  • Last working Home Assistant release (if known): I don’t know if it’s ever worked for me
  • Operating environment (Hass.io/Docker/Windows/etc.): HomeAssistant (hass.io) on Ubuntu Virtualbox host, running on Windows 10
  • Integration causing this issue: Certificate Expiry, installed using Integrations page
  • Link to integration documentation on our website: https://www.home-assistant.io/integrations/cert_expiry/

Problem-relevant configuration.yaml

N/A, installed via integrations UI

Traceback/Error logs

2020-02-18 16:42:34 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.ssl_certificate_expiry fails
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 279, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 461, in async_device_update
    await self.hass.async_add_executor_job(self.update)
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/cert_expiry/sensor.py", line 122, in update
    cert = get_cert(self.server_name, self.server_port)
  File "/usr/src/homeassistant/homeassistant/components/cert_expiry/helper.py", line 12, in get_cert
    with socket.create_connection(address, timeout=TIMEOUT) as sock:
  File "/usr/local/lib/python3.7/socket.py", line 728, in create_connection
    raise err
  File "/usr/local/lib/python3.7/socket.py", line 716, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

Additional information

My guess is that the certificate expiry sensor is trying to update before HA is ready to access the domain. If I remove and reinstall the integration after HA is up and running, it works fine… until the next restart. It is consistent and happens on EVERY restart of HA.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 34 (14 by maintainers)

Most upvoted comments

Ok looking at the code between this integration and the HTTP server, there’s definitely a race as they both try to init at the same time.

I’m confortable with that, and as you said earlier, the default name make sense now.

That’s reasonable, I’ll add it back in later today. But remember that you can’t update the name from the config file and that it’s only used during creation.

I agree with you, the old default name were kind of bad… That’s why I was using custom one.

Knowing the new default name, I’m kinda happy with the change and I’m not asking for more.

Having said that, if you want to do more modification, you could keep both behavior by changing the title to something like that : title = user_input.get(CONF_NAME, host + (f":{port}" if port != DEFAULT_PORT else ""))

That way, we can still override the name with the configuration.yaml and we are sure that it’ll not break other users configuration if they were like me and not using the Entities editor.

You also get the better default name.

First time I hear about the entity registry… I just read a bit about it and it’s really nice. Sorry for my ignorance…

Knowing that, everything work as intended here. The log are really better than the last one.

Great job !

It worked ! I even saw the state transition between “unavailable” and the number of day.

Good job !

Yes, but it’s a pretty invasive change. I’m trying to not change core or other integrations to fix the behavior of this one.

I made a silly mistake earlier, just pushed a small commit to the linked PR. It was updating the entity during the retry, but not actually changing its state as seen by HA.