Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 additions & 10 deletions Home Assistant/addon/pi_somfy/DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -44,6 +45,16 @@ 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.

## Web UI

The add-on provides a web interface accessible in two ways:
Expand All @@ -69,8 +80,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) MQTTno 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
Expand Down
5 changes: 3 additions & 2 deletions Home Assistant/addon/pi_somfy/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 /
Expand Down
4 changes: 4 additions & 0 deletions Home Assistant/addon/pi_somfy/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,22 @@ 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)?"
spi_sck: "int(0,27)"
spi_mosi: "int(0,27)"
spi_miso: "int(0,27)"
spi_csn: "int(0,27)"
enable_mqtt: "bool"
discovery:
- pi_somfy
40 changes: 35 additions & 5 deletions Home Assistant/addon/pi_somfy/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,35 @@ 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}"

for entry in "MQTT_Server:${MQTT_HOST}" "MQTT_Port:${MQTT_PORT}" "MQTT_User:${MQTT_USER}" "MQTT_Password:${MQTT_PASSWORD}" "MQTT_ClientID:somfy-mqtt-bridge"; 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}"

Expand Down Expand Up @@ -74,9 +103,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

Expand All @@ -88,7 +118,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}