Skip to content

How it works

Michal Zaniewicz edited this page Nov 17, 2026 · 6 revisions

Logging in

An integration for Librus already exists (LukMaverick/LibrusSynergiaHA, built on RustySnek/librus-apix), but it logs into the legacy HTML Synergia portal, which can demand a reCAPTCHA a human has to solve - unworkable for something meant to sync unattended in the background.

This integration instead uses the login flow Librus's own website/app uses for its private API gateway - reverse-engineered from emsi/librus_pyapi (MIT), which was itself updated to track a Librus authentication change on 2026-03-28. Confirmed live (2026-09-05) to complete without a captcha challenge for a normal login. An older password-grant login (the one documented by the open-source szkolny-eu/szkolny-android app) no longer works: Librus now answers it with unsupported_grant_type.

The Librus client itself lives in a separate library, librus-synergia (pip install librus-synergia). You can use it outside Home Assistant, and it comes with an unofficial Librus API reference.

This is an unofficial integration using a private API and may violate Librus's Terms of Service. Use your own account at your own risk.

Staying logged in

Librus drops a session after about 10 minutes without a request, so with the default 20-minute refresh most refreshes find it gone. Versions 0.12.50 and newer renew it with Librus's own token refresh, the way the Librus website does, and log in with the password only when that fails (before, nearly every refresh was a password login). The diagnostics (Download diagnostics on the integration's page) show how it went since Home Assistant started: session_renewals counts the token refreshes and the password logins, with the time of the last of each. Since 0.12.52 the session is refreshed before a refresh starts when it has been quiet for 8 minutes, so these counts (which cover only sessions Librus rejected) should stay near zero; messages_bootstraps and messages_retries show how often the messages session was set up and retried. At night (22:00-06:00) and on days without lessons, what is normally asked hourly waits 6 hours.

When Librus is down

The integration keeps the last good response of every part of Librus (in Home Assistant's own storage). If one part fails - grades, the timetable, subject names - its last good copy is shown instead of an empty sensor. If Librus doesn't answer at all, every entity keeps showing the last data (the Connection status sensor says stale) for up to 3 days; after two failed refreshes in a row the next attempts are spaced out (twice the poll interval, then four times, up to 2 hours), so an outage isn't met with a login attempt every cycle - the librus_synergia.refresh action still tries straight away. If Home Assistant starts while Librus is down, the data is rebuilt from the saved responses instead of the integration failing to load. Long lists in attributes (grade logs, recent lists, breakdowns) aren't written to the recorder's history, which keeps the database small; templates and cards read them as before.

Checking the connection

Versions after 0.12.37: Settings > System > Repairs > (⋮) System information has a Librus Synergia (unofficial) section - whether Home Assistant reaches Synergia, the Librus login and Wiadomości, each student's connection status (ok, degraded, stale, error, the same as the Connection status sensor), the oldest last successful update, the parts of Librus that are failing right now, and the librus-synergia library version. It holds no names, so it's safe to paste into a bug report.

Grade averages over the whole year

The integration also writes the history of the overall and per-subject averages, rebuilt from the grades' dates, into Home Assistant's long-term statistics - so a chart covers the school year from its first grade, not just the time since you installed the integration. Add a Statistics graph card and pick e.g. "Ola Kowalska - średnia Matematyka" (statistic type Mean). It's rewritten whenever the grades change; it needs the Recorder, which is on by default.

Clone this wiki locally