Knowledge Base

The AB Electronics UK Knowledge Base provides support solutions, tutorials and troubleshooting guides.

IO Pi Switch Output Custom Component

Created 09/08/2017 | Using the IO Pi Switch Output Custom Component

We have created a custom component to use the IO Pi and IO Pi Zero with Home Assistant smart home software.

Download from GitHub

Software interfaces for Home Assistant from home-assistant.io to use with IO Pi Plus/Zero MCP23017 based Raspbery Pi expansion boards from www.abelectronics.co.uk using binary sensor and switch components.

This has been tested on a Raspberry Pi using manual installation of Home Assistance from https://home-assistant.io/docs/installation/raspberry-pi/ and with Hass.io installation from home-assistant.io/hassio

Provides:

  • Functionality to read and write to IO pins on IO Pi Plus and IO Pi Zero boards which use the MCP23017 I2C port expander.

Installation for IO Pi Plus and Zero

Copy /custom_components folder to the root of the Home Assistant config directory

The iopiinputssensor.py file located in the binary_sensor directory allows you to read from the 16 IO ports on the MCP23017 IC using the Binary Sensor platform in Home Assistant.

The iopiswitch.py file located in the switch directory allows you to write to the 16 IO ports on the MCP23017 IC using the switch platform in Home Assistant.

Switch / Output Mode Configuration

The following code uses the iopiswitch.py switch file to write to the chip on address 0x21.

The IOPi output pin status can be configured with the following code either in configuration.yaml or switches.ymal.

- platform: iopiswitch
  i2c_address: 0x21
  name: IOSwitches
  pins:
    1:
      name: Pin 1
      initial: True
    2:
      name: Pin 2
      initial: True
    3:
      name: Pin 3
    4:
      name: Pin 4 
    5:
      name: Pin 5
    6:
      name: Pin 6
    7:
      name: Pin 7
    8:
      name: Pin 8
    9:
      name: Pin 9
    10:
      name: Pin 10
    11:
      name: Pin 11
    12:
      name: Pin 12 
    13:
      name: Pin 13
    14:
      name: Pin 14
    15:
      name: Pin 15
    16:
      name: Pin 16

Configuration variables:

  • name (Required): Name that will be used in the sensor.
  • i2c_address (Required): The I2C address of the MCP23017 IC.
  • pins (Required): This section will contain a list of the pins you wish to use as outputs.
    • pin number (Required): The pin number that corresponds with the pin number on the IOPi Plus/Zero
    • name (Required): Name that will be used in the switch.
    • initial (Optional): The initial value for this port. Defaults to False

Example groups.yaml file

The following code can be used in the groups.yaml file to display data using the IO Pi Plus/Zero inputs and outputs.

# REPLACE HOME PAGE
  default_view:
    name: Home
    view: yes
    icon: mdi:home
    entities:
      - group.iopioutputs
      - group.iopiinputs    
  
  mainview:
    view: no
    name: Overview
    
  iopiinputs:
    view: no
    name: IOPi Inputs
    control: hidden
    entities:
      - binary_sensor.iopi_in1
      - binary_sensor.iopi_in2
      - binary_sensor.iopi_in3
      - binary_sensor.iopi_in4
      - binary_sensor.iopi_in5
      - binary_sensor.iopi_in6
      - binary_sensor.iopi_in7
      - binary_sensor.iopi_in8
      - binary_sensor.iopi_in9
      - binary_sensor.iopi_in10
      - binary_sensor.iopi_in11
      - binary_sensor.iopi_in12
      - binary_sensor.iopi_in13
      - binary_sensor.iopi_in14
      - binary_sensor.iopi_in15
      - binary_sensor.iopi_in16
         
  iopioutputs:
    view: no
    name: IOPi Outputs
    control: hidden
    entities:
      - switch.pin_1
      - switch.pin_2
      - switch.pin_3
      - switch.pin_4
      - switch.pin_5
      - switch.pin_6
      - switch.pin_7
      - switch.pin_8
      - switch.pin_9
      - switch.pin_10
      - switch.pin_11
      - switch.pin_12
      - switch.pin_13
      - switch.pin_14
      - switch.pin_15
      - switch.pin_16