Saltar al contenido principal

Integración domótica pigpio (Raspberry Pi GPIO), gratuita y de código abierto

Integración pigpio (Raspberry Pi GPIO) para Gladys Assistant

GPIO of a Raspberry Pi through pigpiod: inputs as triggers, outputs and PWM.

info

La documentación de esta integración la escribe su autor y, por ahora, solo está disponible en inglés.

External integration for Gladys Assistant (5.1.0 or later): the GPIO pins of a Raspberry Pi on your local network, through the pigpiod service and its documented socket interface (TCP port 8888), without any account. Unofficial, not affiliated with the pigpio project nor with Raspberry Pi Ltd. It was never tested with a real device: it was written from the official pigpio documentation and tested against a fake pigpiod.

What it does​

  • Inputs: each listed GPIO becomes a binary sensor (1 = high level). Its changes reach Gladys at once (pigpiod notifications) and can start scenes. Inputs are only read: the integration writes neither their mode nor their pull.
  • On/off outputs: switches (a light, a fan).
  • PWM outputs: dimmers from 0 to 100 % (duty cycle, at the frequency and range set in pigpiod).
  • Pulse outputs (gate, garage door): a "pulse" button (output active for the chosen length, then turned off by the integration), an "off" button and the state of the output. Never a switch: a scene "turn everything on" cannot reach them.
  • Every GPIO is also read again at the chosen interval (30 s by default).

Safety​

  • pigpiod has no password: anyone who reaches its port can drive the GPIO. Keep it on your local network, never exposed to the Internet, and limit it to the address of Gladys (pigpiod option -n <address>). The pigpiod option -x also limits the GPIO that may be changed.
  • A GPIO you never listed is never written, not even to turn it off. An off still owed from before (a pulse cut by a restart) goes out even if you removed that GPIO from the lists since. It follows the configuration as it is now: a GPIO now listed as an input is no longer written (that off is dropped), an output gets the off level of its current "active low" setting. At start, before the configuration is read, it goes as it was kept. Before writing an off, the integration reads the mode of the GPIO: in ALT mode (UART, I2C, SPI...) the off is dropped without writing anything (the log and the status say so, /data is updated); in input mode it is dropped without writing only when the GPIO is no longer in the outputs list (a configured output back to input after a Pi restart gets its off level); if the mode reading fails, the off is written anyway.
  • Outputs are off by default: while "Allow the outputs" is unchecked, turning on, PWM and pulses are refused and nothing is sent. The option is read again right before sending.
  • Before every "on", the integration reads the hardware revision of the Pi again on the same connection: if another Raspberry Pi answers at the address, nothing is sent. It also reads the mode of the GPIO: an "on" is never sent to a GPIO held by a function of the system (UART 14/15, I2C 2/3, SPI 7 to 11 when these functions are enabled on the Pi: ALT mode).
  • Off (switch to 0, PWM to 0, "off" button, end of a pulse) depends neither on the option, nor on the identity, nor on a reading, nor even on the configuration (the address and the active-low outputs are also kept in the device, used while the saved address is empty or invalid). It is refused only when the GPIO is no longer listed with that role (in the configuration, else in the device), when the device is unknown or when the value is invalid. It goes on its own connection, is read back, tried again within 250 ms, then kept (in memory and in /data) and sent again (1 s, 2 s, 5 s, 10 s, 30 s, then every minute) until the read back confirms it, as well as at every reading and at every start, before the configuration is even read. A newer "on" of the same GPIO, once sent, replaces it. When an "on" that left just before got no answer, its connection is cut at once (reset) and the confirmed off is read again 5 s, 20 s then 60 s later, and written again if the output came back on. An off owed to an old address (changed since) is still sent every minute until confirmed, and counted in the status.
  • A pulse writes its off in /data before leaving: if it could not be written, nothing is sent. A restart during a pulse sends the off at the next start. A pulse is refused when the output is already active or when an off of that GPIO is still waiting for its confirmation.
  • When the integration stops, every pulse under way is turned off (2 s at most).
  • Many relay boards are active low: list those outputs in "Active-low outputs", their off is then the high level.

Preparing the Raspberry Pi​

  1. Install pigpio and enable the pigpiod service (pigpio package of Raspberry Pi OS).
  2. Limit it to Gladys: for example pigpiod -n 192.168.1.10 (the address of Gladys) in the service command.
  3. Give the Pi a fixed address (DHCP reservation): the address is its identity in Gladys.
  4. Set the pull of the inputs in /boot/firmware/config.txt (for example gpio=17=ip,pu).

The Raspberry Pi 5 is not supported by pigpio.

Configuration​

FieldRole
Raspberry Pi addressIP address or name; :port only if pigpiod does not listen on 8888
InputsBCM numbers (2 to 27) separated by commas
Reading interval5 to 3600 s (30 by default)
Allow the outputsunchecked by default
On/off, pulse, PWM outputsBCM numbers; a GPIO has one role only
Active-low outputsoutputs that are on at the low level
Pulse length100 to 10000 ms (500 by default)

Save, run a Discovery and add the device. The "Test the connection" button reads the Pi again (at most once every 5 s). After changing the GPIO lists, run a Discovery again and save the device again.

Limits​

  • One Raspberry Pi per installation of the integration.
  • Notifications for GPIO 0 to 31 only (every one of the header); a bouncing sensor is published at most every 250 ms per GPIO, its last level always included.

Parámetros de configuración​

Estos son los parámetros que pigpio (Raspberry Pi GPIO) te pide en su pantalla de configuración en Gladys.

ParámetroTipoObligatorioDescripción
Raspberry Pi with pigpiodsectionNoThe integration talks to the pigpiod service of a Raspberry Pi on your local network (TCP port 8888), without any account. pigpiod has no password: anyone who reaches its port can drive the GPIO, so keep it on your local network and limit it to the Gladys address (pigpiod option -n). The Raspberry Pi 5 is not supported by pigpio. Give the Pi a fixed address: the address is its identity in Gladys. GPIO are given by their BCM number (2 to 27); a GPIO you do not list is never written.
Raspberry Pi addressstringSíIP address or host name; add ":port" only if pigpiod does not listen on 8888.
Inputs (BCM numbers)stringNoGPIO read as inputs, separated by commas: their changes reach Gladys at once and can start scenes. They are only read: set their pull-up or pull-down on the Pi (config.txt).
Reading interval (s)numberNoEvery GPIO is also read at this interval, in seconds (5 to 3600), in case a notification was lost.
OutputssectionNoAn output may drive a relay, a pump, a gate. Nothing is ever written to a GPIO you never listed below, and nothing but "off" is written while the option "Allow the outputs" is unchecked. A gate or a garage door goes in "Pulse outputs": a push button, never an on/off switch, so a scene "turn everything on" never opens it.
Allow the outputsbooleanNoUnchecked: turning on, PWM and pulses are refused; turning off stays possible.
On/off outputs (BCM numbers)stringNoGPIO shown as switches (a light, a fan). Never a gate: use the pulse outputs.
Pulse outputs (BCM numbers)stringNoGPIO with a "pulse" button (active for the pulse length, then off) and an "off" button: a gate, a garage door.
PWM outputs (BCM numbers)stringNoGPIO shown as dimmers, 0 to 100 % duty cycle (pigpiod frequency and range).
Active-low outputsstringNoOutputs that are on when the GPIO is low (many relay boards): their off is the high level.
Pulse length (ms)numberNoHow long a pulse keeps the output active, in milliseconds (100 to 10000).
Language of the namesselectNoLanguage of the device and feature names shown by Discovery.

Cómo instalar pigpio (Raspberry Pi GPIO) en Gladys​

  1. En Gladys, abre Integraciones: pigpio (Raspberry Pi GPIO) aparece en el catálogo junto a las integraciones nativas, con una insignia de comunidad.
  2. Haz clic en Instalar. Gladys descarga la imagen Docker (ghcr.io/lm1lc3n7/gladys-pigpio:0.1.1), la ejecuta en un entorno aislado del núcleo y genera la interfaz de la integración (dispositivos, descubrimiento y configuración).
  3. Abre la pantalla de Configuración de la integración, rellena los parámetros y guarda.
  4. También puedes instalarla directamente desde la URL de su repositorio: https://github.com/LM1LC3N7/gladys-pigpio.

pigpio (Raspberry Pi GPIO) requiere Gladys >=5.1.0. El catálogo de Gladys se actualiza cada hora, así que una nueva versión está disponible como máximo una hora después de publicarse.

¿Todavía no usas Gladys? Es gratuito y de código abierto: sigue la guía de instalación para empezar.

Sobre las integraciones externas​

pigpio (Raspberry Pi GPIO) es una integración externa: una integración comunitaria empaquetada como contenedor Docker y publicada en GitHub. Gladys la instala con un clic y la ejecuta en un entorno aislado del núcleo. La publica y mantiene LM1LC3N7, no el equipo principal de Gladys.

Suscríbete a la newsletter de Gladys Assistant

Unos pocos correos al mes sobre nuevas versiones y novedades del proyecto. Enviados por Pierre-Gilles Leymarie, fundador del proyecto. Puedes darte de baja cuando quieras 🙂