Skip to content
Get started

PCF8574 I/O Expander

The PCF8574 component allows you to use PCF8574 or PCF8575 I/O expanders (datasheet, SparkFun) in ESPHome. It uses I²C Bus for communication.

Once configured, you can use any of the 8 pins (PCF8574) or 16 pins (PCF8575) as pins for your projects. Within ESPHome they emulate a real internal GPIO pin and can therefore be used with many of ESPHome’s components such as the GPIO binary sensor or GPIO switch.

Any option accepting a Pin Schema can theoretically be used, but some more complicated components that do communication through this I/O expander will not work.

PCF8574 I/O Expander.
# Example configuration entry
pcf8574:
- id: 'pcf8574_hub'
address: 0x21
pcf8575: false
# Individual outputs
switch:
- platform: gpio
name: "PCF8574 Pin #0"
pin:
pcf8574: pcf8574_hub
# Use pin number 0
number: 0
# One of INPUT or OUTPUT
mode:
output: true
inverted: false
  • id (Required, ID): The id to use for this PCF8574 component.

  • address (Optional, int): The I²C address of the driver. Defaults to 0x21.

  • pcf8575 (Optional, boolean): Whether this is a 16-pin PCF8575. Defaults to false.

  • reset (Optional, boolean): Reset the port to HIGH (released) during startup. Defaults to true. Set to false to preserve the powered expander’s output states across MCU reboots, subject to the limitations below.

  • interrupt_pin (Optional, Pin Schema): The pin connected to the INT output of the PCF8574/PCF8575. When configured, the component becomes interrupt-driven instead of polling — it only reads the chip when a pin actually changes state, significantly reducing I²C bus traffic and CPU usage. The INT pin is active-low and open-drain, so an external or internal pull-up resistor is required. Must be an internal GPIO pin (not another expander pin).

NOTE

If you use PCF8575, pin numbers are from 0 to 15, not 0 to 7 and 10 to 17 as datasheet states!

  • pcf8574 (Required, ID): The id of the PCF8574 component of the pin. Instead of an id, an address: can be given to select the hub by its I²C address; see Selecting an I2C Expander by Address.

  • number (Required, int): The pin number.

  • inverted (Optional, boolean): If all read and written values should be treated as inverted. Defaults to false.

  • mode (Optional, string): A pin mode to set for the pin at. One of INPUT or OUTPUT.

With reset: false, both PCF8574 and PCF8575 read the existing pin levels during setup without writing to the port. Later writes use those observed levels for other outputs, including unconfigured pins. Reads return pin levels, not the stored output latch values.

  • Keep the expander powered while the MCU reboots. If the expander also loses power, its pins start HIGH when power returns; their previous states are lost.
  • You can use outputs alone or a mixture of inputs and outputs. Declare all connected input pins with mode: INPUT. Undeclared pins are treated as outputs: an undeclared pin read LOW at startup is driven LOW on the first port write, even if the external circuit later releases it. Keep the same input/output assignments across reboots.
  • Output states can only be preserved if connected circuits do not override them. For example, an output set HIGH but pulled LOW by another circuit during startup will be remembered as LOW and driven LOW on the first port write.

NOTE

Components using these pins still write their own startup state. A GPIO Switch writes the state chosen by its restore_mode during setup, so use RESTORE_DEFAULT_OFF or RESTORE_DEFAULT_ON to bring back the saved state. A GPIO Output turns off during setup.