A Home Assistant Custom Integration by Alessandro Gorla (gorlix)
Control and monitor the Linux Focus Mode productivity daemon directly from Home Assistant. The integration exposes switches, sensors, binary sensors, and 8 services — all updated in real time via push webhooks from the daemon.
- Home Assistant ≥ 2024.1.0
- Focus Mode Linux App running on your
Linux machine (branch:
Home-Assistant-Integration) - HA instance reachable from the Linux machine (for webhook push)
- Open HACS → Integrations → ⋮ → Custom repositories.
- Add
https://github.com/gorlix/ha-focus-mode-linux— type Integration. - Search for Linux Focus Mode and click Download.
- Restart Home Assistant.
- Download the latest release zip from the Releases page.
- Copy
custom_components/linux_focus_mode/into your HAconfig/custom_components/directory. - Restart Home Assistant.
Go to Settings → Devices & Services → Add Integration → search Linux Focus Mode.
| Field | Description | Example |
|---|---|---|
| Host | IP address or hostname of the Linux machine | 192.168.1.100 |
| Port | API port (default 8000) | 8000 |
| Bearer Token | Token copied from the Linux app → Settings → HA Integration | abcdef1234... |
The integration validates the connection live before saving. On failure it shows the exact error.
After saving credentials, HA displays a webhook URL like:
https://your-ha-instance.local/api/webhook/linux_focus_mode_xxxxxxxx
Open the Linux app → Settings → HA Integration and paste this URL into both fields:
- Webhook eventi di stato (
state_event_url) - Webhook dying gasp (
dying_gasp_url)
Using the same URL for both is correct — the integration distinguishes the two event types
by reading the event field in the JSON payload.
| Entity | Description |
|---|---|
switch.linux_focus_mode_focus_mode |
Toggle the process blocker on/off |
switch.linux_focus_mode_ha_lock |
Activate/deactivate the indefinite HA Lock |
switch.linux_focus_mode_auto_restore |
Enable/disable auto-restore of blocked apps |
Note: Turning off the Focus Mode switch while HA Lock is active raises an error. Use the HA Lock switch (or
unlockservice) to remove the lock first.
| Entity | Description |
|---|---|
sensor.linux_focus_mode_blocked_apps_count |
Number of configured blocked items |
sensor.linux_focus_mode_lock_remaining_time |
Human-readable lock countdown, or — |
| Entity | Description |
|---|---|
binary_sensor.linux_focus_mode_focus_locked |
on when any lock is active |
binary_sensor.linux_focus_mode_app_online |
on when daemon is reachable |
All services are callable from automations, scripts, and the Developer Tools.
| Service | Parameters | Description |
|---|---|---|
linux_focus_mode.focus_on |
— | Activate the blocker |
linux_focus_mode.focus_off |
— | Deactivate the blocker |
linux_focus_mode.lock_timer |
minutes (int, > 0) |
Timer lock for N minutes |
linux_focus_mode.lock_target |
hour (0–23), minute (0–59) |
Lock until HH:MM today |
linux_focus_mode.lock_ha |
— | Indefinite HA lock |
linux_focus_mode.unlock |
— | Cancel any active lock |
linux_focus_mode.restore_on |
— | Enable auto-restore |
linux_focus_mode.restore_off |
— | Disable auto-restore |
automation:
alias: "Start Pomodoro from button"
trigger:
- platform: state
entity_id: input_button.start_pomodoro
action:
- service: linux_focus_mode.focus_on
- service: linux_focus_mode.lock_timer
data:
minutes: 25Home Assistant ←──── push webhook on every state change ────── Linux daemon
│ ▲
└──── GET /api/state every 30 s (fallback) ──────────────────►│
└──── POST/DELETE /api/toggle|lock|restore (service calls) ───►│
- Push webhooks provide real-time updates (no 30 s wait).
- The 30 s polling is a fallback for missed webhooks.
- On app shutdown, a
dying_gaspwebhook marks all entitiesunavailableinstantly.
Entities show unavailable
- The daemon is not running or unreachable. Check that the Linux app is started.
- Verify host/port in the integration settings.
Webhook not working (entities update only every 30 s)
- Make sure the webhook URL is pasted into both fields of the Linux app settings.
- Verify your HA instance is reachable from the Linux machine (check firewall/Nabu Casa).
"Cannot disable Focus Mode while HA Lock is active"
- Turn off the HA Lock switch first, or call
linux_focus_mode.unlock.
Re-entering credentials
- Go to Settings → Devices & Services → select the integration → Configure.
MIT License. See LICENSE for details.