Hi there,
I’ve noticed that the latests updates started giving error when Home Assistant is trying to get data from REST switch. My main suspect is the the version 0.60 (and 0.59) because I have not done any changes to anything else.
Questions:
- Do you guys have idea if rest switch implementation has changed is 0.5x or later HA?
- Is there something that needs to be added or changed to get rest switch working as earlier?
- Are there some new limitations added to rest switch in HA?
- Is there a way to create switch to HA that can be triggered via HA’s REST API but it does not need to call back to external URL to “double check” the state like the REST switch does? Is there any option to disable the check for HA REST switch?
- Is there way to poll I2C bus from HA to set states of sensors?
The problem:
When Home Assistant gives the error related to the rest switch, the switch is not created to the HA front end and I cannot trigger it with UI either. Basically the whole switch is gone, so I cannot trigger e.g. lights that were working fine before the update. It seems that always 9 pcs of REST switches are failing the call and thus disappear from the UI. They are not always the same (It seems switches change if I restart HA process).
I have the following setup:
-
Home Assistant has 48 REST sensors that are updated via Home Assistant’s native REST API at http://localhost:8123/api/states/… by custom Python script.
-
Home Assistant has 48 REST switches that are triggered by automation depending on the REST sensor state. As they are REST switches, they call API after the state has been altered by trigger, so I have 2nd REST API with the custom Python script (below).
-
I have custom Python script that is watching the state of the 48 sensors via I2C bus and will call Home Assistant rest sensor API if it detects changes. This keeps the state of the I2C busses and also provides 2nd REST API that HA can call. This script has not been changed when I started getting errors. Reason for this custom script is that I have not found way to poll I2C bus from HA.
Edit: I checked from top that the Python script is using about 6-7% CPU and 1,6% of Memory in Raspberry Pi 3.
Error that I’m getting in home-assistant.log the following:
2017-12-31 10:22:49 ERROR (MainThread) [homeassistant.components.switch.rest] Error while fetch data.
On my Python script I’m getting error:
Dec 31 10:22:54 raspberrypi python3[1807]: [2017-12-31 10:22:54 +0200] [1807] [INFO] KeepAlive Timeout. Closing connection.
Full HA error
2017-12-31 10:30:33 ERROR (MainThread) [homeassistant.components.switch.rest] Error while fetch data.
Traceback (most recent call last):
File “/srv/homeassistant/lib/python3.6/site-packages/aiohttp/connector.py”, line 796, in _wrap_create_connection
return (yield from self._loop.create_connection(*args, **kwargs))
File “uvloop/loop.pyx”, line 1733, in create_connection
File “uvloop/loop.pyx”, line 1712, in uvloop.loop.Loop.create_connection
File “/usr/local/lib/python3.6/asyncio/futures.py”, line 332, in iter
yield self # This tells Task to wait for completion.
File “/usr/local/lib/python3.6/asyncio/tasks.py”, line 250, in _wakeup
future.result()
File “/usr/local/lib/python3.6/asyncio/futures.py”, line 245, in result
raise self._exception
ConnectionRefusedError: [Errno 111] Connection refused
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “/srv/homeassistant/lib/python3.6/site-packages/aiohttp/connector.py”, line 796, in _wrap_create_connection
return (yield from self._loop.create_connection(*args, **kwargs))
File “uvloop/loop.pyx”, line 1733, in create_connection
File “uvloop/loop.pyx”, line 1712, in uvloop.loop.Loop.create_connection
File “/usr/local/lib/python3.6/asyncio/futures.py”, line 332, in iter
yield self # This tells Task to wait for completion.
File “/usr/local/lib/python3.6/asyncio/tasks.py”, line 250, in _wakeup
future.result()
File “/usr/local/lib/python3.6/asyncio/futures.py”, line 245, in result
raise self._exception
ConnectionRefusedError: [Errno 111] Connection refused
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File “/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/switch/rest.py”, line 164, in async_update
yield from self.get_device_state(self.hass)
File “/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/switch/rest.py”, line 174, in get_device_state
req = yield from websession.get(self._resource, auth=self._auth)
File “/srv/homeassistant/lib/python3.6/site-packages/aiohttp/helpers.py”, line 99, in iter
ret = yield from self._coro
File “/srv/homeassistant/lib/python3.6/site-packages/aiohttp/client.py”, line 267, in _request
conn = yield from self._connector.connect(req)
File “/srv/homeassistant/lib/python3.6/site-packages/aiohttp/connector.py”, line 402, in connect
proto = yield from self._create_connection(req)
File “/srv/homeassistant/lib/python3.6/site-packages/aiohttp/connector.py”, line 748, in _create_connection
_, proto = yield from self._create_direct_connection(req)
File “/srv/homeassistant/lib/python3.6/site-packages/aiohttp/connector.py”, line 859, in _create_direct_connection
raise last_exc
File “/srv/homeassistant/lib/python3.6/site-packages/aiohttp/connector.py”, line 831, in _create_direct_connection
req=req, client_error=client_error)
File “/srv/homeassistant/lib/python3.6/site-packages/aiohttp/connector.py”, line 803, in _wrap_create_connection
raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host localhost:8000 ssl:False [Connection refused]