Files
nikrozmanandClaude Opus 5.5 7398e590e6
CI / build (push) Successful in 15s
Release / release (push) Successful in 17s
GPL-3.0-or-later, Gitea CI and release pipeline
- License the project under GPL-3.0-or-later (LICENSE + SPDX headers).
- CI workflow builds every push and pull request and checks manifest.json.
- Release workflow: an annotated v* tag builds that version, creates a
  Gitea release with the zip attached and adds it to manifest.json.
- Release zips now live in Gitea releases instead of dist/; build.sh is a
  local test build only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-30 00:30:07 +01:00

94 lines
4.8 KiB
Markdown

# Lights Off Timer — Jellyfin sleep timer that turns off your Home Assistant lights
[![CI](https://git.piskot.si/nikrozman/jellyfin-lights-out-ha/actions/workflows/ci.yml/badge.svg)](https://git.piskot.si/nikrozman/jellyfin-lights-out-ha/actions)
[![License: GPL-3.0-or-later](https://img.shields.io/badge/license-GPL--3.0--or--later-blue)](LICENSE)
A Jellyfin plugin that adds a **sleep-timer button next to the volume control** in the web player.
Pick *End of this episode/movie* (the default) or a number of minutes; when playback stops,
the plugin tells **Home Assistant**, which turns the lights off after a cooldown (15 minutes by default).
Starting playback again cancels the countdown.
- **End of this episode/movie** — when the item finishes, the next autoplayed episode is stopped.
- **15 / 30 / 45 / 60 / 90 minutes** (configurable) — playback is stopped when the time is up.
- **Lights off** — on that stop (or when you stop playback yourself while the timer is on),
Home Assistant starts its countdown and turns the lights off when it runs out.
Built for **Jellyfin 12.2** (`targetAbi 12.2.0.0`).
## Install
1. In Jellyfin: **Dashboard → Plugins → Repositories → +**
- Name: `Lights Off Timer`
- URL: `https://git.piskot.si/nikrozman/jellyfin-lights-out-ha/raw/branch/master/manifest.json`
2. **Catalog → Lights Off Timer → Install**, then restart Jellyfin.
3. **Plugins → Lights Off Timer → Settings**:
- **Home Assistant webhook URL** — `https://<your-home-assistant>/api/webhook/<webhook id>`
- **Lights off after (minutes)** — the cooldown, default 15
- **Timer presets** — minutes shown in the menu, default `15,30,45,60,90`
- **Start the countdown on every playback stop** — off by default (only when the sleep timer was on)
4. Reload the Jellyfin web page. The moon button appears next to the volume slider while a video plays.
## Home Assistant
Copy [`home-assistant/jellyfin_lights.yaml`](home-assistant/jellyfin_lights.yaml) into a package,
set a long random `webhook_id`, reload **Timers** and **Automations**, and put the matching URL in the plugin settings.
It creates `timer.movie_lights_off`, which you can show on a dashboard.
The plugin sends:
| When | Payload |
|---|---|
| Playback starts (any item) | `{"event": "started"}` |
| Playback stops with the sleep timer on (or every stop, if enabled) | `{"event": "stopped", "cooldown_minutes": 15, "user": "…", "device": "…", "item": "…"}` |
The webhook id is the only secret: anyone who knows it can trigger the automation.
## Limitations
- The button only exists in **Jellyfin Web** (browser and Jellyfin Media Player). Native apps
(Swiftfin, Android TV, Apple TV…) can't be extended by plugins.
- Stopping playback uses Jellyfin's remote-control command, so the client must support remote control
(Jellyfin Web does).
- Timers live in memory: restarting Jellyfin clears them.
## How it works
- `TimerManager` keeps a timer per playback session and listens to Jellyfin's `PlaybackStart` /
`PlaybackStopped` events. It stops playback with `SendPlaystateCommand(Stop)` and posts to the webhook.
- `ScriptInjection` adds `<script src="../LightsOffTimer/client.js">` to `/web/index.html` as it is served
(nothing in the web client folder is modified).
- `Web/client.js` adds the button and menu to the player and talks to the plugin API with the logged-in user's token:
- `GET /LightsOffTimer/State` — timer for the caller's own session
- `POST /LightsOffTimer/Set` — `{"mode": "end" | "minutes" | "off", "minutes": 30}`
- A `client.js` placed in the plugin's data folder overrides the built-in one, for styling tweaks without rebuilding.
## Build / release
Every push and pull request is built by the [CI workflow](.gitea/workflows/ci.yml).
To release, push an annotated tag; its message becomes the release notes:
```sh
git tag -a v1.0.3.0 -m "What changed"
git push origin v1.0.3.0
```
The [release workflow](.gitea/workflows/release.yml) builds that version against the
`Jellyfin.Controller` 12.2.0 NuGet package, creates a [release](https://git.piskot.si/nikrozman/jellyfin-lights-out-ha/releases)
with `lightsofftimer_<version>.zip` attached, and adds the version (download URL + MD5) to `manifest.json`,
so every Jellyfin server using the repository is offered the update.
Local test build (needs only Docker): `./build.sh` → `out/lightsofftimer_dev.zip`.
For another Jellyfin version, change the package versions in the `.csproj` and `TARGET_ABI` in the release workflow.
## License
Copyright © 2026 Nik Rozman and contributors.
This program is free software: you can redistribute it and/or modify it under the terms of the
GNU General Public License as published by the Free Software Foundation, either version 3 of the License,
or (at your option) any later version. See [LICENSE](LICENSE).
Contributions are welcome under the same license.