Skip to content

Leave out a recipient's mobile devices nobody is using (#299) - #336

Merged
jeyrb merged 2 commits into
rhizomatics:mainfrom
lollox80:feat/idle-mobile-devices-299
Nov 24, 2026
Merged

jeyrb merged 2 commits into
rhizomatics:mainfrom
lollox80:feat/idle-mobile-devices-299

Conversation

@lollox80

Copy link
Copy Markdown
Collaborator

Closes #299

What

A recipient's mobile devices that nobody is using are left out of a notification, as discussed in #299: a sleeping Mac no longer shows a pile of stale alerts on wake, and a watch on the bedside table doesn't buzz.

Supernotify finds each Companion App device's in-use sensor in the entity registry, from the sensor's own id (the part of the unique id after the webhook id), so nothing has to be configured:

Device Companion sensor id Off when
macOS active asleep, screensaver on, display off or locked
Wear OS on_body the watch isn't being worn

As agreed in the issue:

  • When in doubt, send: a device is left out only when its sensor is plainly off. No sensor (iPhone, iPad), or unknown/unavailable, and it's notified as today
  • Critical goes to every device
  • Safety net: if every one of a person's devices would be left out, none is
  • Overrides: send_when_idle per device (YAML, and Notify even when not in use on the recipient form), and include_idle_devices: true on a single notification
  • Trace: left-out devices are recorded as the idle_mobile_devices debug artefact, with the sensor that said so
  • A mobile_app_id given directly as a target of the notification is always notified - only the devices reached through a recipient are filtered

One change from my proposal in the issue

I'd listed Android's interactive among the default sensors. Checking the Companion app source, it's is_interactive, and only means screen on: a phone in a pocket is "idle" nearly all the time, so with a tablet on and the phone in a pocket, the phone would have been the one skipped. So it isn't auto-mapped. Instead in_use_entity on a mobile_devices entry gives or overrides a device's sensor, which covers an Android tablet (binary_sensor.<tablet>_is_interactive) or an iPad with a template binary sensor:

recipients:
  - person: person.bob
    mobile_devices:
      - mobile_app_id: mobile_app_bobs_tablet
        in_use_entity: binary_sensor.bobs_tablet_is_interactive
      - mobile_app_id: mobile_app_bobs_mac
        send_when_idle: true

Where

  • hass_api.py: build_mobile_app_cache() picks up the in-use sensor next to the device tracker; TrackedDeviceDetails.in_use_entity; companion_sensor_id()
  • people.py: Recipient.idle_mobile_app_ids() - the state check, send_when_idle and the all-idle safety net
  • notification.py: applied in resolve_indirect_targets(), right after the mobile snooze filter, so it's the same point where a person's devices first appear
  • schema.py / const.py: in_use_entity and send_when_idle in MOBILE_DEVICE_SCHEMA, include_idle_devices as an action field
  • config_flow.py: the Notify even when not in use field. The details step also used to rebuild mobile_devices from just the id and enabled, which would have dropped in_use_entity; it now keeps whatever else is set for a device
  • services.yaml, translations (11 languages), docs/transports/mobile_push.md

Classes of device and a fallback order are left for a later step, as discussed.

Tests

tests/components/supernotify/test_idle_mobile_devices.py (15 tests): discovery of active/on_body (not is_interactive, not a disabled sensor), configured sensor winning over the discovered one, off/on/unknown/unavailable/missing, send_when_idle, critical, include_idle_devices, explicit targets, all-idle, trace, and the recipient form round trip.

Check Result
ruff check / format, codespell ✅
mypy, ty ✅
pytest HA 2026.5 ✅
pytest HA 2026.10 (lock) ✅ 2934 passed, 98% coverage
pytest HA 2026.11 (pytest-homeassistant) ✅

🤖 Generated with Claude Code

https://claude.ai/code/session_01Xb3AAKXSWfYfHnCk6Vm3kh

…tics#299)

A person's mobile devices are each sent a push, whether anyone is using
them or not: a sleeping Mac shows a pile of stale alerts on wake, a watch
on the bedside table buzzes.

Each Companion App device's in-use sensor is now found in the entity
registry - macOS `active` and Wear OS `on_body` - and a device whose
sensor is plainly `off` is left out as the person's targets are resolved.

- No sensor, or `unknown`/`unavailable`: notified as before
- `critical` goes to every device
- If all of a person's devices are idle, none is left out
- A mobile_app_id given directly in the notification is always notified
- `in_use_entity` on a `mobile_devices` entry gives or overrides the
  sensor, e.g. `is_interactive` for an Android tablet, not taken by
  default since it's off for a phone in a pocket
- `send_when_idle` on a device, also on the recipient form, and
  `include_idle_devices` on a notification, notify it regardless
- Left-out devices are in the debug trace as `idle_mobile_devices`
- The recipient form keeps per-device settings it doesn't show, where it
  rebuilt `mobile_devices` from just the id and enabled flag

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Xb3AAKXSWfYfHnCk6Vm3kh
@jeyrb
jeyrb merged commit c1ff984 into rhizomatics:main Nov 24, 2026
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Per-device conditions for mobile_push devices (skip devices that aren't in use)

2 participants