Knowledge Base

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

Knowledge Base

Using I2C Devices with Home Assistant on the Raspberry Pi

Install Home Assistant on your Raspberry Pi and enable I2C

This tutorial will install the Home Assistant Operation System on your Raspberry Pi and enable I2C to use the ADC Pi, IO Pi expansion boards, and other I2C devices with Home Assistant.

First, we must set up a microSD card with the Home Assistant Operation System.

You will need the following items:

  • Raspberry Pi 4 or Raspberry Pi 3
  • Power Supply for the Raspberry Pi
  • Micro SD Card. Ideally, a 32 GB card or larger.
  • SD Card Reader
  • Ethernet Cable

Optional IO Pi Plus to add additional IO channels or an ADC Pi to add analogue inputs to Home Assistant.

Installing the Home Assistant Operating System

How to install the Home Assistant Operating system onto your Raspberry Pi using Raspberry Pi Imager on Windows, MacOS or Ubuntu

Wiring the OS image to your SD card

  1. Download and install the Raspberry Pi Imager on your computer as described under https://www.raspberrypi.com/software/.
  2. Insert the SD card into your Micro SD Card reader and connect it to your computer.
  3. Open the Raspberry Pi Imager software and select your Raspberry Pi device.
  4. Select the operating system:
    • Select Choose OS
    • Select Other specific-purpose OS > Home assistants and home automation > Home Assistant.
    • Choose the Home Assistant OS that matches your Raspberry Pi, i.e., RPi 3 or RPi 4.
  5. Click Choose Storage and select your SD card.
  6. Write the image to your SD card by clicking the “Next” button and wait for the file to be transferred to your card.
  7. When the transfer has been completed, close the Raspberry Pi Imager software.

How to Enable I2C

Enabling I2C in the Home Assistant Operating system differs from existing methods for enabling the I2C bus on a Raspberry Pi on other operating systems.

To use I2C devices, you need to enable I2C for the Home Assistant Operating System and then set up your I2C devices, such as sensors or IO expanders.

You need to access the boot partition on your SD card with the Home Assistant Operating System installed on it. If Home Assistant is running, shut down your Home Assistant system, unplug the SD card, insert the card into your card reader and connect it to your computer.

The card will mount as a drive or file system called hassos-boot.

You must create two new folders and add and edit config files to enable I2C.

In the root of the hassos-boot partition, add a new folder called CONFIG.

In the CONFIG folder, add another new folder called modules.

Inside the modules folder, add a text file called rpi-i2c.conf with the following content:

i2c-dev

In the root of the hassos-boot partition, edit the file called config.txt and add two lines to it at the end of the file:

dtparam=i2c_vc=on
dtparam=i2c_arm=on

Start your updated Home Assistant Operation System

Unmount or disconnect the card reader, insert the SD card into your Raspberry Pi and reconnect the power to turn it on.

If this is the first boot of your new Home Assistant Operation System, you will be taken through the onboarding process where you set up user accounts, location and other preferences.

In a web browser on your desktop system, within a few minutes, you will be able to reach your new Home Assistant at homeassistant.local:8123 or the IP address of your Raspberry Pi and port 8123

During the first boot it can take over 20 minutes for the operating system to load and configure.

When the operating system starts, the hassos-config.service will automatically process the new rpi-i2c.conf configuration.

Another reboot might be necessary to ensure the imported rpi-i2c.conf is present at boot time.

I2C will now be enabled and available for connected sensors or expansion boards.


Was this article helpful? Yes No

Please tell us how we can improve this article:

Submit
Created 11/11/2023 | Last Updated: 11/11/2023

Related Articles

Using 1 Wire with Home Assistant and the Raspberry Pi OS
Integrating 1-Wire devices into your home automation system
Using I2C Devices with Home Assistant on the Raspberry Pi
Install Home Assistant on your Raspberry Pi and enable I2C
Using the IO Pi with Home Assistant on the Raspberry Pi
Adding up to 128 IO channels to Home Assistant on your Raspberry Pi
Using the ADC Pi with Home Assistant on the Raspberry Pi
Adding up to 32 analogue channels to Home Assistant on your Raspberry Pi
Using the ADC Differential Pi with Home Assistant on the Raspberry Pi
Adding up to 32 analogue channels to Home Assistant on your Raspberry Pi