home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
73.19k stars 30.57k forks source link

Homewizard, unique id is already in use #111711

Closed Corsw closed 7 months ago

Corsw commented 8 months ago

The problem

For some reason the homewizard integration cannot create the sensors for my p1 meter anymore. There are several errors in the log:

What version of Home Assistant Core has the issue?

2024.2.4

What was the last working version of Home Assistant Core?

2024.12.3

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Homewizard

Link to integration documentation on our website

No response

Diagnostics information

config_entry-homewizard-38ba1979c6f5e0f236c454f85b7b3bee.json

Example YAML snippet

No response

Anything in the logs that might be useful for us?

Logger: homeassistant.components.sensor
Source: helpers/entity_platform.py:533
Integration: Sensor (documentation, issues)
First occurred: 27 februari 2024 om 20:41:58 (2 occurrences)
Last logged: 27 februari 2024 om 20:41:58

Error adding entities for domain sensor with platform rest
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1832, in forgiving_as_timestamp
    return dt_util.as_timestamp(value)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/util/dt.py", line 132, in as_timestamp
    raise ValueError("not a valid date/time.")
ValueError: not a valid date/time.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 533, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 782, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1324, in add_to_platform_finish
    await self.async_added_to_hass()
  File "/usr/src/homeassistant/homeassistant/helpers/trigger_template_entity.py", line 161, in async_added_to_hass
    await super().async_added_to_hass()
  File "/usr/src/homeassistant/homeassistant/components/rest/entity.py", line 42, in async_added_to_hass
    self._update_from_rest_data()
  File "/usr/src/homeassistant/homeassistant/components/rest/sensor.py", line 171, in _update_from_rest_data
    value = self._value_template.async_render_with_possible_json_value(
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 752, in async_render_with_possible_json_value
    render_result = _render_with_context(
                    ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 2332, in _render_with_context
    return template.render(**kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/jinja2/environment.py", line 1301, in render
    self.environment.handle_exception()
  File "/usr/local/lib/python3.12/site-packages/jinja2/environment.py", line 936, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "<template>", line 1, in top-level template code
  File "/usr/local/lib/python3.12/site-packages/jinja2/sandbox.py", line 393, in call
    return __context.call(__obj, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1835, in forgiving_as_timestamp
    raise_no_default("as_timestamp", value)
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1637, in raise_no_default
    raise ValueError(
ValueError: Template error: as_timestamp got invalid input '' when rendering template '{% set now_ts = as_timestamp(utcnow()) %} {% set values = namespace() %} {% set values.current = None %} {% for row in value_json.data|reverse if not values.current %} {% set row_timestamp = as_timestamp(row.datum) %} {% if now_ts > row_timestamp %} {% set values.current = row %} {% endif -%} {% endfor -%} {% if values.current %} {{ values.current.prijsZP }} {% else %} {{ states(entity_id) }} {% endif %}' but no default was specified

And this one:

Logger: homeassistant.components.sensor
Source: helpers/entity_platform.py:344
Integration: Sensor (documentation, issues)
First occurred: 27 februari 2024 om 20:41:58 (1 occurrences)
Last logged: 27 februari 2024 om 20:41:58

Error while setting up homewizard platform for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 344, in _async_setup_platform
    await asyncio.shield(task)
  File "/usr/src/homeassistant/homeassistant/components/homewizard/sensor.py", line 634, in async_setup_entry
    ent_reg.async_update_entity(
  File "/usr/src/homeassistant/homeassistant/helpers/entity_registry.py", line 997, in async_update_entity
    return self._async_update_entity(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity_registry.py", line 942, in _async_update_entity
    raise ValueError(
ValueError: Unique id 'homewizard_G0058530046451620' is already in use by 'sensor.totaal_gas_hw'

Additional information

No response

home-assistant[bot] commented 8 months ago

Hey there @dcsbl, mind taking a look at this issue as it has been labeled with an integration (homewizard) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `homewizard` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign homewizard` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


homewizard documentation homewizard source (message by IssueLinks)

DCSBL commented 8 months ago

Just to understand the situation better

Corsw commented 8 months ago

The problem came up after upgrading from HA 2023.12.x to 2024.2.3

removing the sensor.totaal_gas_hw and reloading the integration fixed it. The gas meter is now created as a seperate device, with its own entities. Before the electricty and the gas meter where combined as 1 device in HA, so i assume that this caused by creating the new device?

DCSBL commented 8 months ago

Yup we now split electricity and gas to support multiple gas meters (that is a thing..) and digital water meters. We added a migration for 'old' situations, but this is only tested for out-of-the-box situations. Not sure why this did not work in your situation.

So I assume this issue is fixed for you? If others have issues we can use this as reference.

Corsw commented 8 months ago

Removing the gas sensor and reloading the integration indeed fixed the issue. I'm guessing that the migration from the old situation only works with the standard sensor names.

DCSBL commented 7 months ago

Closing this issue as your issue has been solved, I have not other situations that may indicate we need to adjust the migration.

DCSBL commented 7 months ago

@home-assistant close