InfluxDB sensor and community addon

Hello,

I’m having some difficulties running https://github.com/hassio-addons/addon-influxdb together with https://www.home-assistant.io/components/influxdb/#sensor. When I reboot hassio i’m greeted with the following messages in my log:

Database host is not accessible due to 'HTTPConnectionPool(host='192.168.2.89', port=8086): Max retries exceeded with url: /write?db=home_assistant (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f8f78c2d350>: Failed to establish a new connection: [Errno 111] Connection refused'))', please check your entries in the configuration file (host, port, etc.) and verify that the database exists and is READ/WRITE. Retrying again in 60 seconds.

My sensor is defined as:

- platform: influxdb
  host: 192.168.2.89
  username: homeassistant
  password: !secret influxdb_password
  queries:
  - name: gas_stand_maand_geleden
    unit_of_measurement: 'm3'
    group_function: min
    where: '"entity_id" = ''gas_consumption'' and time > now() - 30d'
    measurement: '"m3"'
  ...

My understanding is that influxdb isn’t up yet when HA is starting, but even after the 60 second retry it isn’t up. When I only restart HA, as opposted to restarting hassio, it does set up the component and my sensor shows up (but that is not a feasable solution for me currently, as for some reason zwave doesn’t like it, and can’t connect to the usb stick anymore)

Any idea where to start to get influx db to connect?

  • delay HA startup?
  • make it reconnect more often?
  • have nginx in the addon start earlier, so hopefully it will accept it, even though the first few queries will fail because influx hasn’t started yet

Thx for thinking with me!

Oh, I also have the following messages in my log

Error while setting up platform influxdb
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/urllib3/connection.py", line 160, in _new_conn
    (self._dns_host, self.port), self.timeout, **extra_kw)
  File "/usr/local/lib/python3.7/site-packages/urllib3/util/connection.py", line 80, in create_connection
    raise err
  File "/usr/local/lib/python3.7/site-packages/urllib3/util/connection.py", line 70, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 603, in urlopen
    chunked=chunked)
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 355, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/usr/local/lib/python3.7/http/client.py", line 1244, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/local/lib/python3.7/http/client.py", line 1290, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/local/lib/python3.7/http/client.py", line 1239, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/local/lib/python3.7/http/client.py", line 1026, in _send_output
    self.send(msg)
  File "/usr/local/lib/python3.7/http/client.py", line 966, in send
    self.connect()
  File "/usr/local/lib/python3.7/site-packages/urllib3/connection.py", line 183, in connect
    conn = self._new_conn()
  File "/usr/local/lib/python3.7/site-packages/urllib3/connection.py", line 169, in _new_conn
    self, "Failed to establish a new connection: %s" % e)
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7f8f769e3350>: Failed to establish a new connection: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
    timeout=timeout
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 641, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/usr/local/lib/python3.7/site-packages/urllib3/util/retry.py", line 399, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='192.168.2.89', port=8086): Max retries exceeded with url: /query?q=SHOW+SERIES+LIMIT+1%3B&db=home_assistant (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f8f769e3350>: Failed to establish a new connection: [Errno 111] Connection refused'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 149, in _async_setup_platform
    await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT)
  File "/usr/local/lib/python3.7/asyncio/tasks.py", line 442, in wait_for
    return fut.result()
  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/influxdb/sensor.py", line 85, in setup_platform
    sensor = InfluxSensor(hass, influx_conf, query)
  File "/usr/src/homeassistant/homeassistant/components/influxdb/sensor.py", line 124, in __init__
    influx.query("SHOW SERIES LIMIT 1;")
  File "/usr/local/lib/python3.7/site-packages/influxdb/client.py", line 416, in query
    expected_response_code=expected_response_code
  File "/usr/local/lib/python3.7/site-packages/influxdb/client.py", line 267, in request
    timeout=self._timeout
  File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/adapters.py", line 516, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='192.168.2.89', port=8086): Max retries exceeded with url: /query?q=SHOW+SERIES+LIMIT+1%3B&db=home_assistant (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f8f769e3350>: Failed to establish a new connection: [Errno 111] Connection refused'))