Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IDEA: Embed cost sensors into the devices they're calculated from #14

Open
whi-tw opened this issue May 9, 2024 · 2 comments
Open

IDEA: Embed cost sensors into the devices they're calculated from #14

whi-tw opened this issue May 9, 2024 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@whi-tw
Copy link

whi-tw commented May 9, 2024

Not doing the template for this one, sorry! I couldn't work out how to structure it into the headings!

I use https://github.com/bramstroker/homeassistant-powercalc for some devices (virtual power meter for devices, calculated by setting on, off, idle power draw readings).

This addon 'embeds' the energy / power sensors 'into' the original device:

image

It's a super clean way of presenting this kind of information, as it reduces the number of individual devices on the system, and puts the energy information directly within the device, so it's available immediately when looking at the device.

Unsure of your thoughts on this, it could be complicated - I'm not 100% on the actual implementation details from powercalc.

I just wanted to draw attention to it as you may not have seen this pattern before, and it could be a good fit.

Unsure.

@whi-tw whi-tw added the enhancement New feature or request label May 9, 2024
@martinarva
Copy link
Owner

Yep, this is in the roadmap. I have already checked the powercalc code, but was a bit overwhelming.

@martinarva
Copy link
Owner

martinarva commented May 9, 2024

I just can't get it to work. Must be something like this:

    @property
    def device_info(self):
        """Return device information to link this sensor with the integration or a specific device."""
        entity_registry = er.async_get(self.hass)
        entity_entry = entity_registry.async_get(self._energy_sensor_id)
        
        if entity_entry and entity_entry.device_id:
            # If there is a device linked to the user-inputted energy sensor, link the sensor to it.
            return {
                "identifiers": {(DOMAIN, self._energy_sensor_id)},  # Unique identifier for your sensor
                "name": self._device_name,
                "via_device": entity_entry.device_id  # Link to the device of the original energy sensor
            }
        else:
            # Fallback if no device is linked to the energy sensor
            return {
                "identifiers": {(DOMAIN, self._energy_sensor_id)},
                "name": self._device_name,
                "manufacturer": "Custom Integration"
            }

But it's not working.

I

@martinarva martinarva self-assigned this May 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants