v1.5.0
✨ New Feature: Attach Counter to an Existing Device (closes #34)
Counter sensors are now automatically associated with the device that owns their trigger entity. When you configure a counter whose trigger entity belongs to a physical or virtual device (e.g. a Tuya light, a Z-Wave switch, etc.), the counter sensor will appear directly on that device's page in Home Assistant instead of creating a separate virtual device entry.
Added
- ✨ Automatic device association:
device_infonow queries the entity registry and device registry at runtime. If the trigger entity is linked to an existing device, the counter sensor adopts that device's identifiers and appears alongside it in the HA UI. - ✅ Graceful fallback: If the trigger entity has no associated device (e.g. virtual helpers, template sensors), the counter falls back to the existing behaviour of creating its own virtual device entry.
Changed
- Updated version to 1.5.0 in
manifest.json. - Added
device_registryandentity_registryimports tosensor.py.
Technical Details
HADailyCounterEntity.device_infouseser.async_get(hass).async_get(entity_id)to retrieve the trigger entity'sdevice_id, thendr.async_get(hass).async_get(device_id)to fetch the fullDeviceEntryand itsidentifiers.- Both registry lookups are synchronous in-memory operations (no I/O), so they are safe to perform inside a property.
- Inspired by the approach used in ha_real-last-changed.
Credits
- 🙏 Feature requested by @alsmaison in #34.