#Entity id errors

1 messages · Page 1 of 1 (latest)

torn sorrel
#

Can you share your code?

#

You're either not creating unique ids

#

Or creating the sensors multiple times

slow timber
#

It happens upon boot of HASS

#

My thinking is that they attempt to recreate then

#

sensor.py needs to create them on the first go around on install of the custom component

#

Then managers.py should in theory check that they exist before running, but looking at debug logging, it never goes through that part at all

#

I linked to the .py files in the main chat if you want to take a quick look

#

Basically if line29 of managers.py was doing its job, I'm pretty sure I wouldn't be seeing the errors at all

torn sorrel
#

It will „create“ them on every reload

#

You don’t need to worry about if it’s already there

slow timber
#

I thought my problem was on the "manager.py" side since if I comment out that line it fixes the issue

#

Thing is, I need it to run once

torn sorrel
#

That error means it really tries to create something with those names twice on reload

#

Either because there’s a loop off

#

Or those entity id‘s are not unique enough and multiple similar entities generate the same one

slow timber
#

Uh-huh, yes I'm pretty sure it does try to create them a second time

#

I'd be more inclined to say it has to do with recreating them

torn sorrel
#

Thing is this is quite some spaghetti code tbh

#

So it's not easy to see by looking at it

slow timber
#

Yeah I'm not the author so I try and make it easier to read bit by bit...

But yeah. Commenting out line 159 of sensor.py fixes the errors. It's not a viable solution though as it still needs to happen once. And if users add devices, it needs to happen again. Hence why I was trying to fix it in managers.py

#

I appreciate you taking a few minutes I know this is an unsupported thing I'm asking about

torn sorrel
#

Yeah you need to find where it's added twice

#

Probably it’s just in the entities array multiple times

#

Don't try to find it in the entity registry

#

Maybe log each unique id of all the sensors before adding them

#

I struggle to even see from which of those classes the problematic sensors are coming from

slow timber
#

Will try and add more logging on my end until I see through which part of the code I'm running through

slow timber
#

Okay so I added further logging

#

This line:

if entity in self.hass.data.get("utility_meter_data", {}):

is what is not working. self.hass.data.get returns nothing at all

#

So that if statement is never true, and the rest of the code runs

#

If that if was true it'd stop and not attemps to create them

#

Here's the logging I added:

def add_meter(self, entity, tariff_list, net_consumption=False):
        LOG.debug("Hil0 calling add_meter")
        self.add_meter_entity(entity, tariff_list)
        self.add_meter_config(entity, tariff_list, net_consumption)

    def add_meter_entity(self, entity, tariff_list):
        LOG.debug("Hil0 in add_meter_entity")
        LOG.debug(f"Hil0 hass.data {self.hass.data.get("utility_meter_data", {})}")
        LOG.debug(f"Hil0 entity is {entity}")
        if entity in self.hass.data.get("utility_meter_data", {}):
            LOG.debug("Hil0 checking entity")
            LOG.debug(f"Entity {entity} is already in the utility meters")
            return
#

And the result:

#
2024-02-13 20:22:44.732 DEBUG (MainThread) [custom_components.hilo] Hil0 calling add_meter
2024-02-13 20:22:44.732 DEBUG (MainThread) [custom_components.hilo] Hil0 in add_meter_entity
2024-02-13 20:22:44.732 DEBUG (MainThread) [custom_components.hilo] Hil0 hass.data {}
2024-02-13 20:22:44.732 DEBUG (MainThread) [custom_components.hilo] Hil0 entity is hilo_energy_total
2024-02-13 20:22:44.734 DEBUG (MainThread) [custom_components.hilo] Hil0 calling add_meter
2024-02-13 20:22:44.734 DEBUG (MainThread) [custom_components.hilo] Hil0 in add_meter_entity
2024-02-13 20:22:44.734 DEBUG (MainThread) [custom_components.hilo] Hil0 hass.data {}
2024-02-13 20:22:44.734 DEBUG (MainThread) [custom_components.hilo] Hil0 entity is hilo_energy_thermostat_cuisine

à