Knowledge Base

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

IO Pi Input Custom Component

Created 09/08/2017 | Using the IO Pi Input 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.

Binary Sensor / Input Mode Configuration

The following code uses the iopiinputssensor.py binary sensor file to read the inputs on chip address 0x20.

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

- platform: iopiinputssensor
  name: IOPiInputs
  i2c_address: 0x20
  pullup: 1
  scan_interval: 1

Configuration variables:

  • name (Required): Name that will be used in the sensor.
  • i2c_address (Required): The I2C address of the MCP23017 IC.
  • pullup (Required): Setting the pullup value to 1 will enable the internal pullup resistors in the MCP23017 IC. A value of 0 (zero) will disable the internal pullup resistors.

The pin status is held in attributes which are named pin1 to pin16 and can be added to the Home Assistance user interface with the following template which needs to be added to configuration.yaml or binary_sensors.ymal.

- platform: template
  sensors:
    iopi_in1:
      value_template: '{{states.binary_sensor.iopi.attributes.pin1 == 1}}'
      friendly_name: 'IO input 1'
    iopi_in2:
      value_template: '{{states.binary_sensor.iopi.attributes.pin2 == 1}}'
      friendly_name: 'IO input 2'  
    iopi_in3:
      value_template: '{{states.binary_sensor.iopi.attributes.pin3 == 1}}'
      friendly_name: 'IO input 3'
    iopi_in4:
      value_template: '{{states.binary_sensor.iopi.attributes.pin4 == 1}}'
      friendly_name: 'IO input 4'
    iopi_in5:
      value_template: '{{states.binary_sensor.iopi.attributes.pin5 == 1}}'
      friendly_name: 'IO input 5'
    iopi_in6:
      value_template: '{{states.binary_sensor.iopi.attributes.pin6 == 1}}'
      friendly_name: 'IO input 6' 
    iopi_in7:
      value_template: '{{states.binary_sensor.iopi.attributes.pin7 == 1}}'
      friendly_name: 'IO input 7'  
    iopi_in8:
      value_template: '{{states.binary_sensor.iopi.attributes.pin8 == 1}}'
      friendly_name: 'IO input 8' 
    iopi_in9:
      value_template: '{{states.binary_sensor.iopi.attributes.pin9 == 1}}'
      friendly_name: 'IO input 9'
    iopi_in10:
      value_template: '{{states.binary_sensor.iopi.attributes.pin10 == 1}}'
      friendly_name: 'IO input 10'  
    iopi_in11:
      value_template: '{{states.binary_sensor.iopi.attributes.pin11 == 1}}'
      friendly_name: 'IO input 11'
    iopi_in12:
      value_template: '{{states.binary_sensor.iopi.attributes.pin12 == 1}}'
      friendly_name: 'IO input 12'
    iopi_in13:
      value_template: '{{states.binary_sensor.iopi.attributes.pin13 == 1}}'
      friendly_name: 'IO input 13'
    iopi_in14:
      value_template: '{{states.binary_sensor.iopi.attributes.pin14 == 1}}'
      friendly_name: 'IO input 14' 
    iopi_in15:
      value_template: '{{states.binary_sensor.iopi.attributes.pin15 == 1}}'
      friendly_name: 'IO input 15'  
    iopi_in16:
      value_template: '{{states.binary_sensor.iopi.attributes.pin16 == 1}}'
      friendly_name: 'IO input 16'