diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e7e32ab --- /dev/null +++ b/.gitignore @@ -0,0 +1,46 @@ +# Python +__pycache__/ +*.py[cod] +*$py.class +*.so +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg + +# Virtual environments +venv/ +ENV/ +env/ +.venv/ + +# IDE +.idea/ +.vscode/ +*.swp +*.swo +*~ + +# OS +.DS_Store +Thumbs.db + +# Testing +.pytest_cache/ +.coverage +htmlcov/ + +# Claude Code +.claude/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..56ca577 --- /dev/null +++ b/README.md @@ -0,0 +1,73 @@ +# HAOS Integrations + +A collection of custom Home Assistant integrations. + +## Integrations + +### Immich Album Watcher + +Immich + +Monitors [Immich](https://immich.app/) photo/video library albums for changes and exposes them as Home Assistant sensors with event-firing capabilities. + +#### Features + +- **Album Monitoring** - Watch selected Immich albums for asset additions and removals +- **Sensor Integration** - Creates Home Assistant sensors showing current asset count per album +- **Event Firing** - Fires Home Assistant events when albums change: + - `immich_album_watcher_album_changed` - General album changes + - `immich_album_watcher_assets_added` - When new assets are added + - `immich_album_watcher_assets_removed` - When assets are removed +- **Configurable Polling** - Adjustable scan interval (10-3600 seconds) +- **Rich Metadata** - Provides detailed album info including: + - Album name and ID + - Asset count + - Owner information + - Shared status + - Thumbnail URL + - Last updated timestamp + +#### Installation + +1. Copy the `immich_album_watcher` folder to your Home Assistant `custom_components` directory +2. Restart Home Assistant +3. Go to **Settings** → **Devices & Services** → **Add Integration** +4. Search for "Immich Album Watcher" +5. Enter your Immich server URL and API key +6. Select the albums you want to monitor + +#### Configuration + +| Option | Description | Default | +|--------|-------------|---------| +| Server URL | Your Immich server URL (e.g., `https://immich.example.com`) | Required | +| API Key | Your Immich API key | Required | +| Albums | Albums to monitor | Required | +| Scan Interval | How often to check for changes (seconds) | 60 | + +#### Events + +Use these events in your automations: + +```yaml +automation: + - alias: "New photos added to album" + trigger: + - platform: event + event_type: immich_album_watcher_assets_added + action: + - service: notify.mobile_app + data: + title: "New Photos" + message: "{{ trigger.event.data.added_count }} new photos in {{ trigger.event.data.album_name }}" +``` + +#### Requirements + +- Home Assistant 2024.1.0 or newer +- Immich server with API access +- Valid Immich API key + +## License + +This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. diff --git a/immich_album_watcher/icon.png b/immich_album_watcher/icon.png new file mode 100644 index 0000000..8216d3f Binary files /dev/null and b/immich_album_watcher/icon.png differ diff --git a/immich_album_watcher/sensor.py b/immich_album_watcher/sensor.py index 162760e..288eb4d 100644 --- a/immich_album_watcher/sensor.py +++ b/immich_album_watcher/sensor.py @@ -51,9 +51,10 @@ class ImmichAlbumSensor(CoordinatorEntity[ImmichAlbumWatcherCoordinator], Sensor """Sensor representing an Immich album.""" _attr_state_class = SensorStateClass.MEASUREMENT - _attr_native_unit_of_measurement = "assets" _attr_icon = "mdi:image-album" + _attr_translation_key = "album_asset_count" + def __init__( self, coordinator: ImmichAlbumWatcherCoordinator, @@ -77,11 +78,11 @@ class ImmichAlbumSensor(CoordinatorEntity[ImmichAlbumWatcherCoordinator], Sensor return self.coordinator.data.get(self._album_id) @property - def name(self) -> str: - """Return the name of the sensor.""" + def translation_placeholders(self) -> dict[str, str]: + """Return translation placeholders.""" if self._album_data: - return self._album_data.name - return f"Album {self._album_id[:8]}" + return {"album_name": self._album_data.name} + return {"album_name": f"Album {self._album_id[:8]}"} @property def native_value(self) -> int | None: diff --git a/immich_album_watcher/strings.json b/immich_album_watcher/strings.json index ea69e75..0be111a 100644 --- a/immich_album_watcher/strings.json +++ b/immich_album_watcher/strings.json @@ -1,4 +1,11 @@ { + "entity": { + "sensor": { + "album_asset_count": { + "name": "{album_name}: Asset Count" + } + } + }, "config": { "step": { "user": { diff --git a/immich_album_watcher/translations/en.json b/immich_album_watcher/translations/en.json index ea69e75..0be111a 100644 --- a/immich_album_watcher/translations/en.json +++ b/immich_album_watcher/translations/en.json @@ -1,4 +1,11 @@ { + "entity": { + "sensor": { + "album_asset_count": { + "name": "{album_name}: Asset Count" + } + } + }, "config": { "step": { "user": { diff --git a/immich_album_watcher/translations/ru.json b/immich_album_watcher/translations/ru.json new file mode 100644 index 0000000..5a6eff7 --- /dev/null +++ b/immich_album_watcher/translations/ru.json @@ -0,0 +1,60 @@ +{ + "config": { + "step": { + "user": { + "title": "Подключение к Immich", + "description": "Введите данные вашего сервера Immich. API-ключ можно получить в Immich → Настройки пользователя → API-ключи.", + "data": { + "immich_url": "URL Immich", + "api_key": "API-ключ" + }, + "data_description": { + "immich_url": "URL вашего сервера Immich (например, http://192.168.1.100:2283)", + "api_key": "Ваш API-ключ Immich" + } + }, + "albums": { + "title": "Выбор альбомов", + "description": "Выберите альбомы для отслеживания изменений.", + "data": { + "albums": "Альбомы для отслеживания" + } + } + }, + "error": { + "cannot_connect": "Не удалось подключиться к серверу Immich", + "invalid_auth": "Неверный API-ключ", + "no_albums": "На сервере не найдено альбомов", + "no_albums_selected": "Пожалуйста, выберите хотя бы один альбом", + "unknown": "Произошла непредвиденная ошибка" + }, + "abort": { + "already_configured": "Этот сервер Immich уже настроен" + } + }, + "options": { + "step": { + "init": { + "title": "Настройки Immich Album Watcher", + "description": "Настройте отслеживаемые альбомы и частоту проверки изменений.", + "data": { + "albums": "Альбомы для отслеживания", + "scan_interval": "Интервал сканирования (секунды)" + }, + "data_description": { + "scan_interval": "Как часто проверять изменения в альбомах (10-3600 секунд)" + } + } + }, + "error": { + "cannot_connect": "Не удалось подключиться к серверу Immich" + } + }, + "entity": { + "sensor": { + "album_asset_count": { + "name": "{album_name}: Число файлов" + } + } + } +}