MCP23017 I/O Expander

Hi all

Fresh install, I enable the I2C interface in the Hass.io configuration but with no luck

Home Assistant 0.105.2

Host system

|Hostname|hassio|
|System|HassOS 3.9|
|Deployment|production|

System Health

arch armv7l
dev false
docker true
hassio true
os_name Linux
python_version 3.7.6
timezone Europe/Bucharest
version 0.105.2
virtualenv false

configuration.yaml

Configure a default setup of Home Assistant (frontend, api, etc)

default_config:

Uncomment this if you are using SSL/TLS, running in Docker container, etc.

http:

base_url: example.duckdns.org:8123

Text to speech

tts:

  • platform: google_translate

binary_sensor:

  • platform: mcp23017
    i2c_address: 0x20
    pins:
    0: Test 1
    1: Test 2
    switch:
  • platform: mcp23017
    i2c_address: 0x21
    pins:
    11: Test switch 1
    12: Test switch 2

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml


home-assistant.log

2020-02-10 00:46:08 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
File “/usr/local/lib/python3.7/site-packages/aiohttp/web_protocol.py”, line 418, in start
resp = await task
File “/usr/local/lib/python3.7/site-packages/aiohttp/web_app.py”, line 458, in _handle
resp = await handler(request)
File “/usr/local/lib/python3.7/site-packages/aiohttp/web_middlewares.py”, line 119, in impl
return await handler(request)
File “/usr/src/homeassistant/homeassistant/components/http/real_ip.py”, line 39, in real_ip_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 135, in auth_middleware
return await handler(request)
File “/usr/src/homeassistant/homeassistant/components/http/view.py”, line 123, 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 784, 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 275, in get_platform
f"{self.pkg_path}.{platform_name}"
File “/usr/local/lib/python3.7/importlib/init.py”, line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File “”, line 1006, in _gcd_import
File “”, line 983, in _find_and_load
File “”, line 967, in _find_and_load_unlocked
File “”, line 677, in _load_unlocked
File “”, line 728, in exec_module
File “”, line 219, in _call_with_frames_removed
File “/usr/src/homeassistant/homeassistant/components/mcp23017/binary_sensor.py”, line 5, in
import board # pylint: disable=import-error
File “/usr/local/lib/python3.7/site-packages/board.py”, line 37, in
if board_id == ap_board.FEATHER_HUZZAH:
AttributeError: module ‘adafruit_platformdetect.board’ has no attribute ‘FEATHER_HUZZAH’


What do you have the expander connected to ?

Is connected to relays and reed sensors

Sorry, I meant at the other end.
To what device is the extender extending ? RPi, nodeMCU ?

The same here. It looks like the “board” library has changed after the upgrade. I have my “custom component” and I use “import board” in it. And I have identical errors… I had to make downgrade to 0.104.3. Now everything works beautifully…

My device is connected directly to RPi3.

It’s a IO Pi Plus (https://www.abelectronics.co.uk/p/54/io-pi-plus) , 32 channel digital expansion board designed for use on the Raspberry Pi and connected directly to RPi3.
Works verry well until last update.

Same here with Rpi 4 ;

starting version 3.2.8
[23:56:51] INFO: Don’t worry, this temporary installation is not overwriting your current one.
[23:56:51] INFO: Installing Home Assistant: latest…
[23:56:51] INFO: Please be patient, this might take a few minutes…
WARNING: You are using pip version 19.2.2, however version 20.0.2 is available.
You should consider upgrading via the ‘pip install --upgrade pip’ command.
[23:59:32] INFO: Installed Home Assistant 0.105.2
[23:59:32] INFO: Making a copy of your configuration for checking…
[00:00:40] INFO: Checking your configuration against this version…
[00:03:12] ERROR: The configuration check did not pass!
[00:03:12] ERROR: See the output below for more details.
INFO:homeassistant.util.package:Attempting install of colorlog==4.1.0
Testing configuration at /tmp/config
INFO:homeassistant.util.package:Attempting install of hbmqtt==0.9.5
INFO:homeassistant.util.package:Attempting install of paho-mqtt==1.5.0
INFO:homeassistant.util.package:Attempting install of aiohttp_cors==0.7.0
INFO:homeassistant.util.package:Attempting install of mutagen==1.43.0
INFO:homeassistant.util.package:Attempting install of gTTS-token==1.1.3
INFO:homeassistant.util.package:Attempting install of pyRFXtrx==0.25
INFO:homeassistant.util.package:Attempting install of RPi.GPIO==0.7.0
INFO:homeassistant.util.package:Attempting install of adafruit-blinka==1.2.1
INFO:homeassistant.util.package:Attempting install of adafruit-circuitpython-mcp230xx==1.1.2
ERROR:homeassistant.scripts.check_config:BURB
Traceback (most recent call last):
File “/usr/local/lib/python3.7/site-packages/homeassistant/scripts/check_config.py”, line 204, in check
async_check_ha_config_file(hass)
File “/usr/local/lib/python3.7/asyncio/base_events.py”, line 579, in run_until_complete
return future.result()
File “/usr/local/lib/python3.7/site-packages/homeassistant/helpers/check_config.py”, line 164, in async_check_ha_config_file
platform = p_integration.get_platform(domain)
File “/usr/local/lib/python3.7/site-packages/homeassistant/loader.py”, line 275, in get_platform
f"{self.pkg_path}.{platform_name}"
File “/usr/local/lib/python3.7/importlib/init.py”, line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File “”, line 1006, in _gcd_import
File “”, line 983, in _find_and_load
File “”, line 967, in _find_and_load_unlocked
File “”, line 677, in _load_unlocked
File “”, line 728, in exec_module
File “”, line 219, in _call_with_frames_removed
File “/usr/local/lib/python3.7/site-packages/homeassistant/components/mcp23017/switch.py”, line 5, in
import board # pylint: disable=import-error
File “/usr/local/lib/python3.7/site-packages/board.py”, line 37, in
if board_id == ap_board.FEATHER_HUZZAH:
AttributeError: module ‘adafruit_platformdetect.board’ has no attribute ‘FEATHER_HUZZAH’
Fatal error while loading config: module ‘adafruit_platformdetect.board’ has no attribute ‘FEATHER_HUZZAH’
Failed config
General Errors:
- module ‘adafruit_platformdetect.board’ has no attribute ‘FEATHER_HUZZAH’

I am having similar issues.
Here is the information.

  • Docker on Raspian. Hassio inside the docker. Version 0.105.3

I have activated the i2c bus via raspy-config.
I have tested that it is being recognized via i2cdetect on the raspi.
Any help would be appreciated.

Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/aiohttp/web_protocol.py", line 418, in start
    resp = await task
  File "/usr/local/lib/python3.7/site-packages/aiohttp/web_app.py", line 458, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/web_middlewares.py", line 119, in impl
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/real_ip.py", line 39, in real_ip_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 135, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 123, 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 784, 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 275, in get_platform
    f"{self.pkg_path}.{platform_name}"
  File "/usr/local/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/usr/src/homeassistant/homeassistant/components/mcp23017/binary_sensor.py", line 5, in <module>
    import board  # pylint: disable=import-error
  File "/usr/local/lib/python3.7/site-packages/board.py", line 37, in <module>
    if board_id == ap_board.FEATHER_HUZZAH:
AttributeError: module 'adafruit_platformdetect.board' has no attribute 'FEATHER_HUZZAH'

A little more searching revealed that your board library seems to have been changed with this latest update, resulting in some erroneous behavior. Apparently version 0.104.3 worked. Please update ASAP.

Luckily I am trying to implement this integration on a test bed system right now, but looking to install in a clients house converting an old wired system to a smart home.

Should we let someone know that? This is obviously a small bug of new version. So I assume it’s easy to fix :slight_smile:

Yup extreamly frustrating indeed! Took me forever, but I finally got the mcp23017 platform to work on a pi4 under HASSIOv104 OSv3.8 as outlined here: I2c not working on the Pi4 But I’m starting to think now though, that only worked because I restored my snapshot from an old pi3 which maybe somehow carriered over the library files?

Because Yeah, now on OSv3.10 IOv105.3 I get so many python errors by simply adding the words “platform: mcp23017” to my configuration.yaml that it doesn’t even boot. Does’t matter if I flash and start from scratch, try upgrading, etc, always the same:

File "/usr/src/homeassistant/homeassistant/components/mcp23017/switch.py", line 5, in <module>
    import board  # pylint: disable=import-error
  File "/usr/local/lib/python3.7/site-packages/board.py", line 37, in <module>
    if board_id == ap_board.FEATHER_HUZZAH:
AttributeError: module 'adafruit_platformdetect.board' has no attribute 'FEATHER_HUZZAH'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/setup.py", line 170, in _async_setup_component
    hass, processed_config
  File "/usr/src/homeassistant/homeassistant/components/binary_sensor/__init__.py", line 127, in async_setup
    await component.async_setup(config)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 126, in async_setup
    await asyncio.wait(tasks)
  File "/usr/local/lib/python3.7/asyncio/tasks.py", line 389, in wait
    return await _wait(fs, timeout, return_when, loop)
  File "/usr/local/lib/python3.7/asyncio/tasks.py", line 482, in _wait
    await waiter
concurrent.futures._base.CancelledError
2020-02-13 21:43:26 ERROR (MainThread) [homeassistant.components.binary_sensor] Error while setting up rpi_gpio platform for binary_sensor
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/asyncio/runners.py", line 43, in run
    return loop.run_until_complete(main)
  File "/usr/local/lib/python3.7/asyncio/base_events.py", line 583, in run_until_complete
    return future.result()
  File "/usr/src/homeassistant/homeassistant/__main__.py", line 249, in setup_and_run_hass
    safe_mode=args.safe_mode,
  File "/usr/src/homeassistant/homeassistant/bootstrap.py", line 89, in async_setup_hass
    await async_from_config_dict(config_dict, hass)
  File "/usr/src/homeassistant/homeassistant/bootstrap.py", line 132, in async_from_config_dict
    await _async_set_up_integrations(hass, config)
  File "/usr/src/homeassistant/homeassistant/bootstrap.py", line 377, in _async_set_up_integrations
    *(async_setup_component(hass, domain, config) for domain in domains_to_load)
  File "/usr/src/homeassistant/homeassistant/setup.py", line 49, in async_setup_component
    return await task  # type: ignore
  File "/usr/src/homeassistant/homeassistant/setup.py", line 145, in _async_setup_component
    hass, config, integration
  File "/usr/src/homeassistant/homeassistant/config.py", line 739, in async_process_component_config
    platform = p_integration.get_platform(domain)
  File "/usr/src/homeassistant/homeassistant/loader.py", line 275, in get_platform
    f"{self.pkg_path}.{platform_name}"
  File "/usr/local/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/usr/src/homeassistant/homeassistant/components/mcp23017/switch.py", line 5, in <module>
    import board  # pylint: disable=import-error
  File "/usr/local/lib/python3.7/site-packages/board.py", line 37, in <module>
    if board_id == ap_board.FEATHER_HUZZAH:
AttributeError: module 'adafruit_platformdetect.board' has no attribute 'FEATHER_HUZZAH'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 159, 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 435, in wait_for
    await waiter
concurrent.futures._base.CancelledError

Ok, just confirmed it, I was able to get my mcp23017 chips working again on the PI4. Had to downgrade to version 104.3 because yes, its true, no matter what version of the HASSIO *.gz image you download, upon first boot, it installs the latest version. And the library files in 105 dont appear to support this chipset combination.

Here is the entire procedure:

  1. flashed “hassos_rpi4-64-3.8.img.gz” to a 32gig card using “balenaEtcher-Portable-1.5.59.exe”
  2. activated i2c using this procedure:
    https://www.home-assistant.io/hassio/enable_i2c/
  3. i2c fails on a pi4, so had to employ the Hack procedure I outlined here:
    I2c not working on the Pi4
  4. install the SSH server from the add-on store and set a standard password
  5. putty in and use this command:
    ha core update --version 0.104.3
  6. ONLY NOW can you place “- platform: mcp23017” into your configuration.yaml

WOW this is a lot of hacking! So is this hows its gonna be? No more i2c or mcp23017 support from here going forward?

Updating the requirements to the latest adrafuit-blinka library (3.9.0) fixes this issue. So, it is a simple fix. I’ll do a PR either tomorrow or Saturday.

Good I am trying to integrate the mcp23017 to expand the GPIOs of the Raspberry Pi 4 and in the configuration I get an error “object”
I’ve been looking for solutions online and I haven’t seen anything. I have checked the GPIOs voltage and I have tension, as I have read to verify that they were activated.

Is there any solution?

Thank you so much!

I don’t have a Pi 4, so I am not familiar with its i2c issues (I might be getting one in the near future to test it out).
So far, I created a Pull Request (Update MCP23017) that fixes this issue:

AttributeError: module 'adafruit_platformdetect.board' has no attribute...

@TLC: What error are you getting?

When I enter the code in the configuration and I am going to restart the HA I get an object message and it doesn’t tell me anything else.

I am sorry but I don’t know what “an object message is”. Can you spot a related message in /var/log/syslog?

I have tried as the partner installed above version 0.104.3 says and it works perfectly. With the last one, the configuration does not accept the code

I tried to use MCP23017 switch, but configuration.yaml gives error on version 0.105.2 also. I have test environment that doesn’t have I2C board connected.

Any ideas should MCP23017 switch give error 500 when checking configuration when switch cannot access I2C bus or there is nothing connected?

Just to make sure: Is the below correctly implemented to the configuration.yaml?

I had the following setup in configuration that gave error 500 when checking configuration:

switch:
  - platform: mcp23017
    i2c_address: 0x20
    pins:
      11: Fan Office

Also noticed that this component was changed few hours ago. Any ideas when this might be relased, if it fixes the problem with MCP23017?

Hi @Jardiamj from what I can see your PR was merged into HA but I’m still having issues connecting an MCP23017 to my RPi4 running HA.

On first boot the MCP23017 is set up and the binary sensors show, but of the system is restarted or even rebooted the MCP23017 component shows errors in the logs.

Any help you can provide would be appreciated.

It working fine with mine RPi4. I have the following configuration file for switches:

  - platform: mcp23017
    i2c_address: 0x20
    pins:
      01: ligh1
      02: loight2

and so on. Having 8 GPIOs as switches connected to 8 rely board.
Also have one binary sensor.
All is working fine.

The challenge was to enable I2C from USB as the folder names has to start with “/” and normal Windows cannot do it.