StyraHem / ShellyForHASS

Shelly smart home platform for Home Assistant
MIT License
615 stars 110 forks source link

[BUG] Invalid entity ID since Home Assistant 2022.03.0 #659

Closed JurajNyiri closed 2 years ago

JurajNyiri commented 2 years ago

Update

Fix is available inside PR https://github.com/StyraHem/ShellyForHASS/pull/660 .

Environment

Describe the bug

Installed Home Assistant 2022.03.0, applied https://github.com/StyraHem/ShellyForHASS/pull/658 to fix https://github.com/StyraHem/ShellyForHASS/issues/655 . Restarted, now most of the entities are not working.

Total consumption and firmware switch entities are working, current consumption entities are not.

Steps to Reproduce

  1. Install Home Assistant 2022.03.0
  2. Apply https://github.com/StyraHem/ShellyForHASS/pull/658 to the latest ShellyForHass version 0.3.3
  3. Restart Hass

Expected behavior

Current consumption and other entities should be working.

Screenshots

image

Traceback/Error logs

2022-03-03 00:53:02 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 526, in async_update_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 638, in _async_write_ha_state
    attr.update(self.hass.data[DATA_CUSTOMIZE].get(self.entity_id))
  File "/usr/src/homeassistant/homeassistant/helpers/entity_values.py", line 40, in get
    domain, _ = split_entity_id(entity_id)
  File "/usr/src/homeassistant/homeassistant/core.py", line 148, in split_entity_id
    raise ValueError(f"Invalid entity ID {entity_id}")
ValueError: Invalid entity ID .shelly_shem_3_c45bbe604121_1_current_consumption
2022-03-03 00:53:05 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 526, in async_update_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 638, in _async_write_ha_state
    attr.update(self.hass.data[DATA_CUSTOMIZE].get(self.entity_id))
  File "/usr/src/homeassistant/homeassistant/helpers/entity_values.py", line 40, in get
    domain, _ = split_entity_id(entity_id)
  File "/usr/src/homeassistant/homeassistant/core.py", line 148, in split_entity_id
    raise ValueError(f"Invalid entity ID {entity_id}")
ValueError: Invalid entity ID .shelly_shem_3_c45bbe604121_2_current_consumption
2022-03-03 00:53:06 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 526, in async_update_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 638, in _async_write_ha_state
    attr.update(self.hass.data[DATA_CUSTOMIZE].get(self.entity_id))
  File "/usr/src/homeassistant/homeassistant/helpers/entity_values.py", line 40, in get
    domain, _ = split_entity_id(entity_id)
  File "/usr/src/homeassistant/homeassistant/core.py", line 148, in split_entity_id
    raise ValueError(f"Invalid entity ID {entity_id}")
ValueError: Invalid entity ID .shelly_shem_3_c45bbe604121_1_current_consumption
2022-03-03 00:53:06 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 526, in async_update_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 638, in _async_write_ha_state
    attr.update(self.hass.data[DATA_CUSTOMIZE].get(self.entity_id))
  File "/usr/src/homeassistant/homeassistant/helpers/entity_values.py", line 40, in get
    domain, _ = split_entity_id(entity_id)
  File "/usr/src/homeassistant/homeassistant/core.py", line 148, in split_entity_id
    raise ValueError(f"Invalid entity ID {entity_id}")
ValueError: Invalid entity ID .shelly_shem_3_c45bbe604121_2_current_consumption
2022-03-03 00:53:06 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 526, in async_update_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 638, in _async_write_ha_state
    attr.update(self.hass.data[DATA_CUSTOMIZE].get(self.entity_id))
  File "/usr/src/homeassistant/homeassistant/helpers/entity_values.py", line 40, in get
    domain, _ = split_entity_id(entity_id)
  File "/usr/src/homeassistant/homeassistant/core.py", line 148, in split_entity_id
    raise ValueError(f"Invalid entity ID {entity_id}")
ValueError: Invalid entity ID .shelly_shem_3_c45bbe604121_3_current_consumption
2022-03-03 00:53:06 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 526, in async_update_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 638, in _async_write_ha_state
    attr.update(self.hass.data[DATA_CUSTOMIZE].get(self.entity_id))
  File "/usr/src/homeassistant/homeassistant/helpers/entity_values.py", line 40, in get
    domain, _ = split_entity_id(entity_id)
  File "/usr/src/homeassistant/homeassistant/core.py", line 148, in split_entity_id
    raise ValueError(f"Invalid entity ID {entity_id}")
ValueError: Invalid entity ID .shelly_shem_3_c45bbe604121_1_current_consumption
2022-03-03 00:53:07 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 526, in async_update_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 638, in _async_write_ha_state
    attr.update(self.hass.data[DATA_CUSTOMIZE].get(self.entity_id))
  File "/usr/src/homeassistant/homeassistant/helpers/entity_values.py", line 40, in get
    domain, _ = split_entity_id(entity_id)
  File "/usr/src/homeassistant/homeassistant/core.py", line 148, in split_entity_id
    raise ValueError(f"Invalid entity ID {entity_id}")
ValueError: Invalid entity ID .shelly_shem_3_c45bbe604121_2_current_consumption
2022-03-03 00:53:07 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 526, in async_update_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 638, in _async_write_ha_state
    attr.update(self.hass.data[DATA_CUSTOMIZE].get(self.entity_id))
  File "/usr/src/homeassistant/homeassistant/helpers/entity_values.py", line 40, in get
    domain, _ = split_entity_id(entity_id)
  File "/usr/src/homeassistant/homeassistant/core.py", line 148, in split_entity_id
    raise ValueError(f"Invalid entity ID {entity_id}")
ValueError: Invalid entity ID .shelly_shem_3_c45bbe604121_3_current_consumption
2022-03-03 00:53:07 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 526, in async_update_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 638, in _async_write_ha_state
    attr.update(self.hass.data[DATA_CUSTOMIZE].get(self.entity_id))
  File "/usr/src/homeassistant/homeassistant/helpers/entity_values.py", line 40, in get
    domain, _ = split_entity_id(entity_id)
  File "/usr/src/homeassistant/homeassistant/core.py", line 148, in split_entity_id
    raise ValueError(f"Invalid entity ID {entity_id}")
ValueError: Invalid entity ID .shelly_shem_b0858a_1_current_consumption
2022-03-03 00:53:09 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 526, in async_update_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 638, in _async_write_ha_state
    attr.update(self.hass.data[DATA_CUSTOMIZE].get(self.entity_id))
  File "/usr/src/homeassistant/homeassistant/helpers/entity_values.py", line 40, in get
    domain, _ = split_entity_id(entity_id)
  File "/usr/src/homeassistant/homeassistant/core.py", line 148, in split_entity_id
    raise ValueError(f"Invalid entity ID {entity_id}")
ValueError: Invalid entity ID .shelly_shem_b0858a_2_current_consumption
2022-03-03 00:53:09 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 526, in async_update_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 638, in _async_write_ha_state
    attr.update(self.hass.data[DATA_CUSTOMIZE].get(self.entity_id))
  File "/usr/src/homeassistant/homeassistant/helpers/entity_values.py", line 40, in get
    domain, _ = split_entity_id(entity_id)
  File "/usr/src/homeassistant/homeassistant/core.py", line 148, in split_entity_id
    raise ValueError(f"Invalid entity ID {entity_id}")
ValueError: Invalid entity ID .shelly_shem_b0858a_2_current_consumption
2022-03-03 00:53:10 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 526, in async_update_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 638, in _async_write_ha_state
    attr.update(self.hass.data[DATA_CUSTOMIZE].get(self.entity_id))
  File "/usr/src/homeassistant/homeassistant/helpers/entity_values.py", line 40, in get
    domain, _ = split_entity_id(entity_id)
  File "/usr/src/homeassistant/homeassistant/core.py", line 148, in split_entity_id
    raise ValueError(f"Invalid entity ID {entity_id}")
ValueError: Invalid entity ID .shelly_shem_b0858a_1_current_consumption

Additional context

JurajNyiri commented 2 years ago

I have rolled back to Home Assistant 2022.02.9 using command ha core update --version 2022.2.9. I have left the integration code exactly like described above (so 0.3.3 with https://github.com/StyraHem/ShellyForHASS/pull/658) and everything works again.

So there must be something new in 2022.03.0 breaking the entity IDs.

blubbel42 commented 2 years ago

Same here. Interesting though: Before this my total consumption sensors were broken a I couldn't figure out why in any way. After upgrading and then rolling back because of issues now everything works fine as it never has before. My thought while looking at the error messages was that the prefixes (Sensor, switch...) of the entities were missing. But I am not sure how to interprete this here. Greetings Blubbel

poldim commented 2 years ago

I think it’s this based on the errors: https://www.home-assistant.io/blog/2022/03/02/release-20223/#updates-for-custom-integration-developers

@hakana - FYI

Helper: split_entity_id() split_entity_id will now raise a ValueError if the passed value does not follow the basic entity ID format (.).

Previously it could return a list with a single item.

(@balloob - #66835)

mleiber commented 2 years ago

Another observation. I got the shelly integration running by applying #658 (which wasn't that easy as I first had to remove the integration, delete and reinstall via HACS and then reconfigure the integration - otherwise I couldn't get HA to restart as it was complaining about that version conflict). I am still having two tons of error messages in the log though.

Now I have two Shelly integrations shown in the configuration:

image

I'm using yaml based configuration. The first one is for that, the second one looks like a UI based integration. Digging deeper, the first one lists 17 devices and 42 entities:

image

The second one 17 devices (the same) and 11 entities.

image

The 11 entities of integration # 2 seem to be *_over_power and *_over_temp binary_sensors that I have excluded in the yaml configuration.

There is also one total_consumption sensor sensor.shelly_shplg_s_df20ac_total_consumption. The others are part of # 1 above. None of them though should be there, some look like duplicates for sensors that are properly named (using the device name), others shouldn't be there at all as they are excluded in the yaml configuration.

One more detail that may be related is I have chosen no prefix id_prefix: "" # no prefix for the entities. This worked fine up until now.

robr92 commented 2 years ago

same problem! I changed on manifest from 1.5.1 to 1.6.1 but when I check the configuration it gives me this error "Integration error: shelly - Requirements for shelly not found: ['paho-mqtt == 1.5.1']."

hakana commented 2 years ago

I have created a new beta version bumping to 1.6.1 but it look like there are other problems also. I will look on that during the day.

matteos1 commented 2 years ago

same here

JurajNyiri commented 2 years ago

I am working on a fix, ETA 1-2 hour. Current consumption and switches already fixed. image

Update 1:

Issue is inside https://github.com/StyraHem/ShellyForHASS/blob/master/custom_components/shelly/sensor.py#L63 image

where ShellyDevice.init function sets entity id in a format of ".something", without the platform.

This is then done properly in some places, like for example ShellyVersion sensor, where platform is added. This does not happen for other classes, such as ShellySensor or ShellySwitch which stopped working in 2022.03.x because of invalid format of entity_id.

Possible fixes

Obvious fix is doing something like

ShellyDevice.__init__(self, dev, instance)
self._unique_id += "_" + sensor_name
self.entity_id = "sensor" + self.entity_id + "_" + sensor_name

and similarly for all the other classes, however I think it should be fixed properly inside the ShellyDevice.init and then all the other code adding platform shall be removed.

@hakana thoughts?

Update 2

Investigated architecture further and I think I will go with the obvious fix stated above and already done today for some classes.

JurajNyiri commented 2 years ago
mleiber commented 2 years ago

I will test it in half an hour. Thx for the quick fix!

Juraj Nyíri @.***> schrieb am Do., 3. März 2022, 12:31:

Fix available in PR #659 https://github.com/StyraHem/ShellyForHASS/issues/659 .

— Reply to this email directly, view it on GitHub https://github.com/StyraHem/ShellyForHASS/issues/659#issuecomment-1057951452, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMPS5IMRUXWJV7S6PZ3X2RDU6CPIBANCNFSM5PY6FO7A . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you commented.Message ID: @.***>

mleiber commented 2 years ago

@jurajny

I did integrate your changes manually and it looks like it is working now. Needed a bit of cleanup to eliminate the orphan entities and 2nd integration that had been created by the defective version. Everything seems to be working fine now.

Thanks a lot for the quick remedy - now we have heating again in our living room. I've implemented a thermostat using a shelly switch which wasn't working anymore. Makes me think if I should make that dependent on the home automation ... ;-).

anyway, thanks again!

asiersan commented 2 years ago

Fix available in PR #660 .

So we must wait for a new release?

JurajNyiri commented 2 years ago

Issue is now fixed in Release 0.3.4.

belmont commented 2 years ago

issue not fixed at all, just did update, shelly failed, did a rollback