Hi I’m trying to get HA to extend some push rods to push an object a specific distance away from a wall upon detecting an Insteon keypad press. It appears the Time of Flight and rpi_gpio components are a good match.
Let’s say the distance to extend to is 2 meters. The pseudo code will be something like:
- Detect a specific keypad press with Insteon.
- Use rpi_gpio to switch on a relay to extend the push rods as long as it’s less than 2 meters.
- Use Time of Flight to measure distance away from wall.
- As we approach 2 meters use rpi_gpio to control another relay to modulate power applied to the pushrods to control speed. It operates in 24VDC so I’d have to do some PWM here. For example 10% duty cycle means 2.4mm/s for a pushrod that operates at 24mms/s under 100% duty cycle.
- Stop pushrods once reaching or having having reached or exceeded 2 meters.
- Use rpi_gpio to control the relays to retract / extend the pushrods until distance is +/- 2 millimeters.
To be honest I’m not sure if HA is the best platform to implement something like this but I need to be able to integrate with Insteon so I guess there’s no choice. Comments? Yes I could have used a servo motor based push rod but they are significantly more expensive.
Anyway my configuration.yml snippet looks like this.
sensor:
- platform: tof
name: Left Pushrod Distance
i2c_address: 0x29
xshut: 17
- platform: tof
name: Right Pushrod Distance
i2c_address: 0x30
xshut: 18
switch:
- platform: rpi_gpio
invert_logic: false
ports:
17: Left TOF Sensor Reset
18: Right TOF Sensor Reset
26: Pushrod On/Off Relay
20: Pushrod Directional Relay 1
21: Pushrod Directional Relay 2
And I’m seeing the following in the Configurations -> Logs section. Any ideas? I did install HA in a docker on Raspberry Pi OS and am not using Hassio.
Errors for the rpi_gpio integration
Logger: aiohttp.server
Source: components/rpi_gpio/__init__.py:2
First occurred: 9:32:12 PM (1 occurrences)
Last logged: 9:32:12 PM
Error handling request
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/aiohttp/web_protocol.py", line 422, in _handle_request
resp = await self._request_handler(request)
File "/usr/local/lib/python3.8/site-packages/aiohttp/web_app.py", line 499, in _handle
resp = await handler(request)
File "/usr/local/lib/python3.8/site-packages/aiohttp/web_middlewares.py", line 118, in impl
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 18, in request_context_middleware
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 72, in ban_middleware
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 127, in auth_middleware
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 129, in handle
result = await result
File "/usr/src/homeassistant/homeassistant/components/config/core.py", line 29, in post
errors = await async_check_ha_config_file(request.app["hass"])
File "/usr/src/homeassistant/homeassistant/config.py", line 874, in async_check_ha_config_file
res = await check_config.async_check_ha_config_file(hass)
File "/usr/src/homeassistant/homeassistant/helpers/check_config.py", line 164, in async_check_ha_config_file
platform = p_integration.get_platform(domain)
File "/usr/src/homeassistant/homeassistant/loader.py", line 424, in get_platform
cache[full_name] = self._import_platform(platform_name)
File "/usr/src/homeassistant/homeassistant/loader.py", line 429, in _import_platform
return importlib.import_module(f"{self.pkg_path}.{platform_name}")
File "/usr/local/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/usr/src/homeassistant/homeassistant/components/rpi_gpio/__init__.py", line 2, in <module>
from RPi import GPIO # pylint: disable=import-error
File "/usr/local/lib/python3.8/site-packages/RPi/GPIO/__init__.py", line 23, in <module>
from RPi._GPIO import *
RuntimeError: This module can only be run on a Raspberry Pi!
Errors for the TOF Integration
2020-12-03 12:46:26 ERROR (SyncWorker_1) [homeassistant.util.package] Unable to install package VL53L1X2==0.1.5: ERROR: Command errored out with exit status 1:
command: /usr/local/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-4eo_8y8r/vl53l1x2/setup.py'"'"'; __file__='"'"'/tmp/pip-install-4eo_8y8r/vl53l1x2/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-eix25r1i
cwd: /tmp/pip-install-4eo_8y8r/vl53l1x2/
Complete output (16 lines):
running bdist_wheel
running build
running build_py
creating build
creating build/lib.linux-armv7l-3.8
copying python/VL53L1X2.py -> build/lib.linux-armv7l-3.8
running build_ext
building 'vl53l1x_python' extension
creating build/temp.linux-armv7l-3.8
creating build/temp.linux-armv7l-3.8/api
creating build/temp.linux-armv7l-3.8/api/core
creating build/temp.linux-armv7l-3.8/api/platform
creating build/temp.linux-armv7l-3.8/python_lib
gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fno-semantic-interposition -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free -ljemalloc -DTHREAD_STACK_SIZE=0x100000 -fPIC -I. -Iapi/core -Iapi/platform -I/usr/local/include/python3.8 -c api/core/vl53l1_api_calibration.c -o build/temp.linux-armv7l-3.8/api/core/vl53l1_api_calibration.o -std=c99
unable to execute 'gcc': No such file or directory
error: command 'gcc' failed with exit status 1
----------------------------------------
ERROR: Failed building wheel for VL53L1X2
ERROR: Command errored out with exit status 1:
command: /usr/local/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-4eo_8y8r/vl53l1x2/setup.py'"'"'; __file__='"'"'/tmp/pip-install-4eo_8y8r/vl53l1x2/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-h6utfa5u/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/include/python3.8/VL53L1X2
cwd: /tmp/pip-install-4eo_8y8r/vl53l1x2/
Complete output (16 lines):
running install
running build
running build_py
creating build
creating build/lib.linux-armv7l-3.8
copying python/VL53L1X2.py -> build/lib.linux-armv7l-3.8
running build_ext
building 'vl53l1x_python' extension
creating build/temp.linux-armv7l-3.8
creating build/temp.linux-armv7l-3.8/api
creating build/temp.linux-armv7l-3.8/api/core
creating build/temp.linux-armv7l-3.8/api/platform
creating build/temp.linux-armv7l-3.8/python_lib
gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fno-semantic-interposition -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free -ljemalloc -DTHREAD_STACK_SIZE=0x100000 -fPIC -I. -Iapi/core -Iapi/platform -I/usr/local/include/python3.8 -c api/core/vl53l1_api_calibration.c -o build/temp.linux-armv7l-3.8/api/core/vl53l1_api_calibration.o -std=c99
unable to execute 'gcc': No such file or directory
error: command 'gcc' failed with exit status 1
----------------------------------------
ERROR: Command errored out with exit status 1: /usr/local/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-4eo_8y8r/vl53l1x2/setup.py'"'"'; __file__='"'"'/tmp/pip-install-4eo_8y8r/vl53l1x2/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-h6utfa5u/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/include/python3.8/VL53L1X2 Check the logs for full command output.
WARNING: You are using pip version 20.2.4; however, version 20.3.1 is available.
You should consider upgrading via the '/usr/local/bin/python3 -m pip install --upgrade pip' command.