Template "scanner" device_tracker: presence-only tracking (is_connected + zone) without faking GPS #4671
Replies: 2 comments
|
Concrete case for this. I have an OpenWrt AP running wifi-presence. It publishes one message per device saying whether that device is connected to the wifi. That is the entire signal: a boolean. There is no declarative way to turn that into presence today. So I run it through Node-RED and call On the proposal itself: the "optional configured zone" half already exists in core. _scanner_option_associated_zone: str = zone.ENTITY_ID_HOMEIt is overridable per entity, and the end result is already tested. In the person tests, I also run |
|
Just a bit of clarification here. If a template scanner device tracker entity were added, it would most likely be based on BaseScannerEntity, as the funky mac address related logic of You should be able to do just basic home vs not home with the existing template entity via in_zones returning an empty array, or one with home in it, while fully omitting lat/long. If that isn't working properly it is a bug. It is true that the doing this would leave inaccurate source type and a debatable tracking type attribute, and won't be prioritized by person, but it should be otherwise functional. This still doesn't address the desired prioritization though, so it is not a full solution. Allowing the existing position based tracker entity to override source type should be fine. Specifically, if an integration has device trackers that use a mixture of connection status and GPS (possibly even varying over time), then deriving from I do have to wonder if the fixed logic implemented by person is just a bit too inflexible for some people's needs. But typically the workaround for an inflexible entity that wraps multiple is to put custom calculation logic in a template entity, and have it the inflexible entity wrap that template. |
Uh oh!
There was an error while loading. Please reload this page.
Describe your core improvement
Problem
Since the legacy
device_tracker.see/known_devices.yamlAPI was deprecated (removal in 2027.5), there is no config-entry-free way to declare a presence-only device tracker (home / not_home / zone) that does not pretend to be GPS. The recommended replacement, Templatedevice_tracker, is built onTrackerEntityand is GPS-only (_attr_source_type = SourceType.GPS, which integrations are not supposed to override). That has two consequences:latitude/longitude/in_zones, not a simple connected/home state.source_type: gps, it competes with real GPS trackers inpersonand regresses presence for BLE/router/ping sources. Details + reproduction: Recommended migration from deprecated device_tracker.see to Template device_tracker regresses person presence for non-GPS sources core#179771.Request
Add a Template variant built on the newer
ScannerEntitymodel (tracking_type = CONNECTION,_attr_source_type = SourceType.ROUTER) instead ofTrackerEntity. Minimal contract:is_connected: a template returningbool | None(the only required member ofBaseScannerEntity).zone.home).in_zonesis then derived by the base class exactly as for real scanners: connected → configured zone (+ enclosing zones), disconnected →not_home,None→ unknown.Why this shape
TrackerEntity's GPSsource_type(which the dev blog explicitly forbids). A "template scanner" fits the declared direction far better than "addsource_typeto Templatedevice_tracker".ScannerEntityreporting a zone lands inlatest_connected, the highest-priority bucket inperson— so BLE/router presence reliably wins over GPS, which is the entire point of room/beacon presence.device_tracker.see: BLE beacons (ESPresense), ping-based presence, Wi-Fi/router presence — all of which are "is_connected+ zone", exactly what a template can express.in_zonesonly became available in 2026.6, so this option only recently became feasible.Related
Current limitations
device_tracker.see(legacy platform API) is deprecated and removed in 2027.5. It was the only easy way to push a plainhome/not_homestate from an automation for a non-GPS source.device_trackeris built onTrackerEntity, which hardcodessource_type: gpsand must not be overridden. Presence can therefore only be expressed vialatitude/longitude/in_zones— there is no way to say "connected / home" without inventing coordinates.person. Because the template tracker reportssource_type: gps, it falls into thelatest_gpsbucket and competes with real GPS trackers (Companion App), instead of taking precedence like the oldbluetooth_lestate did. See core#179771.ScannerEntityis code-only. The connection/router entity model that would express this correctly is available only to config-entry integrations implemented in Python — there is no template / YAML way to create one.device_trackerwrapper (extra broker round-trip,retainhandling) or a full custom integration (e.g. Bermuda) — disproportionate for what used to be one service call.Technical benefits
ScannerEntity(tracking_type = CONNECTION,source_type = ROUTER), so it needs no override ofTrackerEntity's GPSsource_type— which the "device tracker entity models" dev blog explicitly forbids. No contract is bent.personresolution. AScannerEntityreporting a zone lands in thelatest_connectedbucket, the highest-priority path inperson._update_state. That is the semantically correct outcome for BLE/router presence and avoids the current regression where a Templatedevice_trackerforcessource_type: gpsand competes with real GPS trackers (see core#179771).BaseScannerEntityalready derivesin_zonesfromis_connected+ the configured zone. The template variant only needs to feed a templatedbool | Noneand a zone into that existing machinery — no new entity semantics.latitude/longitude, and zone geometry is not abused to fake a home/not_home state.device_tracker.seemigration gap. One template primitive covers the entire class orphaned by the legacy API removal in 2027.5 — BLE beacons (ESPresense), ping, Wi-Fi/router presence — reducing future bug reports, forum churn and custom-integration proliferation.Additional context
No response
All reactions