diff --git a/Home Assistant/addon/pi_somfy/CHANGELOG.md b/Home Assistant/addon/pi_somfy/CHANGELOG.md deleted file mode 100644 index 6f30f4b..0000000 --- a/Home Assistant/addon/pi_somfy/CHANGELOG.md +++ /dev/null @@ -1,10 +0,0 @@ -# Changelog - -## 3.0.0 - -- Initial release as Home Assistant add-on -- Web UI with ingress and external port access -- Auto-discovery for Pi-Somfy custom integration -- Debian-based container with pigpiod for GPIO access -- Persistent configuration across updates -- Watchdog health monitoring diff --git a/Home Assistant/addon/pi_somfy/translations/en.yaml b/Home Assistant/addon/pi_somfy/translations/en.yaml deleted file mode 100644 index a758f4f..0000000 --- a/Home Assistant/addon/pi_somfy/translations/en.yaml +++ /dev/null @@ -1,7 +0,0 @@ ---- -configuration: - gpio_pin: - name: GPIO Pin - description: >- - The GPIO pin number where the 433.42 MHz RF transmitter is connected. - Default is GPIO 4. diff --git a/README.md b/README.md index d3f2248..8254fd0 100644 --- a/README.md +++ b/README.md @@ -403,19 +403,29 @@ Pi-Somfy can integrate directly with [Home Assistant](https://www.home-assistant 1. In Home Assistant, go to **HACS → Integrations**. 2. Click the three-dot menu (top right) and select **Custom repositories**. -3. Add `https://github.com/Nickduino/Pi-Somfy` with category **Integration** and click **Add**. +3. Add `https://github.com/Nickduino/Pi-Somfy` with category **Integration** and click **Add** — or use the button below: + + [![Open your Home Assistant instance and open a repository inside the Home Assistant Community Store.](https://my.home-assistant.io/badges/hacs_repository.svg)](https://my.home-assistant.io/redirect/hacs_repository/?owner=Nickduino&repository=Pi-Somfy&category=integration) 4. Search for "Pi-Somfy" in HACS, click **Download**, and restart Home Assistant. 5. Go to **Settings → Devices & Services → Add Integration**, search for "Pi-Somfy", and enter the IP address and port of your Pi-Somfy instance (default port: 80). #### Option B: Manual install -1. Copy the `Home Assistant/custom_components/pi_somfy` folder into your Home Assistant `config/custom_components/` directory. +1. Copy the `custom_components/pi_somfy` folder into your Home Assistant `config/custom_components/` directory. 2. Restart Home Assistant. 3. Go to **Settings → Devices & Services → Add Integration**, search for "Pi-Somfy", and enter the IP address and port of your Pi-Somfy instance (default port: 80). ### Installing the Add-on -1. Copy the `Home Assistant/addon/pi_somfy` folder to your Home Assistant `addons/pi_somfy` directory. +#### Option A: Add-on repository (recommended) + +1. Go to **Settings → Add-ons → Add-on Store**, click the three-dot menu (top right) and select **Repositories**. +2. Add `https://github.com/Nickduino/Pi-Somfy` and click **Add**. +3. Find "Pi-Somfy" under the new repository and install it. + +#### Option B: Manual install + +1. Copy the `somfy-ha-addon` folder to your Home Assistant `addons/somfy-ha-addon` directory. 2. Go to **Settings → Add-ons → Add-on Store** and click the refresh button. 3. Find "Pi-Somfy" under "Local add-ons" and install it. 4. Configure the GPIO pin in the add-on settings (default: GPIO 4). diff --git a/Home Assistant/custom_components/pi_somfy/__init__.py b/custom_components/pi_somfy/__init__.py similarity index 100% rename from Home Assistant/custom_components/pi_somfy/__init__.py rename to custom_components/pi_somfy/__init__.py diff --git a/Home Assistant/custom_components/pi_somfy/brand/icon.png b/custom_components/pi_somfy/brand/icon.png similarity index 100% rename from Home Assistant/custom_components/pi_somfy/brand/icon.png rename to custom_components/pi_somfy/brand/icon.png diff --git a/Home Assistant/custom_components/pi_somfy/brand/icon@2x.png b/custom_components/pi_somfy/brand/icon@2x.png similarity index 100% rename from Home Assistant/custom_components/pi_somfy/brand/icon@2x.png rename to custom_components/pi_somfy/brand/icon@2x.png diff --git a/Home Assistant/custom_components/pi_somfy/brand/logo.png b/custom_components/pi_somfy/brand/logo.png similarity index 100% rename from Home Assistant/custom_components/pi_somfy/brand/logo.png rename to custom_components/pi_somfy/brand/logo.png diff --git a/Home Assistant/custom_components/pi_somfy/config_flow.py b/custom_components/pi_somfy/config_flow.py similarity index 100% rename from Home Assistant/custom_components/pi_somfy/config_flow.py rename to custom_components/pi_somfy/config_flow.py diff --git a/Home Assistant/custom_components/pi_somfy/const.py b/custom_components/pi_somfy/const.py similarity index 100% rename from Home Assistant/custom_components/pi_somfy/const.py rename to custom_components/pi_somfy/const.py diff --git a/Home Assistant/custom_components/pi_somfy/coordinator.py b/custom_components/pi_somfy/coordinator.py similarity index 100% rename from Home Assistant/custom_components/pi_somfy/coordinator.py rename to custom_components/pi_somfy/coordinator.py diff --git a/Home Assistant/custom_components/pi_somfy/cover.py b/custom_components/pi_somfy/cover.py similarity index 100% rename from Home Assistant/custom_components/pi_somfy/cover.py rename to custom_components/pi_somfy/cover.py diff --git a/Home Assistant/custom_components/pi_somfy/diagnostics.py b/custom_components/pi_somfy/diagnostics.py similarity index 100% rename from Home Assistant/custom_components/pi_somfy/diagnostics.py rename to custom_components/pi_somfy/diagnostics.py diff --git a/Home Assistant/custom_components/pi_somfy/hacs.json b/custom_components/pi_somfy/hacs.json similarity index 100% rename from Home Assistant/custom_components/pi_somfy/hacs.json rename to custom_components/pi_somfy/hacs.json diff --git a/Home Assistant/custom_components/pi_somfy/icon.png b/custom_components/pi_somfy/icon.png similarity index 100% rename from Home Assistant/custom_components/pi_somfy/icon.png rename to custom_components/pi_somfy/icon.png diff --git a/Home Assistant/custom_components/pi_somfy/logo.png b/custom_components/pi_somfy/logo.png similarity index 100% rename from Home Assistant/custom_components/pi_somfy/logo.png rename to custom_components/pi_somfy/logo.png diff --git a/Home Assistant/custom_components/pi_somfy/manifest.json b/custom_components/pi_somfy/manifest.json similarity index 100% rename from Home Assistant/custom_components/pi_somfy/manifest.json rename to custom_components/pi_somfy/manifest.json diff --git a/Home Assistant/custom_components/pi_somfy/services.yaml b/custom_components/pi_somfy/services.yaml similarity index 100% rename from Home Assistant/custom_components/pi_somfy/services.yaml rename to custom_components/pi_somfy/services.yaml diff --git a/Home Assistant/custom_components/pi_somfy/strings.json b/custom_components/pi_somfy/strings.json similarity index 100% rename from Home Assistant/custom_components/pi_somfy/strings.json rename to custom_components/pi_somfy/strings.json diff --git a/Home Assistant/custom_components/pi_somfy/translations/en.json b/custom_components/pi_somfy/translations/en.json similarity index 100% rename from Home Assistant/custom_components/pi_somfy/translations/en.json rename to custom_components/pi_somfy/translations/en.json diff --git a/repository.yaml b/repository.yaml new file mode 100644 index 0000000..d7a1e45 --- /dev/null +++ b/repository.yaml @@ -0,0 +1,3 @@ +name: "Pi-Somfy" +url: "https://github.com/Nickduino/Pi-Somfy" +maintainer: "Nickduino" diff --git a/somfy-ha-addon/CHANGELOG.md b/somfy-ha-addon/CHANGELOG.md new file mode 100644 index 0000000..7698788 --- /dev/null +++ b/somfy-ha-addon/CHANGELOG.md @@ -0,0 +1,29 @@ +# Changelog + +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 +- Auto-discovery for Pi-Somfy custom integration +- Debian-based container with pigpiod for GPIO access +- Persistent configuration across updates +- Watchdog health monitoring diff --git a/Home Assistant/addon/pi_somfy/DOCS.md b/somfy-ha-addon/DOCS.md similarity index 57% rename from Home Assistant/addon/pi_somfy/DOCS.md rename to somfy-ha-addon/DOCS.md index 4c33f1c..ee113cc 100644 --- a/Home Assistant/addon/pi_somfy/DOCS.md +++ b/somfy-ha-addon/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/somfy-ha-addon/Dockerfile similarity index 94% rename from Home Assistant/addon/pi_somfy/Dockerfile rename to somfy-ha-addon/Dockerfile index 28e0c71..c6fd40e 100644 --- a/Home Assistant/addon/pi_somfy/Dockerfile +++ b/somfy-ha-addon/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/somfy-ha-addon/build.sh similarity index 52% rename from Home Assistant/addon/pi_somfy/build.sh rename to somfy-ha-addon/build.sh index 933d142..43f5ae9 100644 --- a/Home Assistant/addon/pi_somfy/build.sh +++ b/somfy-ha-addon/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/build.yaml b/somfy-ha-addon/build.yaml similarity index 100% rename from Home Assistant/addon/pi_somfy/build.yaml rename to somfy-ha-addon/build.yaml diff --git a/Home Assistant/addon/pi_somfy/config.yaml b/somfy-ha-addon/config.yaml similarity index 91% rename from Home Assistant/addon/pi_somfy/config.yaml rename to somfy-ha-addon/config.yaml index b08c084..9f7d3b4 100644 --- a/Home Assistant/addon/pi_somfy/config.yaml +++ b/somfy-ha-addon/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/icon.png b/somfy-ha-addon/icon.png similarity index 100% rename from Home Assistant/addon/pi_somfy/icon.png rename to somfy-ha-addon/icon.png diff --git a/Home Assistant/addon/pi_somfy/logo.png b/somfy-ha-addon/logo.png similarity index 100% rename from Home Assistant/addon/pi_somfy/logo.png rename to somfy-ha-addon/logo.png diff --git a/Home Assistant/addon/pi_somfy/patch_pigpiod.py b/somfy-ha-addon/patch_pigpiod.py similarity index 100% rename from Home Assistant/addon/pi_somfy/patch_pigpiod.py rename to somfy-ha-addon/patch_pigpiod.py diff --git a/Home Assistant/addon/pi_somfy/run.sh b/somfy-ha-addon/run.sh similarity index 61% rename from Home Assistant/addon/pi_somfy/run.sh rename to somfy-ha-addon/run.sh index 6f4e03b..a607b6e 100644 --- a/Home Assistant/addon/pi_somfy/run.sh +++ b/somfy-ha-addon/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/somfy-ha-addon/translations/en.yaml b/somfy-ha-addon/translations/en.yaml new file mode 100644 index 0000000..68bf966 --- /dev/null +++ b/somfy-ha-addon/translations/en.yaml @@ -0,0 +1,29 @@ +--- +configuration: + 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: >- + 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.