Restart Haas on error

As I keep on getting errors every once in a while with 1 of my sensors (emoncms_history) and with influxdb coming up late after a reboot. I was thinking of executing an automatic restart of HASS as soon as an error gets detected. The automatic restart isn’t that much of a problem (simple script) but how to build the trigger?

For emoncms I can probably build something which measures time last updated and if it is longer than 10 mins ago something probably went wrong, but for influxdb I simply get an error that hass failed to set it up so I don’t know how to use that as a trigger.

Any tips?

Hi @fversteegen, maybe you can use something from this topic.

You might want to look at fixing the problem rather than using a dirty workaround ^^

You could for example restart hass only 30 seconds or 2 minutes after restart?
How do you run HASS? On hass.io? In a docker container?

Exactly what I was looking for VDrainer. Thanks!

@touliloup I know I would rather fix the issue but could not find the real issue. Only thing I am getting is timeouts and connection errors, but whenever I check the connection manually everything is working fine! The issue arises when I did a clean install of Raspbian Stretch and Hass 58.1. I even manually edited the timeout to 30 seconds but the problem still arises every now and then. I have the feeling the real issue is either in Python 3.5 or in Hass 58+. When I look at the issues on Github more people have similar issues.

Hum, I had strange problem with a mysql database, I simply changed to postgresql and it’s working much better now.

Maybe simply changing to another database could solve your problem?

Main reason I don’t or cannot change is due to security. I don’t want to have any inbound connections to my local homeassistant instance, so I want hass to publish some values to a webserver running Emoncms. It always worked flawlessly…

Have you made sure that HA starts after influxdb by adding this to your HA systemd start file?

After=network.target mosquitto.service influxdb.service

The problem isn’t local; it is with the connection to my webserver. I am absolutely sure my webserver is up and running.

2017-12-05 12:50:18 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.kwhday_cv fails
Traceback (most recent call last):
File “/usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py”, line 387, in _make_request
six.raise_from(e, None)
File “”, line 2, in raise_from
File “/usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py”, line 383, in _make_request
httplib_response = conn.getresponse()
File “/usr/lib/python3.5/http/client.py”, line 1198, in getresponse
response.begin()
File “/usr/lib/python3.5/http/client.py”, line 297, in begin
version, status, reason = self._read_status()
File “/usr/lib/python3.5/http/client.py”, line 258, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), “iso-8859-1”)
File “/usr/lib/python3.5/socket.py”, line 576, in readinto
return self._sock.recv_into(b)
socket.timeout: timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/usr/local/lib/python3.5/dist-packages/requests/adapters.py”, line 440, in send
timeout=timeout
File “/usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py”, line 639, in urlopen
_stacktrace=sys.exc_info()[2])
File “/usr/local/lib/python3.5/dist-packages/urllib3/util/retry.py”, line 357, in increment
raise six.reraise(type(error), error, _stacktrace)
File “/usr/local/lib/python3.5/dist-packages/urllib3/packages/six.py”, line 686, in reraise
raise value
File “/usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py”, line 601, in urlopen
chunked=chunked)
File “/usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py”, line 389, in _make_request
self._raise_timeout(err=e, url=url, timeout_value=read_timeout)
File “/usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py”, line 309, in _raise_timeout
raise ReadTimeoutError(self, url, “Read timed out. (read timeout=%s)” % timeout_value)
urllib3.exceptions.ReadTimeoutError: HTTPConnectionPool(host=‘www.URLNAME.nl’, port=80): Read timed out. (read timeout=5)

I get an error like that every few days with influxdb (on my Pi). Its a temporary problem that seems to correspond to influxdb compressing its data files. There doesn’t seem any need to restart HA because of them as the connection is then re-established.

At my end the component simply stops working after it produces this error. The connection isn’t re-established.