
* Integrate the work done by @jdeneef back to this repo (#281) * initial setup, config_flow only * initial setup, reading config * renamed to ha_gpiod * added gpiod_config * switches working * added invert_logic for switch * initial setup for binarysensor added * button working in thread * added some timeouts to avoid resource busy * button working! inc state * doc update * version nr updated in manifest * fix for wrong state, tested invert_logic for binary_sensor * updated docs and unique_id * simplified tables * found nothread solution, test a bit more first * working without thread * removed thread, simpeler solution * added cover .. * added cover to docs * default fix relay_time and doc cleanups * doc cleanups * moved listener to hub, no longer blocking * cleanups * fixed comma in manifest file, and added version n manifest * fix for hass.async_create_task for hass 2024.5 * Update README.md * add rpi5 info to readme * added gpiodevice discovery since rpi5 uses different gpiodevice from rpi3 and 4 * readme update * readme typo, license update to mit * fix for cover, updates from gpiod instead of calculated, readme updates * update manifest version * add stop_cover for cover, readme update gpiod no longer mandatory * add github actions hacs validation * limit hacs validation to on push * remove brands check for github action * updated readme, 1.0 version * add hassfest check * sorted manifest * follow blueprint a bit more * update github actions * feat: add bias and drive mode options to switches * updated code adding feature from askz * add bias/drive to cover * gpiod bias and drive added * code cleanup more inline with gpiod, with some deprecations in the future * highlight deprecated * update todo * fixed drive info in readme * readme fix * update readme * retrofit * cover update not init is_closing/opening * readme update * remove changelog * update readme refer to bias for switch * markdown cleanups, markdown render * fix for port ranges, back to int * rename README-DEV * Update README.md * alternative solution removing the loop waiting for gpio events * cleanup of config_validations, eases backward compatibility in configs * added changelog to readme * changelog creation from git * removed changelog, added generation howto to README-DEV, generate from there * read initial status from gpio status (check bias on errors) * typo in changelog git line * added possible bias issue in readme * Add persistentcy support for switches * Make the persistent example more relevant * removed previous persistence via gpiod * updated sensor reading at startup * updated readme for persistence over reboots * fix to remove state error * Align old configuration for sensor and switch * Fix manifest * Align cover configuration with old format * Fix readme attribution * Fix break in cover * Manifest fix * remove commented code * fixed version in manifest * Revert not needed files * Revert LICENSE * CR comments * Another CR fix * More CR comments * Fix doc CR comments * Update custom_components/rpi_gpio/hub.py * Update custom_components/rpi_gpio/hub.py * CR comments * Fix break caused by removing manufacturer. * Update custom_components/rpi_gpio/hub.py * Fixed last CR comments --------- Co-authored-by: J de Neef <6884662+jdeneef@users.noreply.github.com> Co-authored-by: Maxime Saddok <saddok.ma@gmail.com> Co-authored-by: gwhiteCL <whitegc5@comcast.net> Co-authored-by: Shay Levy <levyshay1@gmail.com> * rename update to handle_event to make it less confusion with HA naming. * Fix cover break after my rename * Rename update to handle_event to make it less confusion with HA naming (#287) * rename update to handle_event to make it less confusion with HA naming. * Fix cover break after my rename * Merge from main (#296) * Bump pylint from 3.3.0 to 3.3.1 (#283) Bumps [pylint](https://github.com/pylint-dev/pylint) from 3.3.0 to 3.3.1. - [Release notes](https://github.com/pylint-dev/pylint/releases) - [Commits](https://github.com/pylint-dev/pylint/compare/v3.3.0...v3.3.1) --- updated-dependencies: - dependency-name: pylint dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump pre-commit from 3.8.0 to 4.0.0 (#288) Bumps [pre-commit](https://github.com/pre-commit/pre-commit) from 3.8.0 to 4.0.0. - [Release notes](https://github.com/pre-commit/pre-commit/releases) - [Changelog](https://github.com/pre-commit/pre-commit/blob/main/CHANGELOG.md) - [Commits](https://github.com/pre-commit/pre-commit/compare/v3.8.0...v4.0.0) --- updated-dependencies: - dependency-name: pre-commit dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump actions/checkout from 4.2.0 to 4.2.1 (#289) Bumps [actions/checkout](https://github.com/actions/checkout) from 4.2.0 to 4.2.1. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v4.2.0...v4.2.1) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump black from 24.8.0 to 24.10.0 (#290) Bumps [black](https://github.com/psf/black) from 24.8.0 to 24.10.0. - [Release notes](https://github.com/psf/black/releases) - [Changelog](https://github.com/psf/black/blob/main/CHANGES.md) - [Commits](https://github.com/psf/black/compare/24.8.0...24.10.0) --- updated-dependencies: - dependency-name: black dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump pre-commit from 4.0.0 to 4.0.1 (#291) Bumps [pre-commit](https://github.com/pre-commit/pre-commit) from 4.0.0 to 4.0.1. - [Release notes](https://github.com/pre-commit/pre-commit/releases) - [Changelog](https://github.com/pre-commit/pre-commit/blob/main/CHANGELOG.md) - [Commits](https://github.com/pre-commit/pre-commit/compare/v4.0.0...v4.0.1) --- updated-dependencies: - dependency-name: pre-commit dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump mypy from 1.11.2 to 1.12.0 (#292) Bumps [mypy](https://github.com/python/mypy) from 1.11.2 to 1.12.0. - [Changelog](https://github.com/python/mypy/blob/master/CHANGELOG.md) - [Commits](https://github.com/python/mypy/compare/v1.11.2...v1.12.0) --- updated-dependencies: - dependency-name: mypy dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump mypy from 1.12.0 to 1.12.1 (#295) Bumps [mypy](https://github.com/python/mypy) from 1.12.0 to 1.12.1. - [Changelog](https://github.com/python/mypy/blob/master/CHANGELOG.md) - [Commits](https://github.com/python/mypy/compare/v1.12.0...v1.12.1) --- updated-dependencies: - dependency-name: mypy dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Integrate the fix for cover (#297) * fix for cover * simpler cover fix, not based on cover state * Fix minor bug in the cover code * Refactor cover init --------- Co-authored-by: J de Neef <6884662+jdeneef@users.noreply.github.com> --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Tomer <57483589+tomer-w@users.noreply.github.com> Co-authored-by: J de Neef <6884662+jdeneef@users.noreply.github.com> Co-authored-by: Maxime Saddok <saddok.ma@gmail.com> Co-authored-by: gwhiteCL <whitegc5@comcast.net> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
11 KiB
Home Assistant Raspberry Pi GPIO custom integration
This is a spin-off from the original Home Assistant integration, which was removed in Home Assistant Core version 2022.6.
The rpi_gpio
integration supports the following platforms: Binary Sensor
, Cover
, Switch
rpi_gpio
is based on gpiod
in ha-gpio and ha_gpiod
in ha_gpiod
Installation
HACS
The recommend way to install rpi_gpio
is through HACS.
Manual installation
Copy the rpi_gpio
folder and all of its contents into your Home Assistant's custom_components
folder. This folder is usually inside your /config
folder. If you are running Hass.io, use SAMBA to copy the folder over. You may need to create the custom_components
folder and then copy the rpi_gpio
folder and all of its contents into it.
Usage
The gpiod
platform will be initialized using the path to the gpio chip. When path is not in the config /dev/gpiochip[0-5]
are tested for a gpiodevice having pinctrl
, in sequence [0,4,1,2,3,5]
. So with a raspberry pi you should be OK to leave the path empty.
Raspberry Pi | GPIO Device |
---|---|
RPi3, RPi4 | /dev/gpiochip0 |
RPi5 | /dev/gpiochip4 |
# setup gpiod chip; mostly not required
gpiod:
path: '/dev/gpiochip0'
Options
Key | Required | Default | Type | Description |
---|---|---|---|---|
gpiod |
only for path | - | - | gpiod platform config and initialization, only required when you need to specify a specific gpiodevice path (see path) |
path |
no | discovered | string | path to gpio device, if not set auto discovered |
Binary Sensor
The rpi_gpio
binary sensor platform allows you to read sensor values of the GPIOs of your Raspberry Pi.
Configuration
To use your Raspberry Pi's GPIO in your installation, add the following to your configuration.yaml
file:
# Basic configuration.yaml entry
binary_sensor:
- platform: rpi_gpio
sensors:
- port: 11
name: "PIR Office"
- port: 12
name: "PIR Bedroom"
# Full configuration.yaml entry
binary_sensor:
- platform: rpi_gpio
sensors:
- port: 11
name: "PIR Office"
unique_id: "pir_office_sensor_port_11"
bouncetime: 80
invert_logic: true
pull_mode: "DOWN"
- port: 12
name: "PIR Bedroom"
unique_id: "pir_bedroom_sensor_port_12"
Options
Key | Required | Default | Type | Description |
---|---|---|---|---|
sensors |
yes | list | List of sensor IO ports (BCM mode pin numbers) | |
name |
yes | string | The name for the binary sensor entity | |
port |
yes | integer | the GPIO port to be used | |
unique_id |
no | string | An ID that uniquely identifies the sensor. Set this to a unique value to allow customization through the UI | |
bouncetime |
no | 50 |
integer | The time in milliseconds for port debouncing |
invert_logic |
no | false (ACTIVE HIGH) |
boolean | If true , inverts the output logic to ACTIVE LOW |
pull_mode |
no | UP |
string | control bias setting of GPIO, used to define the electrical state of a GPIO line when not actively driven; UP set weak pull-up resistor on the line, ensuring that the line is pulled to a high level (3.3V or 5V) when not actively driven; DOWN sets weak pull-down resistor to pull to low level (0V), DISABLED remains floating, AS_IS not changed |
For more details about the GPIO layout, visit the Wikipedia article about the Raspberry Pi.
Cover
The rpi_gpio
cover platform allows you to use a Raspberry Pi to control your cover such as Garage doors.
It uses two pins on the Raspberry Pi.
- The
state_pin
will detect if the cover is closed, and - the
relay_pin
will trigger the cover to open or close.
Although you do not need Andrews Hilliday's software controller when you run Home Assistant, he has written clear instructions on how to hook your garage door and sensors up to your Raspberry Pi, which can be found here.
Configuration
To enable Raspberry Pi Covers in your installation, add the following to your configuration.yaml
file:
# Basic configuration.yaml entry
cover:
- platform: rpi_gpio
covers:
- relay_pin: 10
state_pin: 11
# Full configuration.yaml entry
cover:
- platform: rpi_gpio
relay_time: 0.2
invert_relay: false
state_pull_mode: "UP"
invert_state: true
covers:
- relay_pin: 10
state_pin: 11
name: "Left door"
unique_id: "left_door_cover_port_11"
- relay_pin: 12
state_pin: 13
name: "Right door"
unique_id: "right_door_cover_port_13"
Options
Key | Required | Default | Type | Description |
---|---|---|---|---|
relay_time |
no | 0.2 |
float | The time that the relay will be on for in seconds |
invert_relay |
no | false |
boolean | Invert the relay pin output so that it is active-high (True) |
state_pull_mode |
no | UP |
string | The direction the State pin is pulling. It can be UP or DOWN |
invert_state |
no | false |
boolean | Invert the value of the State pin so that 0 means closed |
covers |
yes | list | List of covers | |
relay_pin |
yes | integer | The pin of your Raspberry Pi where the relay is connected | |
state_pin |
yes | integer | The pin of your Raspberry Pi to retrieve the state | |
name |
no | string | The name for the cover entity | |
unique_id |
no | string | An ID that uniquely identifies the cover. Set this to a unique value to allow customization through the UI |
Remote Raspberry Pi Cover
If you don't have Home Assistant running on your Raspberry Pi and you want to use it as a remote cover instead, there is a project called GarageQTPi that will work remotely with the MQTT Cover Component. Follow the GitHub instructions to install and configure GarageQTPi and once configured follow the Home Assistant instructions to configure the MQTT Cover.
Switch
The rpi_gpio
switch platform allows you to control the GPIOs of your Raspberry Pi.
Configuration
To use your Raspberry Pi's GPIO in your installation, add the following to your configuration.yaml
file:
# Basic configuration.yaml entry
switch:
- platform: rpi_gpio
switches:
- port: 11
name: "Fan Office"
- port: 12
name: "Light Desk"
# Full configuration.yaml entry
switch:
- platform: rpi_gpio
switches:
- port: 11
name: "Fan Office"
unique_id: "fan_office_switch_port_11"
persistent: true
- port: 12
name: "Light Desk"
unique_id: "light_desk_switch_port_12"
invert_logic: true
Options
Key | Required | Default | Type | Description |
---|---|---|---|---|
switches |
yes | list | List of switch IO ports (BCM mode pin numbers) | |
name |
yes | string | The name for the switch entity | |
port |
yes | integer | the GPIO port to be used | |
unique_id |
no | string | An ID that uniquely identifies the switch. Set this to a unique value to allow customization through the UI, auto generated when not set manually in config | |
invert_logic |
no | false |
boolean | If true, inverts the output logic to ACTIVE LOW |
persistent |
no | false |
boolean | If true, the switch state will be persistent in HA and will be restored if HA restart / crash |
pull_mode |
no | AS_IS |
string | Type of internal pull resistor to use: UP - pull-up resistor, DOWN - pull-down resistor, AS-IS no change |
drive |
no | PUSH_PULL |
string | control drive configuration of the GPIO, determines how the line behaves when it is set to output mode; PUSH_PULL , GPIO line can both source and sink current, can actively drive the line to both high and low states. OPEN-DRAIN , GPPIO can only sink current (drive the line to low) and is otherwise left floating, and OPEN-SOURCE the reverse. |
persistent |
no | false |
boolean | If true, the switch state will be persistent in HA and will be restored if HA restart / crash. |
For more details about the GPIO layout, visit the Wikipedia article about the Raspberry Pi.
A common question is what does Port refer to, this number is the actual GPIO #, not the pin #. For example, if you have a relay connected to pin 11 its GPIO # is 17.
# Basic configuration.yaml entry
switch:
- platform: rpi_gpio
switches:
- port: 17
name: "Speaker Relay"
Reporting issues
Before reporting issues please enable debug logging as described here, check logs and report issue attaching the log file.