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
72.8k stars 30.5k forks source link

Viessmann ViCare Integration: Missing device_class for energy sensors #122850

Open MarianRychtecky opened 2 months ago

MarianRychtecky commented 2 months ago

The problem

I'm missing the energy sensors device_class for all my Vitodens 100 sensors. Adding the class manually only works for a few seconds before it is automatically rewritten.

What version of Home Assistant Core has the issue?

2024.7.4

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Core

Integration causing the issue

Viessmann vicare

Link to integration documentation on our website

https://www.home-assistant.io/integrations/vicare

Diagnostics information

I wish to add gas consumption to the energy dashboard, however all entities created by ViCare integration miss device_class (in my case, device_class: gas), according to:

https://www.home-assistant.io/docs/energy/faq/#troubleshooting-missing-entities

I tried to add device_class manually under Developer Tools > States, and this works, however entity's settings are rewritten in about 10s or so.

image

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

home-assistant[bot] commented 2 months ago

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

Code owner commands Code owners of `vicare` 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 vicare` 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)


vicare documentation vicare source (message by IssueLinks)

CFenner commented 2 months ago

Should be fixed with https://github.com/home-assistant/core/pull/122334

MarianRychtecky commented 2 months ago

Thank you for your time. Can you estimate release data (roughly)?

CFenner commented 2 months ago

just now.. https://github.com/home-assistant/core/releases/tag/2024.7.4

MarianRychtecky commented 2 months ago

Great! Do I need to reinitialize the sensors? I upgraded and restarted the system, but I still cannot see device_type.

CFenner commented 2 months ago

It should be updated after a restart. Does this behave the same for energy (kwh) and gas (m3)?

Can you share the diagnostic info?

MarianRychtecky commented 2 months ago

Yes, after restarting, I cannot see the device class on kWh or m3. Where can I send the diag info?

CFenner commented 2 months ago

Select the integration and click ...

MarianRychtecky commented 2 months ago

I meant how to deliver to you :D

CFenner commented 2 months ago

just drop in the comment, critical data is removed already.

MarianRychtecky commented 2 months ago

config_entry-vicare-ac250f22af560f56c75a0205d5e8bb71.json

CFenner commented 2 months ago

Everything looks good.

Can you try to remove the type gas from the integration config and set to auto? Reconfigure the integration or change it in the config/.storage/core.config_entries.json and restart.

MarianRychtecky commented 2 months ago

Unfortunately I still cannot see that, I deleted this device and added again with "type: auto".

CFenner commented 2 months ago

@MarianRychtecky can you join the Discord to have a chat?

MarianRychtecky commented 2 months ago

I'd love to, but the invite doesn't work. And no, I'm not usually trouble maker :-)

image

CFenner commented 2 months ago

https://discord.gg/gjf5ur6u, my username is Hafenstrand.

MarianRychtecky commented 2 months ago

Sorry, I'm not able to join

image

Would you contact me at my email:

https://paste.ec/paste/tRUwGbui#XDiTFbuY7tUA0t0ujUXRYm2qZ+LoNIpKJDzJ-rMvcHM

Thank you very much for your help.

CFenner commented 2 months ago

@MarianRychtecky could you verify if the issue is solved with the latest beta release?

MarianRychtecky commented 2 months ago

I installed 2024.8.0b1, but I cannot see any difference, however I'm only looking for device_class on the sensor level. Maybe you want me to test elsewhere?

image

CFenner commented 2 months ago

Oh, just found it... the getter for the unit is not implemented correctly (looks like copy&paste issue).

https://github.com/somm15/PyViCare/blob/4e3bbdc66d78e33571db8cf350f78c6486097006/PyViCare/PyViCareGazBoiler.py#L183

Is tries to access the value with "heating.gas.consumption.summary.dhw")["properties"]["day"]["unit"] but it should be currentDay instead of day.


            "properties": {
              "currentDay": {
                "type": "number",
                "unit": "cubicMeter",
                "value": 0.1
              },
              "currentMonth": {
                "type": "number",
                "unit": "cubicMeter",
                "value": 0.5
              },

Unfortunately the library is not maintained, so we cannot expect a fix in the near future.

I would suggest, that I remove the unit getter, so you would need to set the class yourself.

CFenner commented 2 months ago

@MarianRychtecky can you please verify the PR https://github.com/home-assistant/core/pull/123089 and comment on it? With this you should be able to set the device class permanently.

CFenner commented 2 months ago

There is actually code in place, that should prevent https://github.com/home-assistant/core/issues/122850, but device_class is still reset on update.

https://github.com/home-assistant/core/blob/8687c32c15fb3a577a993a2e32c0527ed36f838b/homeassistant/components/vicare/sensor.py#L981-L988

MarianRychtecky commented 2 months ago

Thank you for your effort on this. Can you please explain to me a bit more in detail what does the update mean? Does removing the getter mean the sensor won't be automatically populated in HA from API? I would rather miss device_class (and the option to add it to the energy monitor) than not have this sensor reading. Thank you, Marian PS: How complicated is it to patch a library?

CFenner commented 2 months ago

Does removing the getter mean the sensor won't be automatically populated in HA from API?

No, the getter for the sensor value is still there, it's would just be the unit of measurement that is not set from the api anymore.

PS: How complicated is it to patch a library?

The library is unmaintained and I did not yet start to publish my own fork. I plan to do this though. Patching would be relatively easy: https://github.com/somm15/PyViCare/pull/373

MarianRychtecky commented 2 months ago

Thank you for your support; I will wait until it is released and I will test.

MarianRychtecky commented 2 months ago

@CFenner Christopher, can you please help me to understand how this will work? I can see your update in the DEV branch; however, after installing 20024.8.3, device_class is not there. Do I need to reinstall ViCare integration to get a new library in place? Thank you

CFenner commented 2 months ago

You will need to wait till next week, it is in the monthly release.

MarianRychtecky commented 2 months ago

Great, thank you for your great help. Much appreciated.

MarianRychtecky commented 1 month ago

Hi Chris, can you please help to understanding a change? After upgrading to 2024.09.01 I see no difference in behaviour. Device class is still missing and adding device_class manually is rewritten instantly. Am I missing something? Thank you, Marian

CFenner commented 1 month ago

@home-assistant reopen

CFenner commented 1 month ago

@MarianRychtecky can you please confirm, that you have no config/custom_component/vicare folder in your instance.

MarianRychtecky commented 1 month ago

I can confirm there no such content.

image

MarianRychtecky commented 1 month ago

Hi all, So that you know, everyone who will have a similar problem. I did a workaround, which works now.

Idea - to create a Template sensor that will "follow" the original sensor but will not change its attributes/properties.

DO NOT USE Heplers! Integration -> Helpers - for some reason, Helpers will inherit the original sensor properties, and "device_class" and "unit_of_measurement" will disappear when the original sensor value (states) is updated.

I created a manual Sensor template in "configuration.conf". I called sensors "followers."

# Templates
template:
  - sensor:
      # DHW GAS
      - name: "DHW gas consumption follower"
        device_class: gas
        unique_id: dhw_gas_consumption_follower
        unit_of_measurement: "m³"
        state_class: total_increasing
        state: >
          {{ states('sensor.<name_of_your_device>_dhw_gas_consumption_today') }}
        icon: mdi:gas-burner
      # Heating GAS
      - name: "Heating gas consumption follower"
        device_class: gas
        unique_id: heating_gas_consumption_follower
        unit_of_measurement: "m³"
        state_class: total_increasing
        state: >
          {{ states('sensor.<name_of_your_device>_heating_gas_consumption_today') }}
        icon: mdi:gas-burner

(be careful with indentation, as always!)

Recently created sensors I named "DHW gas consumption follower" can be added to the energy dashboard:

image

And are tracking gas consumption:

image

McGiverGim commented 1 month ago

Hi! I just installed this integration, and I have the same problem commented here. It seems the device_class is missing in all the entities. Maybe I can help with the problem? The workaround is ok, but I think it's good to have this working out of the box.

CFenner commented 1 month ago

Can you share your diagnostics?

McGiverGim commented 1 month ago

Yes, of course, I think this is what you want: config_entry-vicare-01J87T2D0KMQ6F3SNCVGJC4B84.json

It's a Viessman Vitodens 050-W if it matters...

McGiverGim commented 1 month ago

Is there a way to "add" logs live in my installation? I can add logs to the code to see what is happening, but I don't know if this is possible in a live Home Assistant installation.

McGiverGim commented 1 month ago

Additionally, as a workaround, in place of using templates, it's easier to use the customize.yaml file and simply add:

sensor.caldera_acs_gas_anual:
  device_class: gas
sensor.caldera_calefaccion_gas_anual:
  device_class: gas