# Shelly RGBW2 Animator Leichter Python-Dienst, der Animationen direkt am Shelly RGBW2 (Gen1) abspielt. openHAB sendet nur noch den gewünschten Modus per MQTT – der Pi wird dadurch deutlich entlastet. ## Features - Direkte HTTP-Ansteuerung des Shelly (kein openHAB-Event-Bus) - Steuerung per MQTT (`shelly-animator/set`) - Einfach neue Animationen hinzufügen - Läuft als Docker-Container **oder** systemd-Service ## Schnellstart (Docker – empfohlen) ```bash cd shelly-animator docker compose up -d --build ``` Logs: ```bash docker logs -f shelly-animator ``` ## Alternative: systemd (ohne Docker) ```bash sudo mkdir -p /opt/shelly-animator sudo cp -r app requirements.txt /opt/shelly-animator/ cd /opt/shelly-animator python3 -m venv venv ./venv/bin/pip install -r requirements.txt sudo cp systemd/shelly-animator.service /etc/systemd/system/ sudo systemctl daemon-reload sudo systemctl enable --now shelly-animator ``` ## MQTT-Steuerung | Topic | Richtung | Payload | |--------------------------|----------|----------------------------------| | `shelly-animator/set` | write | `chill` / `party` / `gaming` / `stop` | | `shelly-animator/state` | read | aktueller Modus oder `off` | Beispiele: ```bash mosquitto_pub -h localhost -p 1884 -t shelly-animator/set -m "party" mosquitto_pub -h localhost -p 1884 -t shelly-animator/set -m "stop" ``` ## openHAB Anbindung Ersetze die drei JS-Animation-Rules durch **eine** einfache Rule: ```javascript // Rule: Status → Shelly Animator (MQTT) const { items, actions } = require('openhab'); const status = items.getItem('Status').state.toString(); const mqtt = actions.get('mqtt', 'mqtt:broker:72a3b87ef9'); // ggf. anpassen const map = { 'Chillmode': 'chill', 'Partymode': 'party', 'Gamingmode': 'gaming', }; const anim = map[status] || 'stop'; mqtt.publishMQTT('shelly-animator/set', anim); ``` Trigger: `Status` Item State Change. ## Neue Animation hinzufügen 1. Datei anlegen: `app/animations/meine_anim.py` ```python from .base import Animation import colorsys class MeineAnimation(Animation): name = "meine" interval = 0.15 # Sekunden zwischen Ticks def on_start(self): super().on_start() self._t = 0 def tick(self): self._t += 0.05 # ... Farbe berechnen ... r, g, b = 255, 0, 128 self.shelly.set_color(r, g, b, gain=60) ``` 2. In `app/animations/__init__.py` registrieren: ```python from .meine_anim import MeineAnimation REGISTRY = { ... "meine": MeineAnimation, } ``` 3. Container neu bauen / Service neu starten. ## Umgebungsvariablen | Variable | Default | Beschreibung | |----------------|--------------------------|---------------------------| | `SHELLY_HOST` | `192.168.178.151` | IP des Shelly | | `SHELLY_USER` | `shelly@till.immers.ch` | Digest-Auth User | | `SHELLY_PASS` | `...` | Digest-Auth Passwort | | `MQTT_HOST` | `localhost` | MQTT Broker | | `MQTT_PORT` | `1884` | MQTT Port | | `MQTT_PREFIX` | `shelly-animator` | Topic-Prefix | | `LOG_LEVEL` | `INFO` | DEBUG / INFO / WARNING |