diff --git a/Home Assistant/addon/pi_somfy/CHANGELOG.md b/Home Assistant/addon/pi_somfy/CHANGELOG.md index 6f30f4b..7698788 100644 --- a/Home Assistant/addon/pi_somfy/CHANGELOG.md +++ b/Home Assistant/addon/pi_somfy/CHANGELOG.md @@ -1,6 +1,25 @@ # Changelog -## 3.0.0 +This add-on's version always matches the [Pi-Somfy](https://github.com/Nickduino/Pi-Somfy) +release it's built on, so each entry below is what's new in that release. + +## 3.2 + +- Fixed the add-on showing an incorrect version number, which could cause the add-on to fail + to install or update properly. +- Add support for a CC1101 RF receiver, so button presses on a physical Somfy remote are + tracked and stay in sync with the app and Home Assistant. +- Added an optional CC1101 transmitter as an alternative to the built-in one. +- Redesigned the schedule editor and the manual-operation remote control in the web UI. + +## 3.1 + +- Added native Home Assistant integration: Pi-Somfy shutters now show up as proper cover + entities in Home Assistant, with position control, instead of needing a separate setup. +- Added support for running on a Raspberry Pi 5, detected automatically. +- Made the optional MQTT integration easier to set up. + +## 3.0 - Initial release as Home Assistant add-on - Web UI with ingress and external port access diff --git a/Home Assistant/addon/pi_somfy/DOCS.md b/Home Assistant/addon/pi_somfy/DOCS.md index 4c33f1c..ee113cc 100644 --- a/Home Assistant/addon/pi_somfy/DOCS.md +++ b/Home Assistant/addon/pi_somfy/DOCS.md @@ -19,14 +19,15 @@ This add-on runs [Pi-Somfy](https://github.com/Nickduino/Pi-Somfy) directly on y ## Configuration -| Option | Default | Description | -|---------------|---------|---------------------------------------------------------------------------| -| `gpio_pin` | `4` | GPIO pin number for the 433.42 MHz transmitter | -| `rx_gpio_pin` | (none) | GPIO wired to a CC1101 receiver's data output. Leave blank to disable the physical-remote receiver entirely. | -| `spi_sck` | `21` | CC1101 bit-banged SPI clock GPIO (only used when `rx_gpio_pin` is set) | -| `spi_mosi` | `20` | CC1101 bit-banged SPI MOSI GPIO (only used when `rx_gpio_pin` is set) | -| `spi_miso` | `19` | CC1101 bit-banged SPI MISO GPIO (only used when `rx_gpio_pin` is set) | -| `spi_csn` | `16` | CC1101 bit-banged SPI chip-select GPIO (only used when `rx_gpio_pin` is set) | +| Option | Default | Description | +|------------------|-------------------------|---------------------------------------------------------------------------| +| `gpio_pin` | `4` | GPIO pin number for the 433.42 MHz transmitter | +| `rx_gpio_pin` | (none) | GPIO wired to a CC1101 receiver's data output. Leave blank to disable the physical-remote receiver entirely. | +| `spi_sck` | `21` | CC1101 bit-banged SPI clock GPIO (only used when `rx_gpio_pin` is set) | +| `spi_mosi` | `20` | CC1101 bit-banged SPI MOSI GPIO (only used when `rx_gpio_pin` is set) | +| `spi_miso` | `19` | CC1101 bit-banged SPI MISO GPIO (only used when `rx_gpio_pin` is set) | +| `spi_csn` | `16` | CC1101 bit-banged SPI chip-select GPIO (only used when `rx_gpio_pin` is set) | +| `enable_mqtt` | `false` | Enable the MQTT bridge, using the broker connected via the Supervisor (e.g. the Mosquitto add-on) | ### Physical remote receiver (optional) @@ -44,6 +45,20 @@ on another computer (it mounts as a normal FAT32 `boot`/`bootfs` drive), add `dtparam=spi=on` to the bottom of `config.txt`, then reinsert the card and power the Pi back on. +### MQTT (optional) + +Setting `enable_mqtt` enables the MQTT bridge alongside the web UI, publishing +Home Assistant MQTT auto-discovery for every shutter (cover entities with +live position and open/closing state) to whichever broker is connected via +the Supervisor — install and start the official Mosquitto broker add-on and +Pi-Somfy will find it automatically, no broker details to enter. Useful if +you want push-based updates instead of the custom integration's REST polling. +Leave `enable_mqtt` off to run without MQTT, exactly as before. + +If your broker is not running as a Home Assistant add-on, this toggle will not +find it. Run Pi-Somfy standalone with `-m` and set the broker details in +`operateShutters.conf` instead. + ## Web UI The add-on provides a web interface accessible in two ways: @@ -69,8 +84,8 @@ Shutter configuration and rolling codes are stored in `/data/operateShutters.con ## Notes -- This add-on runs Pi-Somfy with the web interface and scheduler only (no MQTT, no Alexa emulation) -- For MQTT or Alexa integration, run Pi-Somfy standalone on a dedicated Raspberry Pi +- This add-on runs Pi-Somfy with the web interface, scheduler, and (if `enable_mqtt` is set) MQTT — no Alexa emulation +- For Alexa integration, run Pi-Somfy standalone on a dedicated Raspberry Pi - Shutter position is estimated based on movement timing, but persists across restarts (saved to `/data/operateShutters.conf`'s `[ShutterPositions]` section as it changes) ## Support diff --git a/Home Assistant/addon/pi_somfy/Dockerfile b/Home Assistant/addon/pi_somfy/Dockerfile index 28e0c71..c6fd40e 100644 --- a/Home Assistant/addon/pi_somfy/Dockerfile +++ b/Home Assistant/addon/pi_somfy/Dockerfile @@ -40,12 +40,13 @@ RUN git clone --branch v${BUILD_VERSION} --depth 1 https://github.com/Nickduino/ WORKDIR /somfy -# Install Python dependencies (excluding paho-mqtt — not needed without -m flag) +# Install Python dependencies RUN pip3 install --no-cache-dir --break-system-packages \ ephem \ configparser \ Flask \ - requests + requests \ + paho-mqtt # Copy run script COPY run.sh / diff --git a/Home Assistant/addon/pi_somfy/build.sh b/Home Assistant/addon/pi_somfy/build.sh index 933d142..43f5ae9 100644 --- a/Home Assistant/addon/pi_somfy/build.sh +++ b/Home Assistant/addon/pi_somfy/build.sh @@ -12,11 +12,15 @@ set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" -echo "Building Pi-Somfy add-on locally..." +# Read from config.yaml rather than hardcoding, so this can't drift out of +# sync with the tag Supervisor actually builds against. +BUILD_VERSION="$(grep -m1 '^version:' "${SCRIPT_DIR}/config.yaml" | sed -E 's/version: *"?([^"]+)"?/\1/')" + +echo "Building Pi-Somfy add-on locally (version ${BUILD_VERSION})..." docker build \ --build-arg BUILD_FROM=ghcr.io/home-assistant/aarch64-base:latest \ - --build-arg BUILD_VERSION=3.0.0 \ - -t local/pi_somfy:3.0.0 \ + --build-arg BUILD_VERSION="${BUILD_VERSION}" \ + -t "local/pi_somfy:${BUILD_VERSION}" \ "${SCRIPT_DIR}" -echo "Done. Run with: docker run --rm -it local/pi_somfy:3.0.0" +echo "Done. Run with: docker run --rm -it local/pi_somfy:${BUILD_VERSION}" diff --git a/Home Assistant/addon/pi_somfy/config.yaml b/Home Assistant/addon/pi_somfy/config.yaml index b08c084..9f7d3b4 100644 --- a/Home Assistant/addon/pi_somfy/config.yaml +++ b/Home Assistant/addon/pi_somfy/config.yaml @@ -1,6 +1,6 @@ name: "Pi-Somfy" description: "Operate Somfy RTS shutters via 433.42 MHz RF on Raspberry Pi GPIO" -version: "3.0.0" +version: "3.2" slug: "pi_somfy" url: "https://github.com/Nickduino/Pi-Somfy" arch: @@ -31,12 +31,15 @@ ports: ports_description: 80/tcp: "Pi-Somfy Web UI" watchdog: "http://[HOST]:[PORT:80]/cmd/getConfig" +services: + - mqtt:want options: gpio_pin: 4 spi_sck: 21 spi_mosi: 20 spi_miso: 19 spi_csn: 16 + enable_mqtt: false schema: gpio_pin: "int(0,27)" rx_gpio_pin: "int(0,27)?" @@ -44,5 +47,6 @@ schema: spi_mosi: "int(0,27)" spi_miso: "int(0,27)" spi_csn: "int(0,27)" + enable_mqtt: "bool" discovery: - pi_somfy diff --git a/Home Assistant/addon/pi_somfy/run.sh b/Home Assistant/addon/pi_somfy/run.sh index 6f4e03b..a607b6e 100644 --- a/Home Assistant/addon/pi_somfy/run.sh +++ b/Home Assistant/addon/pi_somfy/run.sh @@ -44,6 +44,44 @@ else bashio::log.info "RX receiver disabled (set rx_gpio_pin in add-on options to enable)" fi +# MQTT (Home Assistant auto-discovery via a broker) is optional — pulled +# from the Supervisor's mqtt service (e.g. the Mosquitto add-on) rather +# than asking the user to re-enter broker details already known to HA. +MQTT_ARGS="" +if bashio::config.true 'enable_mqtt'; then + if bashio::services.available 'mqtt'; then + MQTT_HOST=$(bashio::services mqtt "host") + MQTT_PORT=$(bashio::services mqtt "port") + MQTT_USER=$(bashio::services mqtt "username") + MQTT_PASSWORD=$(bashio::services mqtt "password") + bashio::log.info "MQTT enabled: broker ${MQTT_HOST}:${MQTT_PORT}" + + if ! grep -q "^\[MQTT\]" "${CONFIG_FILE}"; then + printf '\n[MQTT]\n' >> "${CONFIG_FILE}" + fi + + for entry in "MQTT_Server:${MQTT_HOST}" \ + "MQTT_Port:${MQTT_PORT}" \ + "MQTT_User:${MQTT_USER}" \ + "MQTT_Password:${MQTT_PASSWORD}" \ + "MQTT_ClientID:somfy-mqtt-bridge" \ + "EnableDiscovery:true"; do + key="${entry%%:*}" + value="${entry#*:}" + if grep -q "^${key}" "${CONFIG_FILE}"; then + sed -i "s|^${key}.*|${key} = ${value}|" "${CONFIG_FILE}" + else + sed -i "/^\[MQTT\]/a ${key} = ${value}" "${CONFIG_FILE}" + fi + done + MQTT_ARGS="-m" + else + bashio::log.warning "enable_mqtt is on but no MQTT broker add-on was found — MQTT disabled" + fi +else + bashio::log.info "MQTT disabled (set enable_mqtt in add-on options to enable)" +fi + # Ensure log location exists and is writable sed -i "s|^LogLocation.*|LogLocation = /data/|" "${CONFIG_FILE}" @@ -74,9 +112,10 @@ if [ "${IS_PI5}" = true ]; then bashio::log.info "Pi 5 detected — using lgpio (no pigpiod needed)" else bashio::log.info "Starting pigpiod..." - # Deliberately not passing -m (disable alerts): -m silently prevents - # pi.callback() from ever delivering edge notifications, which the RX - # receiver needs when rx_gpio_pin is set. + # Deliberately not passing pigpiod's own -m flag (disable alerts) here — + # unrelated to operateShutters.py's -m/MQTT_ARGS above. pigpiod's -m + # silently prevents pi.callback() from ever delivering edge + # notifications, which the RX receiver needs when rx_gpio_pin is set. pigpiod -l sleep 1 @@ -88,7 +127,7 @@ else bashio::log.info "pigpiod started successfully" fi -# Launch Pi-Somfy with web interface only (no MQTT, no Alexa) +# Launch Pi-Somfy with the web interface (no Alexa), MQTT if configured above cd /somfy bashio::log.info "Starting Pi-Somfy..." -exec python3 operateShutters.py -c "${CONFIG_FILE}" -a +exec python3 operateShutters.py -c "${CONFIG_FILE}" -a ${MQTT_ARGS} diff --git a/Home Assistant/addon/pi_somfy/translations/en.yaml b/Home Assistant/addon/pi_somfy/translations/en.yaml index a758f4f..68bf966 100644 --- a/Home Assistant/addon/pi_somfy/translations/en.yaml +++ b/Home Assistant/addon/pi_somfy/translations/en.yaml @@ -1,7 +1,29 @@ --- configuration: gpio_pin: - name: GPIO Pin + name: Transmitter GPIO pin + description: GPIO pin the 433.42 MHz transmitter is wired to. + rx_gpio_pin: + name: Receiver GPIO pin (optional) description: >- - The GPIO pin number where the 433.42 MHz RF transmitter is connected. - Default is GPIO 4. + GPIO wired to a CC1101 receiver's data output, for tracking physical + remote button presses. Leave blank to disable the receiver. + spi_sck: + name: CC1101 SPI clock GPIO + description: Only used when a receiver GPIO pin is set. + spi_mosi: + name: CC1101 SPI MOSI GPIO + description: Only used when a receiver GPIO pin is set. + spi_miso: + name: CC1101 SPI MISO GPIO + description: Only used when a receiver GPIO pin is set. + spi_csn: + name: CC1101 SPI chip-select GPIO + description: Only used when a receiver GPIO pin is set. + enable_mqtt: + name: Enable MQTT + description: >- + Publish shutters to Home Assistant using MQTT auto-discovery, so cover + entities appear automatically with push-based updates instead of REST + polling. Requires the Mosquitto broker add-on to be installed and + running. Leave off to use the web UI and custom integration only.